so I tried doing this but I am not getting the data as expected from the database. Although, I got it at some times but I don't know what's going on here. here is the code :
INDEX.JS
// index.js
const { SqlDatabase } = require("langchain/sql_db");
const AppDataSource = require("./db");
const { SqlDatabaseChain } = require("langchain/chains/sql_db");
const { Ollama } = require("@langchain/ollama");
(async () => {
await AppDataSource.initialize();
const llm = new Ollama({
model: "llama3",
temperature: 0,
});
// Initialize the PostgreSQL database connection
const db = await SqlDatabase.fromDataSourceParams({
appDataSource: AppDataSource,
});
const table_info = await db.getTableInfo();
// console.log(table_info);
// Create the SqlDatabaseChain
const chain = new SqlDatabaseChain({
llm: llm,
database: db,
});
// console.log(chain);
// Define a prompt to query the database
const prompt =
"list some ideaids and their corresponding ideas from the database";
// Run the chain
const result = await chain.invoke({
query: prompt,
});
console.log("Result:", result);
await AppDataSource.destroy();
})();
and this is db.js
const { DataSource } = require("typeorm");
// Configure TypeORM DataSource
const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "postgres",
password: "aaaa",
database: "asas" ,
schema:"public"
});
module.exports = AppDataSource;
I tried setting the includeTables property, and then gave table names and got result but suddenly even that was not working.