最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Connecting postgresql with langchain in nodejs isn't working properly. Although, there aren't any erro

programmeradmin0浏览0评论

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论