英文:
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中使用驼峰命名法。
编辑
文档中提到了这里。
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论