mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix: keep image edit handler provider neutral
This commit is contained in:
parent
d3598d7dc4
commit
9cf53e13c7
3 changed files with 30 additions and 3 deletions
|
|
@ -11,6 +11,18 @@ use super::types::{ImageEditInputFile, ImageEditRequestData, ImageEditResponseDa
|
|||
pub trait ImageEditProviderConfig: Send + Sync {
|
||||
fn supported_image_edit_params(&self) -> &'static [&'static str];
|
||||
|
||||
fn resolve_api_key(
|
||||
&self,
|
||||
api_key: Option<&str>,
|
||||
env_lookup: &dyn Fn(&str) -> Option<String>,
|
||||
) -> Option<String>;
|
||||
|
||||
fn complete_url(
|
||||
&self,
|
||||
api_base: Option<&str>,
|
||||
env_lookup: &dyn Fn(&str) -> Option<String>,
|
||||
) -> CoreResult<String>;
|
||||
|
||||
fn map_image_edit_params(&self, non_default_params: &Map<String, Value>) -> Map<String, Value> {
|
||||
let mut mapped_params = Map::new();
|
||||
for (param, value) in non_default_params {
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ use litellm_core::image_edit::types::{ImageEditInputFile, ImageEditRequestFormat
|
|||
use litellm_core::{CoreResult, LlmProvider};
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
use crate::vllm::image_edit::transformation as vllm;
|
||||
use crate::vllm::image_edit::transformation::VLLM_IMAGE_EDIT_CONFIG;
|
||||
|
||||
const IMAGE_EDIT_TIMEOUT_SECS: u64 = 600;
|
||||
|
|
@ -126,8 +125,8 @@ pub async fn image_edit(request: ImageEditRequest<'_>) -> CoreResult<Value> {
|
|||
let config = image_edit_config_for(provider)
|
||||
.ok_or_else(|| CoreError::InvalidProvider(provider.to_string()))?;
|
||||
|
||||
let api_key = vllm::resolve_api_key(request.api_key, &|key| std::env::var(key).ok());
|
||||
let url = vllm::complete_url(request.api_base, &|key| std::env::var(key).ok())?;
|
||||
let api_key = config.resolve_api_key(request.api_key, &|key| std::env::var(key).ok());
|
||||
let url = config.complete_url(request.api_base, &|key| std::env::var(key).ok())?;
|
||||
let filtered_params = config.map_image_edit_params(&request.optional_params);
|
||||
let transformed = config.transform_image_edit_request(
|
||||
request.model,
|
||||
|
|
|
|||
|
|
@ -62,6 +62,22 @@ impl ImageEditProviderConfig for VllmImageEditConfig {
|
|||
SUPPORTED_IMAGE_EDIT_PARAMS
|
||||
}
|
||||
|
||||
fn resolve_api_key(
|
||||
&self,
|
||||
api_key: Option<&str>,
|
||||
env_lookup: &dyn Fn(&str) -> Option<String>,
|
||||
) -> Option<String> {
|
||||
resolve_api_key(api_key, env_lookup)
|
||||
}
|
||||
|
||||
fn complete_url(
|
||||
&self,
|
||||
api_base: Option<&str>,
|
||||
env_lookup: &dyn Fn(&str) -> Option<String>,
|
||||
) -> CoreResult<String> {
|
||||
complete_url(api_base, env_lookup)
|
||||
}
|
||||
|
||||
fn transform_image_edit_request(
|
||||
&self,
|
||||
model: &str,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue