Skip to content

Commit

Permalink
Merge pull request #33 from dev-jpnobrega/hotfix/handle-query
Browse files Browse the repository at this point in the history
handle other error messages to bypass query execution
  • Loading branch information
zanova committed Nov 25, 2023
2 parents 59e499f + 5662458 commit 72b5c81
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down
10 changes: 6 additions & 4 deletions src/services/chain/sql-database-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
},
},
{
Expand Down

0 comments on commit 72b5c81

Please sign in to comment.