Skip to content

Commit

Permalink
Support modifying AZURE_OPENAI_API_VERSION (#1042)
Browse files Browse the repository at this point in the history
Co-authored-by: Jean-FrançoisMillet <[email protected]>
  • Loading branch information
deephbz and Jean-FrançoisMillet authored Feb 12, 2025
1 parent 255c849 commit 5e8a8ba
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions crates/goose/src/providers/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use mcp_core::tool::Tool;
pub const AZURE_DEFAULT_MODEL: &str = "gpt-4o";
pub const AZURE_DOC_URL: &str =
"https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models";
pub const AZURE_API_VERSION: &str = "2024-10-21";
pub const AZURE_DEFAULT_API_VERSION: &str = "2024-10-21";
pub const AZURE_OPENAI_KNOWN_MODELS: &[&str] = &["gpt-4o", "gpt-4o-mini", "gpt-4"];

#[derive(Debug, serde::Serialize)]
Expand All @@ -25,6 +25,7 @@ pub struct AzureProvider {
endpoint: String,
api_key: String,
deployment_name: String,
api_version: String,
model: ModelConfig,
}

Expand All @@ -41,6 +42,9 @@ impl AzureProvider {
let api_key: String = config.get_secret("AZURE_OPENAI_API_KEY")?;
let endpoint: String = config.get("AZURE_OPENAI_ENDPOINT")?;
let deployment_name: String = config.get("AZURE_OPENAI_DEPLOYMENT_NAME")?;
let api_version: String = config
.get("AZURE_OPENAI_API_VERSION")
.unwrap_or_else(|_| AZURE_DEFAULT_API_VERSION.to_string());

let client = Client::builder()
.timeout(Duration::from_secs(600))
Expand All @@ -51,6 +55,7 @@ impl AzureProvider {
endpoint,
api_key,
deployment_name,
api_version,
model,
})
}
Expand All @@ -63,7 +68,7 @@ impl AzureProvider {
"openai/deployments/{}/chat/completions",
self.deployment_name
));
base_url.set_query(Some(&format!("api-version={}", AZURE_API_VERSION)));
base_url.set_query(Some(&format!("api-version={}", self.api_version)));

let response: reqwest::Response = self
.client
Expand Down Expand Up @@ -99,6 +104,12 @@ impl Provider for AzureProvider {
false,
Some("Name of your Azure OpenAI deployment"),
),
ConfigKey::new(
"AZURE_OPENAI_API_VERSION",
false,
false,
Some("Azure OpenAI API version, default: 2024-10-21"),
),
],
)
}
Expand Down

0 comments on commit 5e8a8ba

Please sign in to comment.