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(