Support for sql.js in javascript langchain SQL Agent Toolkit #21800
Closed
radiantone
announced in
Ideas
Replies: 2 comments 1 reply
-
It actually does work with my edit, but only from command line so far. Still trying to get it to work in browser import { OpenAI } from "@langchain/openai";
import { SqlDatabase } from "langchain/sql_db";
import { createSqlAgent, SqlToolkit } from "langchain/agents/toolkits/sql";
import { DataSource } from "typeorm";
export const run = async () => {
// Download from https://raw.githubusercontent.com/lerocha/chinook-database/master/ChinookDatabase/DataSources/Chinook_Sqlite.sqlite
const datasource = new DataSource({
type: 'sqljs',
location: 'chinook.sqlite',
});
console.log('Loaded database.');
const db = await SqlDatabase.fromDataSourceParams({
appDataSource: datasource,
});
const model = new OpenAI({ temperature: 0 });
const toolkit = new SqlToolkit(db, model);
const executor = createSqlAgent(model, toolkit);
const input = `List the total sales per country. Which country's customers spent the most?`;
console.log(`Executing with input "${input}"...`);
const result = await executor.invoke({ input });
console.log(`Got output ${result.output}`);
console.log(
`Got intermediate steps ${JSON.stringify(
result.intermediateSteps,
null,
2
)}`
);
await datasource.destroy();
};
run() |
Beta Was this translation helpful? Give feedback.
1 reply
-
I was able to get this to work, but it didn't work properly using this method const db = await SqlDatabase.fromDataSourceParams({ I had to instead use SqlDatabase.fromOptionsParams({appDataSourceOptions:me.sqljs_options}) Otherwise, my edit in the top post works, so I will submit a PR for it. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Checked
Feature request
Currently the SQL agent toolkit internals only recognize 'sqlite' (in the sqlite family of drivers). It should be fairly straightforward to add support for sqljs (or sql.js) sqlite for browser.
Motivation
I want to create or otherwise initialize a sql.js sqlite database in my browser app, perhaps pull in a variety of tabular data from various places, then ask questions about it. Within my browser app.
Proposal (If applicable)
Assuming js sqlite and sql.js are query compatible being that sql.js is supposed to be a transpiled sqlite, then perhaps this line: https://github.com/langchain-ai/langchainjs/blob/98ad207545d767be9d2d5e5b64bdbe9ba82bcb61/langchain/src/util/sql_utils.ts#L142 could be augmented to include sqljs as so:
But this is just a wild fantasy at the moment, and I'm sure a little more effort will be required. But this frees developers from locking into command line tools to use SQL agent toolkit, and brings it into the space of web applications (serverless ones).
Beta Was this translation helpful? Give feedback.
All reactions