Skip to content

Commit

Permalink
Merge pull request #38 from dev-jpnobrega/hotfix/sql-chain-adjusts
Browse files Browse the repository at this point in the history
adjust maxdataexamples to 10
  • Loading branch information
dev-jpnobrega committed Dec 4, 2023
2 parents 63156a2 + 8e9193e commit f096fdf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 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.34",
"version": "0.0.35",
"main": "./build/index.js",
"types": "./build/index.d.ts",
"files": [
Expand Down
12 changes: 9 additions & 3 deletions src/services/chain/sql-database-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { ChainValues } from "langchain/schema";
import { CallbackManagerForChainRun } from "langchain/callbacks";
import { PromptTemplate } from "langchain/prompts";


const MESSAGES_ERRORS = {
dataTooBig: 'Data result is too big. Please, be more specific.',
dataEmpty: 'Data result is empty. Please, be more specific.',
}

/**
* Class that represents a SQL database chain in the LangChain framework.
* It extends the BaseChain class and implements the functionality
Expand Down Expand Up @@ -52,7 +58,7 @@ export default class SqlDatabaseChain extends BaseChain {

customMessage = '';

maxDataExamples = 30; // TODO add config in agent settings
maxDataExamples = 10; // TODO add config in agent settings

sqlOutputKey: string | undefined = undefined;

Expand Down Expand Up @@ -104,7 +110,7 @@ export default class SqlDatabaseChain extends BaseChain {
return sqlBlock;
}

return null;
throw new Error(MESSAGES_ERRORS.dataEmpty);
}

private async checkResultDatabase(database: SqlDatabase, sql: string) {
Expand All @@ -118,7 +124,7 @@ export default class SqlDatabaseChain extends BaseChain {
const result = parseInt(data[0]?.resultcount, 10);

if (result >= this.maxDataExamples) {
throw new Error('Data result is too big. Please, be more specific.');
throw new Error(MESSAGES_ERRORS.dataTooBig);
}

return result;
Expand Down

0 comments on commit f096fdf

Please sign in to comment.