Enable runtime access to provider name (#5399)

This commit is contained in:
Will Pfleger
2025-10-28 14:21:24 -04:00
committed by GitHub
parent f1ad5490b6
commit 4d8c91efbd
25 changed files with 196 additions and 3 deletions
+4
View File
@@ -309,6 +309,10 @@ mod tests {
crate::providers::base::ProviderMetadata::empty() crate::providers::base::ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
+7
View File
@@ -43,6 +43,7 @@ pub struct AnthropicProvider {
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
supports_streaming: bool, supports_streaming: bool,
name: String,
} }
impl AnthropicProvider { impl AnthropicProvider {
@@ -67,6 +68,7 @@ impl AnthropicProvider {
api_client, api_client,
model, model,
supports_streaming: true, supports_streaming: true,
name: Self::metadata().name,
}) })
} }
@@ -91,6 +93,7 @@ impl AnthropicProvider {
api_client, api_client,
model, model,
supports_streaming: config.supports_streaming.unwrap_or(true), supports_streaming: config.supports_streaming.unwrap_or(true),
name: config.name.clone(),
}) })
} }
@@ -176,6 +179,10 @@ impl Provider for AnthropicProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+6
View File
@@ -27,6 +27,7 @@ pub struct AzureProvider {
deployment_name: String, deployment_name: String,
api_version: String, api_version: String,
model: ModelConfig, model: ModelConfig,
name: String,
} }
impl Serialize for AzureProvider { impl Serialize for AzureProvider {
@@ -94,6 +95,7 @@ impl AzureProvider {
deployment_name, deployment_name,
api_version, api_version,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -128,6 +130,10 @@ impl Provider for AzureProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+3
View File
@@ -325,6 +325,9 @@ pub trait Provider: Send + Sync {
where where
Self: Sized; Self: Sized;
/// Get the name of this provider instance
fn get_name(&self) -> &str;
// Internal implementation of complete, used by complete_fast and complete // Internal implementation of complete, used by complete_fast and complete
// Providers should override this to implement their actual completion logic // Providers should override this to implement their actual completion logic
async fn complete_with_model( async fn complete_with_model(
+7
View File
@@ -42,6 +42,8 @@ pub struct BedrockProvider {
model: ModelConfig, model: ModelConfig,
#[serde(skip)] #[serde(skip)]
retry_config: RetryConfig, retry_config: RetryConfig,
#[serde(skip)]
name: String,
} }
impl BedrockProvider { impl BedrockProvider {
@@ -78,6 +80,7 @@ impl BedrockProvider {
client, client,
model, model,
retry_config, retry_config,
name: Self::metadata().name,
}) })
} }
@@ -184,6 +187,10 @@ impl Provider for BedrockProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn retry_config(&self) -> RetryConfig { fn retry_config(&self) -> RetryConfig {
self.retry_config.clone() self.retry_config.clone()
} }
@@ -24,6 +24,8 @@ pub const CLAUDE_CODE_DOC_URL: &str = "https://claude.ai/cli";
pub struct ClaudeCodeProvider { pub struct ClaudeCodeProvider {
command: String, command: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl ClaudeCodeProvider { impl ClaudeCodeProvider {
@@ -42,6 +44,7 @@ impl ClaudeCodeProvider {
Ok(Self { Ok(Self {
command: resolved_command, command: resolved_command,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -463,6 +466,10 @@ impl Provider for ClaudeCodeProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
// Return the model config with appropriate context limit for Claude models // Return the model config with appropriate context limit for Claude models
self.model.clone() self.model.clone()
@@ -23,6 +23,8 @@ pub const CURSOR_AGENT_DOC_URL: &str = "https://docs.cursor.com/en/cli/overview"
pub struct CursorAgentProvider { pub struct CursorAgentProvider {
command: String, command: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl CursorAgentProvider { impl CursorAgentProvider {
@@ -41,6 +43,7 @@ impl CursorAgentProvider {
Ok(Self { Ok(Self {
command: resolved_command, command: resolved_command,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -395,6 +398,10 @@ impl Provider for CursorAgentProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
// Return the model config with appropriate context limit for Cursor models // Return the model config with appropriate context limit for Cursor models
self.model.clone() self.model.clone()
+8
View File
@@ -106,6 +106,8 @@ pub struct DatabricksProvider {
image_format: ImageFormat, image_format: ImageFormat,
#[serde(skip)] #[serde(skip)]
retry_config: RetryConfig, retry_config: RetryConfig,
#[serde(skip)]
name: String,
} }
impl DatabricksProvider { impl DatabricksProvider {
@@ -146,6 +148,7 @@ impl DatabricksProvider {
model: model.clone(), model: model.clone(),
image_format: ImageFormat::OpenAi, image_format: ImageFormat::OpenAi,
retry_config, retry_config,
name: Self::metadata().name,
}; };
// Check if the default fast model exists in the workspace // Check if the default fast model exists in the workspace
@@ -222,6 +225,7 @@ impl DatabricksProvider {
model, model,
image_format: ImageFormat::OpenAi, image_format: ImageFormat::OpenAi,
retry_config: RetryConfig::default(), retry_config: RetryConfig::default(),
name: Self::metadata().name,
}) })
} }
@@ -260,6 +264,10 @@ impl Provider for DatabricksProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn retry_config(&self) -> RetryConfig { fn retry_config(&self) -> RetryConfig {
self.retry_config.clone() self.retry_config.clone()
} }
@@ -76,6 +76,8 @@ pub struct GcpVertexAIProvider {
/// Retry configuration for handling rate limit errors /// Retry configuration for handling rate limit errors
#[serde(skip)] #[serde(skip)]
retry_config: RetryConfig, retry_config: RetryConfig,
#[serde(skip)]
name: String,
} }
impl GcpVertexAIProvider { impl GcpVertexAIProvider {
@@ -109,6 +111,7 @@ impl GcpVertexAIProvider {
location, location,
model, model,
retry_config, retry_config,
name: Self::metadata().name,
}) })
} }
@@ -494,6 +497,10 @@ impl Provider for GcpVertexAIProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
/// Completes a model interaction by sending a request and processing the response. /// Completes a model interaction by sending a request and processing the response.
/// ///
/// # Arguments /// # Arguments
+7
View File
@@ -24,6 +24,8 @@ pub const GEMINI_CLI_DOC_URL: &str = "https://ai.google.dev/gemini-api/docs";
pub struct GeminiCliProvider { pub struct GeminiCliProvider {
command: String, command: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl GeminiCliProvider { impl GeminiCliProvider {
@@ -42,6 +44,7 @@ impl GeminiCliProvider {
Ok(Self { Ok(Self {
command: resolved_command, command: resolved_command,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -311,6 +314,10 @@ impl Provider for GeminiCliProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
// Return the model config with appropriate context limit for Gemini models // Return the model config with appropriate context limit for Gemini models
self.model.clone() self.model.clone()
@@ -113,6 +113,8 @@ pub struct GithubCopilotProvider {
#[serde(skip)] #[serde(skip)]
mu: tokio::sync::Mutex<RefCell<Option<CopilotState>>>, mu: tokio::sync::Mutex<RefCell<Option<CopilotState>>>,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl GithubCopilotProvider { impl GithubCopilotProvider {
@@ -127,6 +129,7 @@ impl GithubCopilotProvider {
cache, cache,
mu, mu,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -392,6 +395,10 @@ impl Provider for GithubCopilotProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+11 -1
View File
@@ -39,6 +39,8 @@ pub struct GoogleProvider {
#[serde(skip)] #[serde(skip)]
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl GoogleProvider { impl GoogleProvider {
@@ -59,7 +61,11 @@ impl GoogleProvider {
let api_client = let api_client =
ApiClient::new(host, auth)?.with_header("Content-Type", "application/json")?; ApiClient::new(host, auth)?.with_header("Content-Type", "application/json")?;
Ok(Self { api_client, model }) Ok(Self {
api_client,
model,
name: Self::metadata().name,
})
} }
async fn post(&self, model_name: &str, payload: &Value) -> Result<Value, ProviderError> { async fn post(&self, model_name: &str, payload: &Value) -> Result<Value, ProviderError> {
@@ -86,6 +92,10 @@ impl Provider for GoogleProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+13
View File
@@ -320,6 +320,11 @@ impl Provider for LeadWorkerProvider {
) )
} }
fn get_name(&self) -> &str {
// Return the lead provider's name as the default
self.lead_provider.get_name()
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
// Return the lead provider's model config as the default // Return the lead provider's model config as the default
// In practice, this might need to be more sophisticated // In practice, this might need to be more sophisticated
@@ -472,6 +477,10 @@ mod tests {
ProviderMetadata::empty() ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock-lead"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
@@ -634,6 +643,10 @@ mod tests {
ProviderMetadata::empty() ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock-lead"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
+7
View File
@@ -23,6 +23,8 @@ pub struct LiteLLMProvider {
api_client: ApiClient, api_client: ApiClient,
base_path: String, base_path: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl LiteLLMProvider { impl LiteLLMProvider {
@@ -67,6 +69,7 @@ impl LiteLLMProvider {
api_client, api_client,
base_path, base_path,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -154,6 +157,10 @@ impl Provider for LiteLLMProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+7
View File
@@ -47,6 +47,7 @@ pub struct OllamaProvider {
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
supports_streaming: bool, supports_streaming: bool,
name: String,
} }
impl OllamaProvider { impl OllamaProvider {
@@ -92,6 +93,7 @@ impl OllamaProvider {
api_client, api_client,
model, model,
supports_streaming: true, supports_streaming: true,
name: Self::metadata().name,
}) })
} }
@@ -131,6 +133,7 @@ impl OllamaProvider {
api_client, api_client,
model, model,
supports_streaming: config.supports_streaming.unwrap_or(true), supports_streaming: config.supports_streaming.unwrap_or(true),
name: config.name.clone(),
}) })
} }
@@ -176,6 +179,10 @@ impl Provider for OllamaProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+7
View File
@@ -54,6 +54,7 @@ pub struct OpenAiProvider {
model: ModelConfig, model: ModelConfig,
custom_headers: Option<HashMap<String, String>>, custom_headers: Option<HashMap<String, String>>,
supports_streaming: bool, supports_streaming: bool,
name: String,
} }
impl OpenAiProvider { impl OpenAiProvider {
@@ -107,6 +108,7 @@ impl OpenAiProvider {
model, model,
custom_headers, custom_headers,
supports_streaming: true, supports_streaming: true,
name: Self::metadata().name,
}) })
} }
@@ -163,6 +165,7 @@ impl OpenAiProvider {
model, model,
custom_headers: config.headers, custom_headers: config.headers,
supports_streaming: config.supports_streaming.unwrap_or(true), supports_streaming: config.supports_streaming.unwrap_or(true),
name: config.name.clone(),
}) })
} }
@@ -201,6 +204,10 @@ impl Provider for OpenAiProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+11 -1
View File
@@ -40,6 +40,8 @@ pub struct OpenRouterProvider {
#[serde(skip)] #[serde(skip)]
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl OpenRouterProvider { impl OpenRouterProvider {
@@ -57,7 +59,11 @@ impl OpenRouterProvider {
.with_header("HTTP-Referer", "https://block.github.io/goose")? .with_header("HTTP-Referer", "https://block.github.io/goose")?
.with_header("X-Title", "goose")?; .with_header("X-Title", "goose")?;
Ok(Self { api_client, model }) Ok(Self {
api_client,
model,
name: Self::metadata().name,
})
} }
async fn post(&self, payload: &Value) -> Result<Value, ProviderError> { async fn post(&self, payload: &Value) -> Result<Value, ProviderError> {
@@ -242,6 +248,10 @@ impl Provider for OpenRouterProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
@@ -30,6 +30,8 @@ pub struct SageMakerTgiProvider {
sagemaker_client: SageMakerClient, sagemaker_client: SageMakerClient,
endpoint_name: String, endpoint_name: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl SageMakerTgiProvider { impl SageMakerTgiProvider {
@@ -79,6 +81,7 @@ impl SageMakerTgiProvider {
sagemaker_client, sagemaker_client,
endpoint_name, endpoint_name,
model, model,
name: Self::metadata().name,
}) })
} }
@@ -272,6 +275,10 @@ impl Provider for SageMakerTgiProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+7
View File
@@ -48,6 +48,8 @@ pub struct SnowflakeProvider {
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
image_format: ImageFormat, image_format: ImageFormat,
#[serde(skip)]
name: String,
} }
impl SnowflakeProvider { impl SnowflakeProvider {
@@ -101,6 +103,7 @@ impl SnowflakeProvider {
api_client, api_client,
model, model,
image_format: ImageFormat::OpenAi, image_format: ImageFormat::OpenAi,
name: Self::metadata().name,
}) })
} }
@@ -302,6 +305,10 @@ impl Provider for SnowflakeProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
@@ -36,6 +36,7 @@ pub struct TestProvider {
inner: Option<Arc<dyn Provider>>, inner: Option<Arc<dyn Provider>>,
records: Arc<Mutex<HashMap<String, TestRecord>>>, records: Arc<Mutex<HashMap<String, TestRecord>>>,
file_path: String, file_path: String,
name: String,
} }
impl TestProvider { impl TestProvider {
@@ -44,6 +45,7 @@ impl TestProvider {
inner: Some(inner), inner: Some(inner),
records: Arc::new(Mutex::new(HashMap::new())), records: Arc::new(Mutex::new(HashMap::new())),
file_path: file_path.into(), file_path: file_path.into(),
name: Self::metadata().name,
} }
} }
@@ -55,6 +57,7 @@ impl TestProvider {
inner: None, inner: None,
records: Arc::new(Mutex::new(records)), records: Arc::new(Mutex::new(records)),
file_path, file_path,
name: Self::metadata().name,
}) })
} }
@@ -112,6 +115,10 @@ impl Provider for TestProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
async fn complete_with_model( async fn complete_with_model(
&self, &self,
_model_config: &ModelConfig, _model_config: &ModelConfig,
@@ -189,6 +196,10 @@ mod tests {
) )
} }
fn get_name(&self) -> &str {
"mock-testprovider"
}
async fn complete_with_model( async fn complete_with_model(
&self, &self,
_model_config: &ModelConfig, _model_config: &ModelConfig,
+7
View File
@@ -46,6 +46,8 @@ pub struct TetrateProvider {
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
supports_streaming: bool, supports_streaming: bool,
#[serde(skip)]
name: String,
} }
impl TetrateProvider { impl TetrateProvider {
@@ -66,6 +68,7 @@ impl TetrateProvider {
api_client, api_client,
model, model,
supports_streaming: true, supports_streaming: true,
name: Self::metadata().name,
}) })
} }
@@ -150,6 +153,10 @@ impl Provider for TetrateProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+7
View File
@@ -78,6 +78,8 @@ pub struct VeniceProvider {
base_path: String, base_path: String,
models_path: String, models_path: String,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl VeniceProvider { impl VeniceProvider {
@@ -105,6 +107,7 @@ impl VeniceProvider {
base_path, base_path,
models_path, models_path,
model, model,
name: Self::metadata().name,
}; };
Ok(instance) Ok(instance)
@@ -210,6 +213,10 @@ impl Provider for VeniceProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+11 -1
View File
@@ -42,6 +42,8 @@ pub struct XaiProvider {
#[serde(skip)] #[serde(skip)]
api_client: ApiClient, api_client: ApiClient,
model: ModelConfig, model: ModelConfig,
#[serde(skip)]
name: String,
} }
impl XaiProvider { impl XaiProvider {
@@ -55,7 +57,11 @@ impl XaiProvider {
let auth = AuthMethod::BearerToken(api_key); let auth = AuthMethod::BearerToken(api_key);
let api_client = ApiClient::new(host, auth)?; let api_client = ApiClient::new(host, auth)?;
Ok(Self { api_client, model }) Ok(Self {
api_client,
model,
name: Self::metadata().name,
})
} }
async fn post(&self, payload: Value) -> Result<Value, ProviderError> { async fn post(&self, payload: Value) -> Result<Value, ProviderError> {
@@ -87,6 +93,10 @@ impl Provider for XaiProvider {
) )
} }
fn get_name(&self) -> &str {
&self.name
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model.clone() self.model.clone()
} }
+4
View File
@@ -1361,6 +1361,10 @@ mod tests {
) )
} }
fn get_name(&self) -> &str {
"mock-scheduler"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
+16
View File
@@ -557,6 +557,10 @@ mod final_output_tool_tests {
goose::providers::base::ProviderMetadata::empty() goose::providers::base::ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock-test"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
@@ -672,6 +676,10 @@ mod final_output_tool_tests {
goose::providers::base::ProviderMetadata::empty() goose::providers::base::ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock-test"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
@@ -858,6 +866,10 @@ mod retry_tests {
goose::providers::base::ProviderMetadata::empty() goose::providers::base::ProviderMetadata::empty()
} }
fn get_name(&self) -> &str {
"mock-test"
}
fn get_model_config(&self) -> ModelConfig { fn get_model_config(&self) -> ModelConfig {
self.model_config.clone() self.model_config.clone()
} }
@@ -1080,6 +1092,10 @@ mod max_turns_tests {
config_keys: vec![], config_keys: vec![],
} }
} }
fn get_name(&self) -> &str {
"mock-test"
}
} }
#[tokio::test] #[tokio::test]