Skip to content

Commit

Permalink
Throw informative exception
Browse files Browse the repository at this point in the history
  • Loading branch information
sinajia committed May 26, 2024
1 parent d770f92 commit 0101717
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion libs/langchain-community/src/chat_models/alibaba_tongyi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ export class ChatAlibabaTongyi
);

for await (const chunk of stream) {
/* if some error occurs:
{
"code": "DataInspectionFailed",
"message": "Output data may contain inappropriate content.",
"request_id": "43d18007-5aa5-9d18-b3b3-a55aba9ce8cb"
}
*/
if (!chunk.output) {
throw new Error(JSON.stringify(chunk));
}
const { text, finish_reason } = chunk.output;
yield new ChatGenerationChunk({
text,
Expand Down Expand Up @@ -593,7 +603,7 @@ export class ChatAlibabaTongyi
continue;
}
try {
yield JSON.parse(line.slice("data:".length).trim());
yield JSON.parse(line.slice("data:".length));
} catch (e) {
console.warn(`Received a non-JSON parseable chunk: ${line}`);
}
Expand Down

0 comments on commit 0101717

Please sign in to comment.