mirror of
https://github.com/openai/codex.git
synced 2026-09-14 11:57:03 +00:00
V4
This commit is contained in:
@@ -17,6 +17,7 @@ use eventsource_stream::Eventsource;
|
||||
use futures::Stream;
|
||||
use futures::StreamExt;
|
||||
use futures::TryStreamExt;
|
||||
use serde_json::Value;
|
||||
use serde_json::json;
|
||||
use tokio::sync::mpsc;
|
||||
use tokio::time::timeout;
|
||||
@@ -355,12 +356,20 @@ impl ChatCompletionsApiClient {
|
||||
}));
|
||||
}
|
||||
ResponseItem::LocalShellCall {
|
||||
call_id, action, ..
|
||||
id,
|
||||
call_id,
|
||||
action,
|
||||
..
|
||||
} => {
|
||||
let tool_id = call_id
|
||||
.clone()
|
||||
.filter(|value| !value.is_empty())
|
||||
.or_else(|| id.clone())
|
||||
.unwrap_or_default();
|
||||
messages.push(json!({
|
||||
"role": "assistant",
|
||||
"tool_calls": [{
|
||||
"id": call_id.clone().unwrap_or_default(),
|
||||
"id": tool_id,
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": "shell",
|
||||
@@ -382,7 +391,7 @@ impl ChatCompletionsApiClient {
|
||||
"type": "function",
|
||||
"function": {
|
||||
"name": name,
|
||||
"arguments": json!(input).to_string(),
|
||||
"arguments": input,
|
||||
},
|
||||
}],
|
||||
}));
|
||||
@@ -836,14 +845,20 @@ fn create_tools_json_for_chat_completions_api(
|
||||
return None;
|
||||
}
|
||||
|
||||
tool.as_object().map(|map| {
|
||||
let function_value = if let Some(function) = tool.get("function") {
|
||||
function.clone()
|
||||
} else if let Some(map) = tool.as_object() {
|
||||
let mut function = map.clone();
|
||||
function.remove("type");
|
||||
json!({
|
||||
"type": "function",
|
||||
"function": function,
|
||||
})
|
||||
})
|
||||
Value::Object(function)
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(json!({
|
||||
"type": "function",
|
||||
"function": function_value,
|
||||
}))
|
||||
})
|
||||
.collect::<Vec<serde_json::Value>>();
|
||||
Ok(tools_json)
|
||||
|
||||
@@ -941,15 +941,15 @@ impl Session {
|
||||
let mut previous_response_id = None;
|
||||
let mut request_items = full_prompt_items.clone();
|
||||
|
||||
if let Some(chain) = state.responses_api_chain() {
|
||||
if let Some(prev_id) = chain.last_response_id {
|
||||
let prefix = common_prefix_len(&chain.last_prompt_items, &full_prompt_items);
|
||||
if prefix == 0 && !chain.last_prompt_items.is_empty() {
|
||||
state.reset_responses_api_chain();
|
||||
} else {
|
||||
previous_response_id = Some(prev_id);
|
||||
request_items = full_prompt_items[prefix..].to_vec();
|
||||
}
|
||||
if let Some(chain) = state.responses_api_chain()
|
||||
&& let Some(prev_id) = chain.last_response_id
|
||||
{
|
||||
let prefix = common_prefix_len(&chain.last_prompt_items, &full_prompt_items);
|
||||
if prefix == 0 && !chain.last_prompt_items.is_empty() {
|
||||
state.reset_responses_api_chain();
|
||||
} else {
|
||||
previous_response_id = Some(prev_id);
|
||||
request_items = full_prompt_items[prefix..].to_vec();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1949,14 +1949,16 @@ async fn run_turn(
|
||||
.get_model_family()
|
||||
.supports_parallel_tool_calls;
|
||||
let parallel_tool_calls = model_supports_parallel;
|
||||
let mut prompt = Prompt::default();
|
||||
prompt.instructions = instructions.clone();
|
||||
prompt.input = request_items;
|
||||
prompt.tools = tools_json;
|
||||
prompt.parallel_tool_calls = parallel_tool_calls;
|
||||
prompt.output_schema = turn_context.final_output_json_schema.clone();
|
||||
prompt.store_response = store_response;
|
||||
prompt.previous_response_id = previous_response_id.clone();
|
||||
let prompt = Prompt {
|
||||
instructions: instructions.clone(),
|
||||
input: request_items,
|
||||
tools: tools_json,
|
||||
parallel_tool_calls,
|
||||
output_schema: turn_context.final_output_json_schema.clone(),
|
||||
store_response,
|
||||
previous_response_id: previous_response_id.clone(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let payload = StreamPayload { prompt };
|
||||
|
||||
|
||||
@@ -88,20 +88,25 @@ async fn run_compact_task_inner(
|
||||
let mut turn_input = history.get_history_for_prompt();
|
||||
let turn_input_len = turn_input.len();
|
||||
crate::conversation_history::format_prompt_items(&mut turn_input, false);
|
||||
let mut prompt = Prompt::default();
|
||||
prompt.input = turn_input;
|
||||
prompt.tools = Vec::new();
|
||||
prompt.parallel_tool_calls = false;
|
||||
prompt.output_schema = None;
|
||||
prompt.store_response = false;
|
||||
let prompt = Prompt {
|
||||
input: turn_input,
|
||||
tools: Vec::new(),
|
||||
parallel_tool_calls: false,
|
||||
output_schema: None,
|
||||
store_response: false,
|
||||
..Default::default()
|
||||
};
|
||||
let instructions = crate::client_common::compute_full_instructions(
|
||||
turn_context.base_instructions.as_deref(),
|
||||
&turn_context.client.get_model_family(),
|
||||
false,
|
||||
)
|
||||
.into_owned();
|
||||
prompt.instructions = instructions.clone();
|
||||
prompt.previous_response_id = None;
|
||||
let prompt = Prompt {
|
||||
instructions: instructions.clone(),
|
||||
previous_response_id: None,
|
||||
..prompt
|
||||
};
|
||||
let payload = StreamPayload { prompt };
|
||||
let attempt_result = drain_to_completed(&sess, turn_context.as_ref(), payload).await;
|
||||
|
||||
|
||||
@@ -128,12 +128,14 @@ pub(crate) async fn assess_command(
|
||||
}];
|
||||
crate::conversation_history::format_prompt_items(&mut prompt_items, false);
|
||||
|
||||
let mut prompt = Prompt::default();
|
||||
prompt.input = prompt_items;
|
||||
prompt.tools = Vec::new();
|
||||
prompt.parallel_tool_calls = false;
|
||||
prompt.output_schema = Some(sandbox_assessment_schema());
|
||||
prompt.store_response = false;
|
||||
let prompt = Prompt {
|
||||
input: prompt_items,
|
||||
tools: Vec::new(),
|
||||
parallel_tool_calls: false,
|
||||
output_schema: Some(sandbox_assessment_schema()),
|
||||
store_response: false,
|
||||
..Default::default()
|
||||
};
|
||||
let instructions = crate::client_common::compute_full_instructions(
|
||||
Some(system_prompt.as_str()),
|
||||
&config.model_family,
|
||||
@@ -141,7 +143,10 @@ pub(crate) async fn assess_command(
|
||||
)
|
||||
.into_owned();
|
||||
|
||||
prompt.instructions = instructions.clone();
|
||||
let prompt = Prompt {
|
||||
instructions: instructions.clone(),
|
||||
..prompt
|
||||
};
|
||||
let payload = StreamPayload { prompt };
|
||||
|
||||
let child_otel =
|
||||
|
||||
Reference in New Issue
Block a user