From a02711c742c41ca21ba6da5c3c651dc839c2a873 Mon Sep 17 00:00:00 2001 From: An Xie Date: Wed, 8 Jan 2025 15:31:06 -0700 Subject: [PATCH 1/2] fix(community): togetherai response different format handling --- .../src/llms/togetherai.ts | 40 +++++++++++-------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/libs/langchain-community/src/llms/togetherai.ts b/libs/langchain-community/src/llms/togetherai.ts index d03d44a5c12b..5c70c2e64e6f 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; + }>; } /** @@ -110,19 +115,19 @@ export interface TogetherAIInputs extends BaseLLMParams { export interface TogetherAICallOptions extends BaseLLMCallOptions, - Pick< - TogetherAIInputs, - | "modelName" - | "model" - | "temperature" - | "topP" - | "topK" - | "repetitionPenalty" - | "logprobs" - | "safetyModel" - | "maxTokens" - | "stop" - > {} + Pick< + TogetherAIInputs, + | "modelName" + | "model" + | "temperature" + | "topP" + | "topK" + | "repetitionPenalty" + | "logprobs" + | "safetyModel" + | "maxTokens" + | "stop" + > { } export class TogetherAI extends LLM { lc_serializable = true; @@ -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( From c85d187cf6260dd96008658d60d5fa1f7f808038 Mon Sep 17 00:00:00 2001 From: An Xie Date: Wed, 8 Jan 2025 15:49:10 -0700 Subject: [PATCH 2/2] revert format changes --- .../src/llms/togetherai.ts | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/libs/langchain-community/src/llms/togetherai.ts b/libs/langchain-community/src/llms/togetherai.ts index 5c70c2e64e6f..e388246c883c 100644 --- a/libs/langchain-community/src/llms/togetherai.ts +++ b/libs/langchain-community/src/llms/togetherai.ts @@ -115,19 +115,19 @@ export interface TogetherAIInputs extends BaseLLMParams { export interface TogetherAICallOptions extends BaseLLMCallOptions, - Pick< - TogetherAIInputs, - | "modelName" - | "model" - | "temperature" - | "topP" - | "topK" - | "repetitionPenalty" - | "logprobs" - | "safetyModel" - | "maxTokens" - | "stop" - > { } + Pick< + TogetherAIInputs, + | "modelName" + | "model" + | "temperature" + | "topP" + | "topK" + | "repetitionPenalty" + | "logprobs" + | "safetyModel" + | "maxTokens" + | "stop" + > {} export class TogetherAI extends LLM { lc_serializable = true;