无法在Node.js上使用langchain设置自定义OpenAI模型

huangapple go评论78阅读模式
英文:

Can't set custom OpenAI model with langchain on nodejs

问题

我正在尝试在我的 OpenAI 实例中使用 Node.js 中的 langchain 来设置 "gpt-3.5-turbo" 模型,但以下方式默认将我的请求发送到 text-davinci 模型。

const { OpenAI } = require("langchain/llms");
const { ConversationChain } = require("langchain/chains");
const { BufferMemory } = require("langchain/memory");

const model = new OpenAI({ model: "gpt-3.5-turbo", openAIApiKey: "###", temperature: 0.9 });
const memory = new BufferMemory();

const chain = new ConversationChain({ llm: model, memory: memory });

async function x() {
  const res = await chain.call({ input: "Hello this is xyz!" });
  const res2 = await chain.call({ input: "Hello what was my name?" });
  console.log(res);
  console.log(res2);
}

x();

在文档中,我找到了使用 Python 设置模型的方法。它通过在实例上使用 model_name 属性进行设置。但这种方式在 Node.js 中不起作用。是否有办法在 langchain Node.js 中设置自定义模型?

英文:

I am trying to set "gpt-3.5-turbo" model in my OpenAI instance using langchain in node.js, but below way sends my requests defaultly as text-davinci model.

const { OpenAI } = require("langchain/llms");
const { ConversationChain } = require("langchain/chains");
const { BufferMemory } = require("langchain/memory");

const model = new OpenAI({ model:"gpt-3.5-turbo", openAIApiKey: "###", temperature: 0.9 });
const memory = new BufferMemory();

const chain = new ConversationChain({llm:model, memory: memory});

async function x(){
const res = await chain.call({input:"Hello this is xyz!"});
const res2 = await chain.call({input:"Hello what was my name?"});
console.log(res);
console.log(res2);
}

x();

On documentation, i found the way to setting model with python. It sets with model_name attribute on the instance. But this way doesn't work with nodejs. Is there any way to setting custom models with langchain node.js ?

答案1

得分: 2

我查看了代码库,似乎**modelName**是你应该使用的参数。

奇怪的是,在文档的搜索功能中,对于modelName没有任何结果。我猜它是相同的参数,但在Python API中使用驼峰命名法。

与Python LangChain的关系

编辑

文档中提到了这里

英文:

I looked at the codebase and it seems like modelName is the parameter that you should use.

It's strange that the search function in the docs give no results for modelName. I guess it is the same parameters used in python API but in camel case.

Relationship with Python LangChain

edit

Docs have it here

huangapple
  • 本文由 发表于 2023年4月7日 01:46:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/75952371.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定