Change cloud language model provider JSON protocol to surface errors and usage information (#29830)
Release Notes: - N/A --------- Co-authored-by: Nathan Sobo <nathan@zed.dev> Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
parent
3984531a45
commit
c3d9cdecab
8 changed files with 128 additions and 197 deletions
|
@ -8,8 +8,6 @@ use std::{
|
|||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
use crate::RequestUsage;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct RateLimiter {
|
||||
semaphore: Arc<Semaphore>,
|
||||
|
@ -69,32 +67,4 @@ impl RateLimiter {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stream_with_usage<'a, Fut, T>(
|
||||
&self,
|
||||
future: Fut,
|
||||
) -> impl 'a
|
||||
+ Future<
|
||||
Output = Result<(
|
||||
impl Stream<Item = T::Item> + use<Fut, T>,
|
||||
Option<RequestUsage>,
|
||||
)>,
|
||||
>
|
||||
where
|
||||
Fut: 'a + Future<Output = Result<(T, Option<RequestUsage>)>>,
|
||||
T: Stream,
|
||||
{
|
||||
let guard = self.semaphore.acquire_arc();
|
||||
async move {
|
||||
let guard = guard.await;
|
||||
let (inner, usage) = future.await?;
|
||||
Ok((
|
||||
RateLimitGuard {
|
||||
inner,
|
||||
_guard: guard,
|
||||
},
|
||||
usage,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue