Skip to content

Commit 47d8ede

Browse files
committed
Add support for configuring max_completion_tokens for OpenAI
Related to db94227
1 parent 692d61b commit 47d8ede

File tree

5 files changed

+13
-2
lines changed

5 files changed

+13
-2
lines changed

docs/sample-provider-configs/openai-o1.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ text_generation:
66
prompt: null
77
temperature: 1.0
88
# o1 models do not support max_response_tokens.
9-
# They use `max_completion_tokens` as an alternative,
10-
# but we don't support it yet (see https://github.com/64bit/async-openai/issues/272).
9+
# They use `max_completion_tokens` as an alternative
1110
max_response_tokens: null
11+
max_completion_tokens: 16384
1212
max_context_tokens: 128000
1313
speech_to_text:
1414
model_id: whisper-1

etc/app/config.yml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ agents:
8080
# prompt: "You are a brief, but helpful bot called {{ baibot_name }} powered by the {{ baibot_model_id }} model. The date/time of this conversation's start is: {{ baibot_conversation_start_time_utc }}."
8181
# temperature: 1.0
8282
# max_response_tokens: 16384
83+
# # Reasoning models need to use `max_completion_tokens` instead of `max_response_tokens`.
84+
# max_completion_tokens: ~
8385
# max_context_tokens: 128000
8486
# speech_to_text:
8587
# model_id: whisper-1

src/agent/provider/openai/config.rs

+4
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub struct TextGenerationConfig {
5858
#[serde(default)]
5959
pub max_response_tokens: Option<u32>,
6060

61+
#[serde(default)]
62+
pub max_completion_tokens: Option<u32>,
63+
6164
#[serde(default)]
6265
pub max_context_tokens: u32,
6366
}
@@ -69,6 +72,7 @@ impl Default for TextGenerationConfig {
6972
prompt: Some(default_prompt().to_owned()),
7073
temperature: super::super::default_temperature(),
7174
max_response_tokens: Some(16_384),
75+
max_completion_tokens: None,
7276
max_context_tokens: 128_000,
7377
}
7478
}

src/agent/provider/openai/controller.rs

+4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ impl ControllerTrait for Controller {
144144
request_builder.max_tokens(max_response_tokens);
145145
}
146146

147+
if let Some(max_completion_tokens) = text_generation_config.max_completion_tokens {
148+
request_builder.max_completion_tokens(max_completion_tokens);
149+
}
150+
147151
let request = request_builder.build()?;
148152

149153
if let Ok(request_as_json) = serde_json::to_string(&request) {

src/agent/provider/openai_compat/config.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ impl TryInto<OpenAITextGenerationConfig> for TextGenerationConfig {
9393
prompt: self.prompt,
9494
temperature: self.temperature,
9595
max_response_tokens: self.max_response_tokens,
96+
max_completion_tokens: None,
9697
max_context_tokens: self.max_context_tokens,
9798
})
9899
}

0 commit comments

Comments
 (0)