Skip to content

Commit d201fdd

Browse files
committed
feat(baseten): support top_p, presence_penalty, frequency_penalty
Adds `topP`, `presencePenalty`, and `frequencyPenalty` to `BasetenLLMOptions`, forwarded to Baseten's OpenAI-compatible endpoint as `top_p`, `presence_penalty`, and `frequency_penalty` respectively. These are documented sampling parameters for Baseten inference. Also switches the existing `temperature` plumbing from a truthy check to `!== undefined` so that `temperature: 0` is preserved.
1 parent adf2651 commit d201fdd

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/agents-plugin-baseten": patch
3+
---
4+
5+
feat(baseten): support top_p, presence_penalty, and frequency_penalty options on the LLM

plugins/baseten/src/llm.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ export interface LLMOptions {
1717
baseURL?: string;
1818
user?: string;
1919
temperature?: number;
20+
topP?: number;
21+
presencePenalty?: number;
22+
frequencyPenalty?: number;
2023
client?: OpenAI;
2124
toolChoice?: llm.ToolChoice;
2225
parallelToolCalls?: boolean;
@@ -96,10 +99,22 @@ export class OpenAILLM extends llm.LLM {
9699
extras.max_completion_tokens = this.#opts.maxCompletionTokens;
97100
}
98101

99-
if (this.#opts.temperature) {
102+
if (this.#opts.temperature !== undefined) {
100103
extras.temperature = this.#opts.temperature;
101104
}
102105

106+
if (this.#opts.topP !== undefined) {
107+
extras.top_p = this.#opts.topP;
108+
}
109+
110+
if (this.#opts.presencePenalty !== undefined) {
111+
extras.presence_penalty = this.#opts.presencePenalty;
112+
}
113+
114+
if (this.#opts.frequencyPenalty !== undefined) {
115+
extras.frequency_penalty = this.#opts.frequencyPenalty;
116+
}
117+
103118
if (this.#opts.serviceTier) {
104119
extras.service_tier = this.#opts.serviceTier;
105120
}
@@ -159,6 +174,9 @@ export class LLM extends OpenAILLM {
159174
apiKey,
160175
baseURL: 'https://inference.baseten.co/v1',
161176
temperature: opts.temperature,
177+
topP: opts.topP,
178+
presencePenalty: opts.presencePenalty,
179+
frequencyPenalty: opts.frequencyPenalty,
162180
user: opts.user,
163181
maxCompletionTokens: opts.maxTokens,
164182
toolChoice: opts.toolChoice,

plugins/baseten/src/types.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,19 @@ export interface BasetenLLMOptions {
1515
apiKey?: string;
1616
model: string;
1717
temperature?: number;
18+
/** Nucleus sampling parameter. Forwarded to Baseten as `top_p`. */
19+
topP?: number;
1820
maxTokens?: number;
21+
/**
22+
* Penalty for new tokens based on whether they appear in the text so far.
23+
* Forwarded to Baseten as `presence_penalty`.
24+
*/
25+
presencePenalty?: number;
26+
/**
27+
* Penalty for new tokens based on their frequency in the text so far.
28+
* Forwarded to Baseten as `frequency_penalty`.
29+
*/
30+
frequencyPenalty?: number;
1931
user?: string;
2032
toolChoice?: 'none' | 'auto' | 'required' | { type: 'function'; function: { name: string } };
2133
parallelToolCalls?: boolean;

0 commit comments

Comments
 (0)