new(whatsapp.gblib): LLM SQL.
This commit is contained in:
parent
5965cb1e35
commit
8dd7ac5597
2 changed files with 21 additions and 0 deletions
|
@ -367,6 +367,11 @@ export class GBVMService extends GBService {
|
||||||
if (!min[connectionName]) {
|
if (!min[connectionName]) {
|
||||||
GBLogEx.info(min, `Loading custom connection ${connectionName}...`);
|
GBLogEx.info(min, `Loading custom connection ${connectionName}...`);
|
||||||
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
|
min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions);
|
||||||
|
min[`llmconnection`] ={
|
||||||
|
type: dialect,
|
||||||
|
username,
|
||||||
|
database: storageName, password};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -46,6 +46,8 @@ import { RunnableSequence } from '@langchain/core/runnables';
|
||||||
import { DynamicStructuredTool } from '@langchain/core/tools';
|
import { DynamicStructuredTool } from '@langchain/core/tools';
|
||||||
import { convertToOpenAITool } from '@langchain/core/utils/function_calling';
|
import { convertToOpenAITool } from '@langchain/core/utils/function_calling';
|
||||||
import { ChatOpenAI, OpenAI } from '@langchain/openai';
|
import { ChatOpenAI, OpenAI } from '@langchain/openai';
|
||||||
|
import { SqlDatabaseChain } from 'langchain/chains/sql_db';
|
||||||
|
|
||||||
import { GBMinInstance } from 'botlib';
|
import { GBMinInstance } from 'botlib';
|
||||||
import * as Fs from 'fs';
|
import * as Fs from 'fs';
|
||||||
import { jsonSchemaToZod } from 'json-schema-to-zod';
|
import { jsonSchemaToZod } from 'json-schema-to-zod';
|
||||||
|
@ -61,6 +63,7 @@ import { DialogKeywords } from '../../basic.gblib/services/DialogKeywords.js';
|
||||||
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
import { GBVMService } from '../../basic.gblib/services/GBVMService.js';
|
||||||
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
import { GBLogEx } from '../../core.gbapp/services/GBLogEx.js';
|
||||||
import { pagespeedonline } from 'googleapis/build/src/apis/pagespeedonline/index.js';
|
import { pagespeedonline } from 'googleapis/build/src/apis/pagespeedonline/index.js';
|
||||||
|
import { SqlDatabase } from 'langchain/dist/sql_db.js';
|
||||||
|
|
||||||
export interface CustomOutputParserFields {}
|
export interface CustomOutputParserFields {}
|
||||||
export type ExpectedOutput = any;
|
export type ExpectedOutput = any;
|
||||||
|
@ -467,6 +470,19 @@ export class ChatServices {
|
||||||
result = await conversationalToolChain.invoke({
|
result = await conversationalToolChain.invoke({
|
||||||
question
|
question
|
||||||
});
|
});
|
||||||
|
} else if (LLMMode === 'sql') {
|
||||||
|
|
||||||
|
const db = await SqlDatabase.fromDataSourceParams({
|
||||||
|
appDataSource: min[`llmconnection`],
|
||||||
|
});
|
||||||
|
|
||||||
|
const chain = new SqlDatabaseChain({
|
||||||
|
llm: model,
|
||||||
|
database: db
|
||||||
|
});
|
||||||
|
|
||||||
|
result = await chain.run(question);
|
||||||
|
|
||||||
} else if (LLMMode === 'nochain') {
|
} else if (LLMMode === 'nochain') {
|
||||||
result = await (tools.length > 0 ? modelWithTools : model).invoke(`
|
result = await (tools.length > 0 ? modelWithTools : model).invoke(`
|
||||||
${systemPrompt}
|
${systemPrompt}
|
||||||
|
|
Loading…
Add table
Reference in a new issue