From a30c2fa1b39a8747949c5bc1a84b65dfd5d01b2c Mon Sep 17 00:00:00 2001 From: Axe Date: Wed, 8 Jan 2025 21:34:18 -0700 Subject: [PATCH] fix(community): togetherai response different format handling (#7488) Co-authored-by: An Xie --- libs/langchain-community/src/llms/togetherai.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/libs/langchain-community/src/llms/togetherai.ts b/libs/langchain-community/src/llms/togetherai.ts index d03d44a5c12b..e388246c883c 100644 --- a/libs/langchain-community/src/llms/togetherai.ts +++ b/libs/langchain-community/src/llms/togetherai.ts @@ -27,7 +27,7 @@ interface TogetherAIInferenceResult { }; // eslint-disable-next-line @typescript-eslint/no-explicit-any subjobs: Array; - output: { + output?: { choices: Array<{ finish_reason: string; index: number; @@ -36,6 +36,11 @@ interface TogetherAIInferenceResult { raw_compute_time: number; result_type: string; }; + choices?: Array<{ + finish_reason: string; + index: number; + text: string; + }>; } /** @@ -247,8 +252,11 @@ export class TogetherAI extends LLM { 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(