Skip to content

Commit

Permalink
fix(community): togetherai response different format handling (#7488)
Browse files Browse the repository at this point in the history
Co-authored-by: An Xie <[email protected]>
  • Loading branch information
axe-me and an-upfeat authored Jan 9, 2025
1 parent 67e00e0 commit a30c2fa
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libs/langchain-community/src/llms/togetherai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface TogetherAIInferenceResult {
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
subjobs: Array<any>;
output: {
output?: {
choices: Array<{
finish_reason: string;
index: number;
Expand All @@ -36,6 +36,11 @@ interface TogetherAIInferenceResult {
raw_compute_time: number;
result_type: string;
};
choices?: Array<{
finish_reason: string;
index: number;
text: string;
}>;
}

/**
Expand Down Expand Up @@ -247,8 +252,11 @@ export class TogetherAI extends LLM<TogetherAICallOptions> {
prompt,
options
);
const outputText = response.output.choices[0].text;
return outputText ?? "";
if (response.output) {
return response.output.choices[0]?.text ?? "";
} else {
return response.choices?.[0]?.text ?? "";
}
}

async *_streamResponseChunks(
Expand Down

0 comments on commit a30c2fa

Please sign in to comment.