Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stop option to Together AI #3714

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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