In my Angular 16 (standalone) app, I have a simple service to test LangChain against OpenAI.
This same code is working perfectly fine in a NodeJS app, however, when run from Angular, the result returned from OpenAI is always an empty string:
在我的Angel 16(独立的)应用程序中,我有一个简单的服务来测试LangChain和OpenAI。同样的代码在NodeJS应用程序中运行得非常好,然而,当从角度运行时,OpenAI返回的结果总是空字符串:
[llm/start] [1:llm:OpenAIChat] Entering LLM run with input: {
"prompts": [
"Israel's capital is"
]
}
console.js:132 [llm/end] [1:llm:OpenAIChat] [12ms] Exiting LLM run with output: {
"generations": [
[
{
"text": ""
}
]
]
}
chat.service.ts:49 Completion returned in simplePromptTest:
Here is the Angular service code generating the above output:
以下是生成上述输出的角度服务代码:
import { OpenAI } from "langchain/llms/openai";
const llm = new OpenAI({
openAIApiKey: "sk-......ws",
modelName: "gpt-3.5-turbo",
temperature: 0,
verbose: true
});
@Injectable({
providedIn: 'root'
})
export class ChatService {
constructor() { }
async simplePromptTest() {
const result = await llm.predict("Israel's capital is");
console.log('Completion returned in simplePromptTest: ', result);
return result;
}
}
Packages I installed are:
我安装的程序包包括:
npm install -S langchain
npm install -S openai
What am I missing, please?
我错过了什么?
更多回答
empty result means you made no call or there is error while making OpenAI call, you can break you program and see actually which steps is failing..
空结果意味着你没有调用或者在调用OpenAI时出现错误,你可以中断你的程序,看看到底是哪些步骤失败了。
Thanks ZKS. Calls are registered in openai and charged. Same code runs OK in NodeJS, not Angular. console log shows no error. Where else shall I look for errors?
谢谢ZKS。通话在OpenAI中注册并收费。相同的代码在NodeJS中运行正常,但在角度上运行不正常。控制台日志未显示错误。我还应该在哪里寻找错误?
我是一名优秀的程序员,十分优秀!