gpt4 book ai didi

LangChain simple llm.predict in Angular returns empty result(Lang Chain Simple llm.在角度预测返回空结果)

转载 作者:bug小助手 更新时间:2023-10-26 19:43:25 31 4
gpt4 key购买 nike



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中运行正常,但在角度上运行不正常。控制台日志未显示错误。我还应该在哪里寻找错误?

优秀答案推荐
更多回答

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com