mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-23 00:41:40 +00:00
refactor(rust): inject VertexAuth into OcrClient so the bridge keeps one token cache
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
abb9618971
commit
5a474fd799
7 changed files with 22 additions and 4 deletions
2
litellm-rust/Cargo.lock
generated
2
litellm-rust/Cargo.lock
generated
|
|
@ -2056,6 +2056,7 @@ dependencies = [
|
|||
"futures-util",
|
||||
"litellm-auth",
|
||||
"litellm-auth-aws",
|
||||
"litellm-auth-gcp",
|
||||
"litellm-callbacks",
|
||||
"litellm-core-utils",
|
||||
"litellm-http",
|
||||
|
|
@ -2175,6 +2176,7 @@ dependencies = [
|
|||
"criterion",
|
||||
"futures-util",
|
||||
"litellm-auth",
|
||||
"litellm-auth-gcp",
|
||||
"litellm-callbacks-legacy",
|
||||
"litellm-core",
|
||||
"litellm-host-python",
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ futures-util.workspace = true
|
|||
base64.workspace = true
|
||||
litellm-auth.workspace = true
|
||||
litellm-auth-aws.workspace = true
|
||||
litellm-auth-gcp.workspace = true
|
||||
litellm-http.workspace = true
|
||||
litellm-llms.workspace = true
|
||||
moka.workspace = true
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use litellm_auth_gcp::VertexAuth;
|
||||
use litellm_http::{HttpClientConfig, HttpClientPool};
|
||||
use litellm_llms::{
|
||||
base_llm::ocr::{error::Error, transformation::LiteLLMOcrResponse},
|
||||
|
|
@ -19,7 +20,8 @@ pub async fn perform(
|
|||
pub async fn ocr(
|
||||
pool: &HttpClientPool,
|
||||
config: &HttpClientConfig,
|
||||
vertex_auth: VertexAuth,
|
||||
request: LiteLLMOcrRequest,
|
||||
) -> Result<LiteLLMOcrResponse, Error> {
|
||||
perform(&OcrClient::new(pool, config)?, request).await
|
||||
perform(&OcrClient::new(pool, config, vertex_auth)?, request).await
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use litellm_auth_gcp::VertexAuth;
|
||||
use litellm_callbacks::{
|
||||
event::{CallEvent, WireRequest},
|
||||
host::{Host, HostOp, HostResult},
|
||||
|
|
@ -182,6 +183,7 @@ async fn facade_uses_the_injected_http_pool_configuration() {
|
|||
crate::ocr::client::ocr(
|
||||
&HttpClientPool::new(),
|
||||
&config,
|
||||
VertexAuth::default(),
|
||||
wire_request("mistral/model", &base, json!({})),
|
||||
)
|
||||
.await
|
||||
|
|
@ -200,6 +202,7 @@ async fn unbuildable_http_configuration_fails_before_dispatch() {
|
|||
let error = crate::ocr::client::ocr(
|
||||
&HttpClientPool::new(),
|
||||
&config,
|
||||
VertexAuth::default(),
|
||||
wire_request("mistral/model", &base, json!({})),
|
||||
)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -42,12 +42,16 @@ pub struct OcrClient {
|
|||
}
|
||||
|
||||
impl OcrClient {
|
||||
pub fn new(pool: &HttpClientPool, config: &HttpClientConfig) -> Result<Self, transport::Error> {
|
||||
pub fn new(
|
||||
pool: &HttpClientPool,
|
||||
config: &HttpClientConfig,
|
||||
vertex_auth: VertexAuth,
|
||||
) -> Result<Self, transport::Error> {
|
||||
Ok(Self {
|
||||
provider_http: pool.client(config, ClientVariant::Provider)?,
|
||||
polling_http: pool.client(config, ClientVariant::NoRedirect)?,
|
||||
document_fetcher: MediaFetcher::new(pool, config)?,
|
||||
vertex_auth: VertexAuth::default(),
|
||||
vertex_auth,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ bytes.workspace = true
|
|||
litellm-auth.workspace = true
|
||||
litellm-callbacks-legacy.workspace = true
|
||||
litellm-core.workspace = true
|
||||
litellm-auth-gcp.workspace = true
|
||||
litellm-http.workspace = true
|
||||
litellm-llms.workspace = true
|
||||
litellm-types.workspace = true
|
||||
|
|
|
|||
|
|
@ -3,7 +3,10 @@ mod errors;
|
|||
mod host;
|
||||
mod project;
|
||||
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use host::OcrRouteHost;
|
||||
use litellm_auth_gcp::VertexAuth;
|
||||
use litellm_callbacks_legacy::{LegacySurface, PublicCall, run_legacy_call};
|
||||
use litellm_core::ocr::route::ocr_machine;
|
||||
use litellm_llms::custom_httpx::llm_http_handler::OcrClient;
|
||||
|
|
@ -24,6 +27,8 @@ const ASYNC_SURFACE: LegacySurface = LegacySurface {
|
|||
..SURFACE
|
||||
};
|
||||
|
||||
static VERTEX_AUTH: LazyLock<VertexAuth> = LazyLock::new(VertexAuth::default);
|
||||
|
||||
fn run_ocr(
|
||||
py: Python<'_>,
|
||||
request: Bound<'_, PyAny>,
|
||||
|
|
@ -32,7 +37,7 @@ fn run_ocr(
|
|||
asynchronous: bool,
|
||||
) -> PyResult<Py<PyAny>> {
|
||||
let config = http::call_config(py, &kwargs)?;
|
||||
let client = OcrClient::new(http::pool(), &config)
|
||||
let client = OcrClient::new(http::pool(), &config, VERTEX_AUTH.clone())
|
||||
.map_err(|error| RustBridgeDeclined::new_err(error.to_string()))?;
|
||||
run_legacy_call(
|
||||
py,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue