mirror of
https://github.com/openai/codex.git
synced 2026-11-15 21:50:46 +00:00
Some clippy
This commit is contained in:
@@ -304,11 +304,10 @@ impl ChatCompletionsApiClient {
|
||||
"content": content_value,
|
||||
});
|
||||
|
||||
if let Some(reasoning) = reasoning_by_anchor_index.get(&idx) {
|
||||
message
|
||||
.as_object_mut()
|
||||
.expect("message")
|
||||
.insert("reasoning".to_string(), json!({"text": reasoning}));
|
||||
if let Some(reasoning) = reasoning_by_anchor_index.get(&idx)
|
||||
&& let Some(obj) = message.as_object_mut()
|
||||
{
|
||||
obj.insert("reasoning".to_string(), json!({"text": reasoning}));
|
||||
}
|
||||
|
||||
messages.push(message);
|
||||
@@ -641,19 +640,18 @@ async fn process_chat_sse<S>(
|
||||
|
||||
if let Some(finish) = choice.get("finish_reason").and_then(|f| f.as_str())
|
||||
&& finish == "tool_calls"
|
||||
&& 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);
|
||||
let item = ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
name,
|
||||
arguments,
|
||||
call_id,
|
||||
};
|
||||
let _ =
|
||||
tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
|
||||
}
|
||||
&& 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);
|
||||
let item = ResponseItem::FunctionCall {
|
||||
id: None,
|
||||
name,
|
||||
arguments,
|
||||
call_id,
|
||||
};
|
||||
let _ = tx_event.send(Ok(ResponseEvent::OutputItemDone(item))).await;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,9 +121,10 @@ impl ModelProviderInfo {
|
||||
let mut builder = client.post(url);
|
||||
|
||||
if let Some(context) = effective_auth.as_ref()
|
||||
&& let Some(token) = context.bearer_token.as_ref() {
|
||||
builder = builder.bearer_auth(token);
|
||||
}
|
||||
&& let Some(token) = context.bearer_token.as_ref()
|
||||
{
|
||||
builder = builder.bearer_auth(token);
|
||||
}
|
||||
|
||||
Ok(self.apply_http_headers(builder))
|
||||
}
|
||||
|
||||
@@ -76,10 +76,10 @@ impl ApiClient for ResponsesApiClient {
|
||||
|
||||
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 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 {
|
||||
@@ -122,22 +122,22 @@ impl ResponsesApiClient {
|
||||
.unwrap_or_else(|| self.config.conversation_id.to_string()),
|
||||
});
|
||||
|
||||
if let Some(reasoning) = prompt.reasoning.as_ref() {
|
||||
payload
|
||||
.as_object_mut()
|
||||
.expect("payload object")
|
||||
.insert("reasoning".to_string(), serde_json::to_value(reasoning)?);
|
||||
if let Some(reasoning) = prompt.reasoning.as_ref()
|
||||
&& let Some(obj) = payload.as_object_mut()
|
||||
{
|
||||
obj.insert("reasoning".to_string(), serde_json::to_value(reasoning)?);
|
||||
}
|
||||
|
||||
if let Some(text) = prompt.text_controls.as_ref() {
|
||||
payload
|
||||
.as_object_mut()
|
||||
.expect("payload object")
|
||||
.insert("text".to_string(), serde_json::to_value(text)?);
|
||||
if let Some(text) = prompt.text_controls.as_ref()
|
||||
&& let Some(obj) = payload.as_object_mut()
|
||||
{
|
||||
obj.insert("text".to_string(), serde_json::to_value(text)?);
|
||||
}
|
||||
|
||||
if let Some(prev) = prompt.previous_response_id.as_ref() {
|
||||
payload.as_object_mut().expect("payload object").insert(
|
||||
if let Some(prev) = prompt.previous_response_id.as_ref()
|
||||
&& let Some(obj) = payload.as_object_mut()
|
||||
{
|
||||
obj.insert(
|
||||
"previous_response_id".to_string(),
|
||||
Value::String(prev.clone()),
|
||||
);
|
||||
@@ -148,10 +148,12 @@ impl ResponsesApiClient {
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
payload.as_object_mut().expect("payload object").insert(
|
||||
"include".to_string(),
|
||||
Value::Array(include.into_iter().map(Value::String).collect()),
|
||||
);
|
||||
if let Some(obj) = payload.as_object_mut() {
|
||||
obj.insert(
|
||||
"include".to_string(),
|
||||
Value::Array(include.into_iter().map(Value::String).collect()),
|
||||
);
|
||||
}
|
||||
|
||||
Ok(payload)
|
||||
}
|
||||
@@ -261,14 +263,14 @@ impl ResponsesApiClient {
|
||||
|
||||
if status == StatusCode::UNAUTHORIZED
|
||||
&& let Some(provider) = self.config.auth_provider.as_ref()
|
||||
&& let Some(ctx) = auth.as_ref()
|
||||
&& ctx.mode == AuthMode::ChatGPT
|
||||
{
|
||||
provider
|
||||
.refresh_token()
|
||||
.await
|
||||
.map_err(|err| StreamAttemptError::Fatal(Error::Auth(err)))?;
|
||||
}
|
||||
&& let Some(ctx) = auth.as_ref()
|
||||
&& ctx.mode == AuthMode::ChatGPT
|
||||
{
|
||||
provider
|
||||
.refresh_token()
|
||||
.await
|
||||
.map_err(|err| StreamAttemptError::Fatal(Error::Auth(err)))?;
|
||||
}
|
||||
|
||||
if !(status == StatusCode::TOO_MANY_REQUESTS
|
||||
|| status == StatusCode::UNAUTHORIZED
|
||||
@@ -671,10 +673,11 @@ fn backoff(attempt: u64) -> Duration {
|
||||
Duration::from_millis(base * 100)
|
||||
}
|
||||
|
||||
fn rate_limit_regex() -> &'static Regex {
|
||||
static RE: OnceLock<Regex> = OnceLock::new();
|
||||
fn rate_limit_regex() -> Option<&'static Regex> {
|
||||
static RE: OnceLock<Option<Regex>> = OnceLock::new();
|
||||
|
||||
RE.get_or_init(|| Regex::new(r"Please try again in (\d+(?:\.\d+)?)(s|ms)").unwrap())
|
||||
RE.get_or_init(|| Regex::new(r"Please try again in (\d+(?:\.\d+)?)(s|ms)").ok())
|
||||
.as_ref()
|
||||
}
|
||||
|
||||
fn try_parse_retry_after(err: &ErrorResponse) -> Option<Duration> {
|
||||
@@ -682,8 +685,8 @@ fn try_parse_retry_after(err: &ErrorResponse) -> Option<Duration> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let re = rate_limit_regex();
|
||||
if let Some(message) = &err.message
|
||||
if let Some(re) = rate_limit_regex()
|
||||
&& let Some(message) = &err.message
|
||||
&& let Some(captures) = re.captures(message)
|
||||
{
|
||||
let seconds = captures.get(1);
|
||||
@@ -721,8 +724,8 @@ pub async fn stream_from_fixture(
|
||||
|
||||
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}")))?;
|
||||
let line =
|
||||
line.map_err(|e| Error::Other(format!("failed to read fixture {display_path}: {e}")))?;
|
||||
content.push_str(&line);
|
||||
content.push_str("\n\n");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user