Skip to content

Commit

Permalink
Add stop to Together AI (#3714)
Browse files Browse the repository at this point in the history
Signed-off-by: Sunghyun Hwang <hwang@hey.com>
  • Loading branch information
Sunghyun Hwang authored Dec 20, 2023
1 parent 24c5f9c commit 9769205
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libs/langchain-community/src/llms/togetherai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ interface TogetherAIInferenceResult {
top_p: number;
top_k: number;
max_tokens: number;
stop: string[];
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
subjobs: Array<any>;
Expand Down Expand Up @@ -96,6 +97,10 @@ export interface TogetherAIInputs extends BaseLLMParams {
* Limit the number of tokens generated.
*/
maxTokens?: number;
/**
* A list of tokens at which the generation should stop.
*/
stop?: string[];
}

export interface TogetherAICallOptions
Expand All @@ -110,6 +115,7 @@ export interface TogetherAICallOptions
| "logprobs"
| "safetyModel"
| "maxTokens"
| "stop"
> {}

export class TogetherAI extends LLM<TogetherAICallOptions> {
Expand Down Expand Up @@ -137,6 +143,8 @@ export class TogetherAI extends LLM<TogetherAICallOptions> {

safetyModel?: string;

stop?: string[];

private apiKey: string;

private inferenceUrl = "https://api.together.xyz/inference";
Expand All @@ -162,6 +170,7 @@ export class TogetherAI extends LLM<TogetherAICallOptions> {
this.logprobs = inputs.logprobs;
this.safetyModel = inputs.safetyModel;
this.maxTokens = inputs.maxTokens;
this.stop = inputs.stop;
}

_llmType() {
Expand All @@ -188,6 +197,7 @@ export class TogetherAI extends LLM<TogetherAICallOptions> {
stream_tokens: this?.streaming,
safety_model: this?.safetyModel ?? options?.safetyModel,
max_tokens: this?.maxTokens ?? options?.maxTokens,
stop: this?.stop ?? options?.stop,
};
return body;
}
Expand Down

2 comments on commit 9769205

@vercel
Copy link

@vercel vercel bot commented on 9769205 Dec 20, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

langchainjs-docs – ./docs/core_docs/

langchainjs-docs-ruddy.vercel.app
langchainjs-docs-git-main-langchain.vercel.app
langchainjs-docs-langchain.vercel.app
js.langchain.com

@vercel
Copy link

@vercel vercel bot commented on 9769205 Dec 20, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.