Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community[patch]: Throw more descriptive errors for Ali toyi chat models #5549

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it safer to check for something like chunk.code?

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));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the trim call?

} catch (e) {
console.warn(`Received a non-JSON parseable chunk: ${line}`);
}
Expand Down