mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
Add base_path field to custom provider config (#7558)
Signed-off-by: Dan Prince <dprince@redhat.com>
This commit is contained in:
@@ -2027,6 +2027,7 @@ fn add_provider() -> anyhow::Result<()> {
|
||||
headers,
|
||||
requires_auth,
|
||||
catalog_provider_id: None,
|
||||
base_path: None,
|
||||
})?;
|
||||
|
||||
cliclack::outro(format!("Custom provider added: {}", display_name))?;
|
||||
|
||||
@@ -100,6 +100,8 @@ pub struct UpdateCustomProviderRequest {
|
||||
pub requires_auth: bool,
|
||||
#[serde(default)]
|
||||
pub catalog_provider_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
fn default_requires_auth() -> bool {
|
||||
@@ -655,6 +657,7 @@ pub async fn create_custom_provider(
|
||||
headers: request.headers,
|
||||
requires_auth: request.requires_auth,
|
||||
catalog_provider_id: request.catalog_provider_id,
|
||||
base_path: request.base_path,
|
||||
},
|
||||
)?;
|
||||
|
||||
@@ -726,6 +729,7 @@ pub async fn update_custom_provider(
|
||||
headers: request.headers,
|
||||
requires_auth: request.requires_auth,
|
||||
catalog_provider_id: request.catalog_provider_id,
|
||||
base_path: request.base_path,
|
||||
},
|
||||
)?;
|
||||
|
||||
|
||||
@@ -44,6 +44,8 @@ pub struct DeclarativeProviderConfig {
|
||||
pub requires_auth: bool,
|
||||
#[serde(default)]
|
||||
pub catalog_provider_id: Option<String>,
|
||||
#[serde(default)]
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
fn default_requires_auth() -> bool {
|
||||
@@ -105,6 +107,7 @@ pub struct CreateCustomProviderParams {
|
||||
pub headers: Option<HashMap<String, String>>,
|
||||
pub requires_auth: bool,
|
||||
pub catalog_provider_id: Option<String>,
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -119,6 +122,7 @@ pub struct UpdateCustomProviderParams {
|
||||
pub headers: Option<HashMap<String, String>>,
|
||||
pub requires_auth: bool,
|
||||
pub catalog_provider_id: Option<String>,
|
||||
pub base_path: Option<String>,
|
||||
}
|
||||
|
||||
pub fn create_custom_provider(
|
||||
@@ -159,6 +163,7 @@ pub fn create_custom_provider(
|
||||
supports_streaming: params.supports_streaming,
|
||||
requires_auth: params.requires_auth,
|
||||
catalog_provider_id: params.catalog_provider_id,
|
||||
base_path: params.base_path,
|
||||
};
|
||||
|
||||
let custom_providers_dir = custom_providers_dir();
|
||||
@@ -221,6 +226,7 @@ pub fn update_custom_provider(params: UpdateCustomProviderParams) -> Result<()>
|
||||
supports_streaming: params.supports_streaming,
|
||||
requires_auth: params.requires_auth,
|
||||
catalog_provider_id: params.catalog_provider_id,
|
||||
base_path: params.base_path,
|
||||
};
|
||||
|
||||
let file_path = custom_providers_dir().join(format!("{}.json", updated_config.name));
|
||||
|
||||
@@ -168,11 +168,15 @@ impl OpenAiProvider {
|
||||
} else {
|
||||
format!("{}://{}", url.scheme(), url.host_str().unwrap_or(""))
|
||||
};
|
||||
let base_path = url.path().trim_start_matches('/').to_string();
|
||||
let base_path = if base_path.is_empty() || base_path == "v1" || base_path == "v1/" {
|
||||
"v1/chat/completions".to_string()
|
||||
let base_path = if let Some(ref explicit_path) = config.base_path {
|
||||
explicit_path.trim_start_matches('/').to_string()
|
||||
} else {
|
||||
base_path
|
||||
let url_path = url.path().trim_start_matches('/').to_string();
|
||||
if url_path.is_empty() || url_path == "v1" || url_path == "v1/" {
|
||||
"v1/chat/completions".to_string()
|
||||
} else {
|
||||
url_path
|
||||
}
|
||||
};
|
||||
|
||||
let timeout_secs = config.timeout_seconds.unwrap_or(600);
|
||||
|
||||
@@ -4177,6 +4177,10 @@
|
||||
"api_key_env": {
|
||||
"type": "string"
|
||||
},
|
||||
"base_path": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"base_url": {
|
||||
"type": "string"
|
||||
},
|
||||
@@ -8159,6 +8163,10 @@
|
||||
"api_url": {
|
||||
"type": "string"
|
||||
},
|
||||
"base_path": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
},
|
||||
"catalog_provider_id": {
|
||||
"type": "string",
|
||||
"nullable": true
|
||||
|
||||
@@ -173,6 +173,7 @@ export type CspMetadata = {
|
||||
|
||||
export type DeclarativeProviderConfig = {
|
||||
api_key_env?: string;
|
||||
base_path?: string | null;
|
||||
base_url: string;
|
||||
catalog_provider_id?: string | null;
|
||||
description?: string | null;
|
||||
@@ -1477,6 +1478,7 @@ export type UiMetadata = {
|
||||
export type UpdateCustomProviderRequest = {
|
||||
api_key: string;
|
||||
api_url: string;
|
||||
base_path?: string | null;
|
||||
catalog_provider_id?: string | null;
|
||||
display_name: string;
|
||||
engine: string;
|
||||
|
||||
Reference in New Issue
Block a user