Skip to content

Commit 1329a61

Browse files
authored
fix: #4997 zhipu chat model response typeError (#5212)
1 parent 4592eaf commit 1329a61

File tree

1 file changed

+9
-5
lines changed
  • libs/langchain-community/src/chat_models

1 file changed

+9
-5
lines changed

libs/langchain-community/src/chat_models/zhipuai.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,14 @@ interface ResponseChoice {
6767
message: ChoiceMessage;
6868
}
6969

70+
interface ZhipuAIError {
71+
error: BaseResponse;
72+
}
73+
7074
/**
7175
* Interface representing a response from a chat completion.
7276
*/
73-
interface ChatCompletionResponse extends BaseResponse {
77+
interface ChatCompletionResponse extends ZhipuAIError {
7478
choices: ResponseChoice[];
7579
created: number;
7680
id: string;
@@ -295,12 +299,12 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
295299
options?.signal,
296300
(event) => {
297301
const data: ChatCompletionResponse = JSON.parse(event.data);
298-
if (data?.code) {
302+
if (data?.error?.code) {
299303
if (rejected) {
300304
return;
301305
}
302306
rejected = true;
303-
reject(new Error(data?.message));
307+
reject(new Error(data?.error?.message));
304308
return;
305309
}
306310

@@ -340,8 +344,8 @@ export class ChatZhipuAI extends BaseChatModel implements ChatZhipuAIParams {
340344
false,
341345
options?.signal
342346
).then<ChatCompletionResponse>((data) => {
343-
if (data?.code) {
344-
throw new Error(data?.message);
347+
if (data?.error?.code) {
348+
throw new Error(data?.error?.message);
345349
}
346350
const { finish_reason, message } = data.choices[0];
347351
const text = message.content;

0 commit comments

Comments
 (0)