题意:OpenAI 微调引擎在 Node 中无法运行 - '找不到引擎'。
问题背景:
I have fine-tuned an engine on OpenAI using my own data. I can access the engine in the Playground with no issues, however, when I try to access it programmatically using Node & the openai Node library, I get an "Engine not found" error. The weird thing is, I could have sworn it worked before.
我已经在 OpenAI 上使用自己的数据微调了一个引擎。我可以在 Playground 中无问题地访问该引擎,但是当我尝试使用 Node 和 openai Node 库以编程方式访问它时,却收到‘找不到引擎’的错误。奇怪的是,我记得它之前是可以工作的。
Anyway, here is my code: 无论如何,这是我的代码:
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
async function getDream() {
const completion = await openai.createCompletion("davinci:ft-personal-2022-04-09-19-12-54", {
prompt: "I dreamed",
});
console.log(completion.data.choices[0].text);
}
getDream();
Here's the error: 这是错误信息:
error: {
message: 'Engine not found',
type: 'invalid_request_error',
param: null,
code: null
}
I tried running the same code but with a regular engine (davinci). Works fine that way. I've double-checked that I have the name of my fine-tuned engine right and tried it using the engine ID just in case. Nothing seems to work.
我尝试使用常规引擎(davinci)运行相同的代码,这样是可以正常工作的。我已经反复检查了微调引擎的名称,并尝试使用引擎 ID,以防万一。但是似乎什么都不起作用。
PS - I have run this using the OpenAI CLI as well using openai api completions.create -m davinci:ft-personal-2022-04-09-19-12-54 -p "I dreamed"
and that works as well.
PS - 我也使用 OpenAI CLI 运行过这个命令 openai api completions.create -m davinci:ft-personal-2022-04-09-19-12-54 -p "I dreamed"
,这也是可以正常工作的。
问题解决:
I'm back, answering my own question in hopes that it will help others.
我回来了,回答我自己的问题,希望这能帮助其他人。
It seems that if you are using your own fine-tuned model, you have to use a different method than if you use one of the default models. Instead of createCompletion
, you should use createCompletionFromModel
. So the function above (getDream
) should actually look like this:
看起来如果你使用的是自己微调的模型,而不是使用默认模型,那么需要使用不同的方法。你应该使用 createCompletionFromModel
而不是 createCompletion
。所以上面的函数(getDream)实际上应该是这样的:
async function getDream() {
const response = await openai.createCompletionFromModel({
model: 'davinci:ft-personal-2022-04-09-19-12-54',
prompt: 'I dreamed'
// add other parameters here
});
}
You can add other completion parameters to this below prompt
, e.g. temperature
, frequency_penalty
, etc.
你可以在下面的提示中添加其他补全参数,例如温度、频率惩罚等。