This commit is contained in:
jif-oai
2025-10-31 13:28:33 +01:00
parent 69341a04f4
commit cfe7fb825c
6 changed files with 67 additions and 39 deletions
+3 -5
View File
@@ -140,7 +140,7 @@ impl ApiClient for ChatCompletionsApiClient {
.get(reqwest::header::RETRY_AFTER)
.and_then(|v| v.to_str().ok())
.and_then(|s| s.parse::<u64>().ok())
.map(|s| Duration::from_secs(s));
.map(Duration::from_secs);
tokio::time::sleep(retry_after.unwrap_or_else(|| backoff(attempt))).await;
}
Err(error) => {
@@ -624,7 +624,7 @@ async fn process_chat_sse<S>(
.and_then(|v| v.as_array())
{
for call in tool_calls {
if let Some(index) = call.get("index").and_then(|i| i.as_u64())
if let Some(index) = call.get("index").and_then(serde_json::Value::as_u64)
&& index == 0
&& let Some(function) = call.get("function")
{
@@ -641,8 +641,7 @@ async fn process_chat_sse<S>(
if let Some(finish) = choice.get("finish_reason").and_then(|f| f.as_str())
&& finish == "tool_calls"
{
if let Some(name) = function_call_state.name.take() {
&& let Some(name) = function_call_state.name.take() {
let call_id =
function_call_state.call_id.take().unwrap_or_default();
let arguments = std::mem::take(&mut function_call_state.arguments);
@@ -655,7 +654,6 @@ async fn process_chat_sse<S>(
let _ =
tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
}
}
}
}
}
+2 -3
View File
@@ -120,11 +120,10 @@ impl ModelProviderInfo {
let url = self.get_full_url(effective_auth.as_ref());
let mut builder = client.post(url);
if let Some(context) = effective_auth.as_ref() {
if let Some(token) = context.bearer_token.as_ref() {
if let Some(context) = effective_auth.as_ref()
&& let Some(token) = context.bearer_token.as_ref() {
builder = builder.bearer_auth(token);
}
}
Ok(self.apply_http_headers(builder))
}
+7 -9
View File
@@ -74,13 +74,12 @@ impl ApiClient for ResponsesApiClient {
let mut payload_json = self.build_payload(&prompt)?;
if self.config.provider.is_azure_responses_endpoint() {
if let Some(input_value) = payload_json.get_mut("input")
if self.config.provider.is_azure_responses_endpoint()
&& let Some(input_value) = payload_json.get_mut("input")
&& let Some(array) = input_value.as_array_mut()
{
attach_item_ids_array(array, &prompt.input);
}
}
let max_attempts = self.config.provider.request_max_retries();
for attempt in 0..=max_attempts {
@@ -218,7 +217,7 @@ impl ResponsesApiClient {
.headers()
.get("cf-ray")
.and_then(|v| v.to_str().ok())
.map(|s| s.to_string());
.map(std::string::ToString::to_string);
}
match res {
@@ -260,8 +259,8 @@ impl ResponsesApiClient {
.and_then(|s| s.parse::<u64>().ok());
let retry_after = retry_after_secs.map(|s| Duration::from_millis(s * 1_000));
if status == StatusCode::UNAUTHORIZED {
if let Some(provider) = self.config.auth_provider.as_ref()
if status == StatusCode::UNAUTHORIZED
&& let Some(provider) = self.config.auth_provider.as_ref()
&& let Some(ctx) = auth.as_ref()
&& ctx.mode == AuthMode::ChatGPT
{
@@ -270,7 +269,6 @@ impl ResponsesApiClient {
.await
.map_err(|err| StreamAttemptError::Fatal(Error::Auth(err)))?;
}
}
if !(status == StatusCode::TOO_MANY_REQUESTS
|| status == StatusCode::UNAUTHORIZED
@@ -718,13 +716,13 @@ pub async fn stream_from_fixture(
let (tx_event, rx_event) = mpsc::channel::<Result<ResponseEvent>>(1600);
let display_path = path.as_ref().display().to_string();
let file = std::fs::File::open(path.as_ref())
.map_err(|e| Error::Other(format!("failed to open fixture {}: {}", display_path, e)))?;
.map_err(|e| Error::Other(format!("failed to open fixture {display_path}: {e}")))?;
let lines = std::io::BufReader::new(file).lines();
let mut content = String::new();
for line in lines {
let line = line
.map_err(|e| Error::Other(format!("failed to read fixture {}: {}", display_path, e)))?;
.map_err(|e| Error::Other(format!("failed to read fixture {display_path}: {e}")))?;
content.push_str(&line);
content.push_str("\n\n");
}