Add support for configuring max_completion_tokens for OpenAI

Related to db9422740c
This commit is contained in:
Slavi Pantaleev
2025-02-27 09:52:24 +02:00
parent 692d61b239
commit 47d8edea70
5 changed files with 13 additions and 2 deletions

View File

@@ -58,6 +58,9 @@ pub struct TextGenerationConfig {
#[serde(default)]
pub max_response_tokens: Option<u32>,
#[serde(default)]
pub max_completion_tokens: Option<u32>,
#[serde(default)]
pub max_context_tokens: u32,
}
@@ -69,6 +72,7 @@ impl Default for TextGenerationConfig {
prompt: Some(default_prompt().to_owned()),
temperature: super::super::default_temperature(),
max_response_tokens: Some(16_384),
max_completion_tokens: None,
max_context_tokens: 128_000,
}
}

View File

@@ -144,6 +144,10 @@ impl ControllerTrait for Controller {
request_builder.max_tokens(max_response_tokens);
}
if let Some(max_completion_tokens) = text_generation_config.max_completion_tokens {
request_builder.max_completion_tokens(max_completion_tokens);
}
let request = request_builder.build()?;
if let Ok(request_as_json) = serde_json::to_string(&request) {

View File

@@ -93,6 +93,7 @@ impl TryInto<OpenAITextGenerationConfig> for TextGenerationConfig {
prompt: self.prompt,
temperature: self.temperature,
max_response_tokens: self.max_response_tokens,
max_completion_tokens: None,
max_context_tokens: self.max_context_tokens,
})
}