import { DataSource } from "typeorm"; import { OpenAI } from "langchain/llms/openai"; import { SqlDatabase } from "langchain/sql_db"; import { SqlDatabaseChain } from "langchain/chains/sql_db"; /** * This example uses Chinook database, which is a sample database available for SQL Server, Oracle, MySQL, etc. * To set it up follow the instructions on https://database.guide/2-sample-databases-sqlite/, placing the .db file * in the examples folder. */ const datasource = new DataSource({ type: "sqlite", database: "Chinook.db", }); const db = await SqlDatabase.fromDataSourceParams({ appDataSource: datasource, }); const chain = new SqlDatabaseChain({ llm: new OpenAI({ temperature: 0 }), database: db, }); const res = await chain.run("How many tracks are there?"); console.log(res); // There are 3503 tracks.