mirror of
https://github.com/openai/codex.git
synced 2026-04-24 14:45:27 +00:00
R2
This commit is contained in:
@@ -71,11 +71,6 @@ impl fmt::Debug for ModelClient {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct StreamPayload {
|
||||
pub prompt: Prompt,
|
||||
}
|
||||
|
||||
type ApiClientStream = BoxStream<'static, ApiClientResult<ResponseEvent>>;
|
||||
|
||||
enum ModelBackend {
|
||||
@@ -178,8 +173,8 @@ impl ModelClient {
|
||||
&& self.config.features.enabled(Feature::ResponsesApiChaining)
|
||||
}
|
||||
|
||||
pub async fn stream(&self, payload: &StreamPayload) -> Result<ResponseStream> {
|
||||
let mut prompt = payload.prompt.clone();
|
||||
pub async fn stream(&self, prompt: &Prompt) -> Result<ResponseStream> {
|
||||
let mut prompt = prompt.clone();
|
||||
self.populate_prompt(&mut prompt);
|
||||
if self.provider.wire_api == WireApi::Responses
|
||||
&& let Some(path) = &*CODEX_RS_SSE_FIXTURE
|
||||
@@ -287,8 +282,7 @@ impl ModelClient {
|
||||
prompt.instructions = instructions;
|
||||
prompt.store_response = false;
|
||||
prompt.previous_response_id = None;
|
||||
let payload = StreamPayload { prompt };
|
||||
self.stream(&payload).await
|
||||
self.stream(&prompt).await
|
||||
}
|
||||
|
||||
pub fn get_provider(&self) -> ModelProviderInfo {
|
||||
|
||||
@@ -52,7 +52,6 @@ use tracing::info;
|
||||
use tracing::warn;
|
||||
|
||||
use crate::client::ModelClient;
|
||||
use crate::client::StreamPayload;
|
||||
use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::config::Config;
|
||||
@@ -1937,17 +1936,15 @@ async fn run_turn(
|
||||
prompt.parallel_tool_calls = parallel_tool_calls;
|
||||
prompt.output_schema = turn_context.final_output_json_schema.clone();
|
||||
|
||||
let payload = StreamPayload { prompt };
|
||||
|
||||
let mut retries = 0;
|
||||
loop {
|
||||
let attempt_payload = payload.clone();
|
||||
let attempt_prompt = prompt.clone();
|
||||
match try_run_turn(
|
||||
Arc::clone(&router),
|
||||
Arc::clone(&sess),
|
||||
Arc::clone(&turn_context),
|
||||
Arc::clone(&turn_diff_tracker),
|
||||
attempt_payload,
|
||||
attempt_prompt,
|
||||
cancellation_token.child_token(),
|
||||
)
|
||||
.await
|
||||
@@ -2028,10 +2025,10 @@ async fn try_run_turn(
|
||||
sess: Arc<Session>,
|
||||
turn_context: Arc<TurnContext>,
|
||||
turn_diff_tracker: SharedTurnDiffTracker,
|
||||
payload: StreamPayload,
|
||||
prompt: Prompt,
|
||||
cancellation_token: CancellationToken,
|
||||
) -> CodexResult<TurnRunResult> {
|
||||
let supports_responses_api_chaining = payload.prompt.store_response;
|
||||
let supports_responses_api_chaining = prompt.store_response;
|
||||
|
||||
let rollout_item = RolloutItem::TurnContext(TurnContextItem {
|
||||
cwd: turn_context.cwd.clone(),
|
||||
@@ -2046,7 +2043,7 @@ async fn try_run_turn(
|
||||
let mut stream = turn_context
|
||||
.client
|
||||
.clone()
|
||||
.stream(&payload)
|
||||
.stream(&prompt)
|
||||
.or_cancel(&cancellation_token)
|
||||
.await??;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::sync::Arc;
|
||||
use super::Session;
|
||||
use super::TurnContext;
|
||||
use super::get_last_assistant_message_from_turn;
|
||||
use crate::client::StreamPayload;
|
||||
use crate::client_common::Prompt;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::error::CodexErr;
|
||||
use crate::error::Result as CodexResult;
|
||||
@@ -86,8 +86,7 @@ async fn run_compact_task_inner(
|
||||
let turn_input = history.get_history_for_prompt();
|
||||
let turn_input_len = turn_input.len();
|
||||
let (prompt, _) = crate::state::build_prompt_from_items(turn_input, None);
|
||||
let payload = StreamPayload { prompt };
|
||||
let attempt_result = drain_to_completed(&sess, turn_context.as_ref(), payload).await;
|
||||
let attempt_result = drain_to_completed(&sess, turn_context.as_ref(), prompt).await;
|
||||
|
||||
match attempt_result {
|
||||
Ok(()) => {
|
||||
@@ -250,9 +249,9 @@ fn build_compacted_history_with_limit(
|
||||
async fn drain_to_completed(
|
||||
sess: &Session,
|
||||
turn_context: &TurnContext,
|
||||
payload: StreamPayload,
|
||||
prompt: Prompt,
|
||||
) -> CodexResult<()> {
|
||||
let mut stream = turn_context.client.clone().stream(&payload).await?;
|
||||
let mut stream = turn_context.client.clone().stream(&prompt).await?;
|
||||
loop {
|
||||
let maybe_event = stream.next().await;
|
||||
let Some(event) = maybe_event else {
|
||||
|
||||
@@ -6,12 +6,12 @@ use std::time::Instant;
|
||||
|
||||
use crate::AuthManager;
|
||||
use crate::client::ModelClient;
|
||||
use crate::client::StreamPayload;
|
||||
use crate::client_common::ResponseEvent;
|
||||
use crate::config::Config;
|
||||
use crate::protocol::SandboxPolicy;
|
||||
use askama::Template;
|
||||
use codex_api_client::{ModelProviderInfo, Prompt};
|
||||
use codex_api_client::ModelProviderInfo;
|
||||
use codex_api_client::Prompt;
|
||||
use codex_otel::otel_event_manager::OtelEventManager;
|
||||
use codex_protocol::ConversationId;
|
||||
use codex_protocol::models::ContentItem;
|
||||
@@ -130,8 +130,6 @@ pub(crate) async fn assess_command(
|
||||
instructions: system_prompt,
|
||||
..Default::default()
|
||||
};
|
||||
let payload = StreamPayload { prompt };
|
||||
|
||||
let child_otel =
|
||||
parent_otel.with_model(config.model.as_str(), config.model_family.slug.as_str());
|
||||
|
||||
@@ -148,7 +146,7 @@ pub(crate) async fn assess_command(
|
||||
|
||||
let start = Instant::now();
|
||||
let assessment_result = timeout(SANDBOX_ASSESSMENT_TIMEOUT, async move {
|
||||
let mut stream = client.stream(&payload).await?;
|
||||
let mut stream = client.stream(&prompt).await?;
|
||||
let mut last_json: Option<String> = None;
|
||||
while let Some(event) = stream.next().await {
|
||||
match event {
|
||||
|
||||
Reference in New Issue
Block a user