fix: request payload for o1 models (#921)

Co-authored-by: Salman Mohammed <smohammed@squareup.com>
This commit is contained in:
Wendy Tang
2025-01-30 07:24:32 -08:00
committed by GitHub
parent 6e9423b8c4
commit e8ced5a385
4 changed files with 31 additions and 11 deletions
+25 -7
View File
@@ -256,8 +256,16 @@ pub fn create_request(
tools: &[Tool],
image_format: &ImageFormat,
) -> anyhow::Result<Value, Error> {
if model_config.model_name.starts_with("o1-mini") {
return Err(anyhow!(
"o1-mini model is not currently supported since Goose uses tool calling."
));
}
let is_o1 = model_config.model_name.starts_with("o1");
let system_message = json!({
"role": "system",
"role": if is_o1 { "developer" } else { "system" },
"content": system
});
@@ -282,17 +290,27 @@ pub fn create_request(
.unwrap()
.insert("tools".to_string(), json!(tools_spec));
}
if let Some(temp) = model_config.temperature {
payload
.as_object_mut()
.unwrap()
.insert("temperature".to_string(), json!(temp));
// o1 models currently don't support temperature
if !is_o1 {
if let Some(temp) = model_config.temperature {
payload
.as_object_mut()
.unwrap()
.insert("temperature".to_string(), json!(temp));
}
}
// o1 models use max_completion_tokens instead of max_tokens
if let Some(tokens) = model_config.max_tokens {
let key = if is_o1 {
"max_completion_tokens"
} else {
"max_tokens"
};
payload
.as_object_mut()
.unwrap()
.insert("max_tokens".to_string(), json!(tokens));
.insert(key.to_string(), json!(tokens));
}
Ok(payload)
}
-1
View File
@@ -19,7 +19,6 @@ pub const OPEN_AI_KNOWN_MODELS: &[&str] = &[
"gpt-4-turbo",
"gpt-3.5-turbo",
"o1",
"o1-mini",
];
pub const OPEN_AI_DOC_URL: &str = "https://platform.openai.com/docs/models";