new(all): ChatGPT integration.
This commit is contained in:
parent
179b20a248
commit
b75d9cf793
7 changed files with 1532 additions and 39 deletions
1495
package-lock.json
generated
1495
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
@ -87,6 +87,7 @@
|
||||||
"botframework-connector": "4.18.0",
|
"botframework-connector": "4.18.0",
|
||||||
"botlib": "3.0.0",
|
"botlib": "3.0.0",
|
||||||
"c3-chart-maker": "0.2.8",
|
"c3-chart-maker": "0.2.8",
|
||||||
|
"chatgpt": "^2.4.2",
|
||||||
"chrome-remote-interface": "0.31.3",
|
"chrome-remote-interface": "0.31.3",
|
||||||
"cli-progress": "3.11.2",
|
"cli-progress": "3.11.2",
|
||||||
"cli-spinner": "0.2.10",
|
"cli-spinner": "0.2.10",
|
||||||
|
|
|
@ -335,7 +335,7 @@ export class GBMinService {
|
||||||
});
|
});
|
||||||
client.clientAuthorizations.add(
|
client.clientAuthorizations.add(
|
||||||
'AuthorizationBotConnector',
|
'AuthorizationBotConnector',
|
||||||
new Swagger.ApiKeyAuthorization('Authorization', `Bearer ${min.instance.webchatKey}`, 'header')
|
new Swagger.ApiKeyAfuthorization('Authorization', `Bearer ${min.instance.webchatKey}`, 'header')
|
||||||
);
|
);
|
||||||
const response = await client.Conversations.Conversations_StartConversation();
|
const response = await client.Conversations.Conversations_StartConversation();
|
||||||
const conversationId = response.obj.conversationId;
|
const conversationId = response.obj.conversationId;
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
import { GBServer } from '../../../src/app.js';
|
import { GBServer } from '../../../src/app.js';
|
||||||
import { BotAdapter } from 'botbuilder';
|
import { BotAdapter } from 'botbuilder';
|
||||||
import { WaterfallDialog } from 'botbuilder-dialogs';
|
import { WaterfallDialog } from 'botbuilder-dialogs';
|
||||||
|
import { ChatGPTAPIBrowser } from 'chatgpt';
|
||||||
import { GBLog, GBMinInstance, IGBDialog, IGBPackage } from 'botlib';
|
import { GBLog, GBMinInstance, IGBDialog, IGBPackage } from 'botlib';
|
||||||
import { Messages } from '../strings.js';
|
import { Messages } from '../strings.js';
|
||||||
import { KBService } from './../services/KBService.js';
|
import { KBService } from './../services/KBService.js';
|
||||||
|
@ -291,6 +292,25 @@ export class AskDialog extends IGBDialog {
|
||||||
});
|
});
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
|
if (process.env.OPENAI_EMAIL) {
|
||||||
|
if (!GBServer.globals.chatGPT) {
|
||||||
|
GBServer.globals.chatGPT = new ChatGPTAPIBrowser({
|
||||||
|
email: process.env.OPENAI_EMAIL,
|
||||||
|
password: process.env.OPENAI_PASSWORD
|
||||||
|
});
|
||||||
|
await GBServer.globals.chatGPT.init();
|
||||||
|
}
|
||||||
|
GBLog.info(`ChatGPT being used...`);
|
||||||
|
const response = await GBServer.globals.chatGPT.sendMessage(text);
|
||||||
|
|
||||||
|
if (!response) {
|
||||||
|
GBLog.info(`SEARCH called but NO answer could be found (zero results).`);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
await min.conversationalService.sendText(min, step, response);
|
||||||
|
}
|
||||||
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
|
}
|
||||||
|
|
||||||
// Not found.
|
// Not found.
|
||||||
|
|
||||||
|
|
|
@ -122,34 +122,34 @@ export class GuaribasQuestion extends Model<GuaribasQuestion> {
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
@AutoIncrement
|
@AutoIncrement
|
||||||
@Column(DataType.INTEGER)
|
@Column(DataType.INTEGER)
|
||||||
questionId: number;
|
declare questionId: number;
|
||||||
|
|
||||||
@Column(DataType.STRING(64))
|
@Column(DataType.STRING(64))
|
||||||
subject1: string;
|
declare subject1: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(64))
|
@Column(DataType.STRING(64))
|
||||||
subject2: string;
|
declare subject2: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(64))
|
@Column(DataType.STRING(64))
|
||||||
subject3: string;
|
declare subject3: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(64))
|
@Column(DataType.STRING(64))
|
||||||
subject4: string;
|
declare subject4: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(1024))
|
@Column(DataType.STRING(1024))
|
||||||
keywords: string;
|
declare keywords: string;
|
||||||
|
|
||||||
@Column(DataType.BOOLEAN)
|
@Column(DataType.BOOLEAN)
|
||||||
skipIndex: boolean;
|
declare skipIndex: boolean;
|
||||||
|
|
||||||
@Column(DataType.STRING(512))
|
@Column(DataType.STRING(512))
|
||||||
from: string;
|
declare from: string;
|
||||||
|
|
||||||
@Column(DataType.STRING(512))
|
@Column(DataType.STRING(512))
|
||||||
to: string;
|
declare to: string;
|
||||||
|
|
||||||
@Column(DataType.TEXT)
|
@Column(DataType.TEXT)
|
||||||
content: string;
|
declare content: string;
|
||||||
|
|
||||||
@Column(DataType.DATE)
|
@Column(DataType.DATE)
|
||||||
@CreatedAt
|
@CreatedAt
|
||||||
|
@ -162,18 +162,18 @@ export class GuaribasQuestion extends Model<GuaribasQuestion> {
|
||||||
//tslint:disable-next-line:no-use-before-declare
|
//tslint:disable-next-line:no-use-before-declare
|
||||||
@ForeignKey(() => GuaribasAnswer)
|
@ForeignKey(() => GuaribasAnswer)
|
||||||
@Column(DataType.INTEGER)
|
@Column(DataType.INTEGER)
|
||||||
answerId: number;
|
declare answerId: number;
|
||||||
|
|
||||||
@BelongsTo(() => GuaribasInstance)
|
@BelongsTo(() => GuaribasInstance)
|
||||||
instance: GuaribasInstance;
|
declare instance: GuaribasInstance;
|
||||||
|
|
||||||
@ForeignKey(() => GuaribasInstance)
|
@ForeignKey(() => GuaribasInstance)
|
||||||
@Column(DataType.INTEGER)
|
@Column(DataType.INTEGER)
|
||||||
instanceId: number;
|
declare instanceId: number;
|
||||||
|
|
||||||
@ForeignKey(() => GuaribasPackage)
|
@ForeignKey(() => GuaribasPackage)
|
||||||
@Column(DataType.INTEGER)
|
@Column(DataType.INTEGER)
|
||||||
packageId: number;
|
declare packageId: number;
|
||||||
|
|
||||||
@BelongsTo(() => GuaribasPackage)
|
@BelongsTo(() => GuaribasPackage)
|
||||||
package: GuaribasPackage;
|
package: GuaribasPackage;
|
||||||
|
|
|
@ -291,17 +291,17 @@ export class KBService implements IGBKBService {
|
||||||
content: string;
|
content: string;
|
||||||
subject1: string;
|
subject1: string;
|
||||||
subject2: string;
|
subject2: string;
|
||||||
subject: string;
|
subject3: string;
|
||||||
subject4: string;
|
subject4: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = new SearchClient<SearchResults>(instance.searchHost.split('.')[0], 'azuresql-index', {
|
const client = new SearchClient<SearchResults>('https://' + instance.searchHost, 'azuresql-index', {
|
||||||
key: instance.searchKey
|
key: instance.searchKey
|
||||||
} as any);
|
} as any);
|
||||||
|
|
||||||
const results = await client.search(query, {
|
const results = await client.search(query, {
|
||||||
filter: `instanceId eq ${instance.instanceId} and skipIndex eq false`,
|
filter: `instanceId eq ${instance.instanceId} and skipIndex eq false`,
|
||||||
searchFields: ['content', 'subject1', 'subject2', 'subject', 'subject4'],
|
searchFields: ['content', 'subject1', 'subject2', 'subject3', 'subject4'],
|
||||||
select: ['instanceId', 'questionId', 'answerId'],
|
select: ['instanceId', 'questionId', 'answerId'],
|
||||||
skip: 0,
|
skip: 0,
|
||||||
top: 1
|
top: 1
|
||||||
|
@ -341,10 +341,6 @@ export class KBService implements IGBKBService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
GBLog.info(`SEARCH called but NO answer could be found (zero results).`);
|
|
||||||
}
|
|
||||||
|
|
||||||
return { answer: undefined, questionId: 0 };
|
return { answer: undefined, questionId: 0 };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,4 +53,5 @@ export class RootData {
|
||||||
public entryPointDialog: string; // To replace default welcome dialog.
|
public entryPointDialog: string; // To replace default welcome dialog.
|
||||||
public debugConversationId: any; // Used to self-message during debug.
|
public debugConversationId: any; // Used to self-message during debug.
|
||||||
public debuggers: any[]; // Client of attached Debugger instances by botId.
|
public debuggers: any[]; // Client of attached Debugger instances by botId.
|
||||||
|
public chatGPT: any; // ChatGPT API handle (shared Browser).
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue