From 566245814f0644762f0f55a669a7c70f1f84a1f3 Mon Sep 17 00:00:00 2001 From: Thiago Leite Date: Sat, 25 Nov 2023 15:55:08 -0300 Subject: [PATCH] handle other error messages to bypass query execution --- package.json | 2 +- src/services/chain/sql-database-chain.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 2e112d3..ec51bf0 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ai-agent-enterprise", "description": "AI Agent simplifies the implementation and use of generative AI with LangChain", - "version": "0.0.29", + "version": "0.0.30", "main": "./build/index.js", "types": "./build/index.d.ts", "files": [ diff --git a/src/services/chain/sql-database-chain.ts b/src/services/chain/sql-database-chain.ts index 44ba03a..d9fe48e 100644 --- a/src/services/chain/sql-database-chain.ts +++ b/src/services/chain/sql-database-chain.ts @@ -8,8 +8,6 @@ import { ChainValues } from "langchain/schema"; import { CallbackManagerForChainRun } from "langchain/callbacks"; import { PromptTemplate } from "langchain/prompts"; -const CONTEXTUAL_ERROR = 'There is no specific information in the provided SQL table schema'; - /** * Class that represents a SQL database chain in the LangChain framework. * It extends the BaseChain class and implements the functionality @@ -110,9 +108,13 @@ export default class SqlDatabaseChain extends BaseChain { question: (input) => input.question, query: (input) => input.query, response: (input) => { - if (input.query.content.includes(CONTEXTUAL_ERROR)) return null; + const sql = input.query.content.toLowerCase(); + + if (sql.includes('select') && sql.includes('from')) { + return this.database.run(input.query); + } - return this.database.run(input.query) + return null; }, }, {