mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
pass on save info to model + ui tweaks (#14123)
Passing on more information to the model for context purposes, to streamline image-identification.
This commit is contained in:
committed by
GitHub
Unverified
parent
44ecc527cb
commit
42f20a6845
@@ -421,9 +421,23 @@ fn for_prompt_rewrites_image_generation_calls_when_images_are_supported() {
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputImage {
|
||||
image_url: "data:image/png;base64,Zm9v".to_string(),
|
||||
}],
|
||||
content: vec![
|
||||
ContentItem::InputText {
|
||||
text: "Image Generation Call".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Image ID: ig_123".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Prompt: lobster".to_string(),
|
||||
},
|
||||
ContentItem::InputImage {
|
||||
image_url: "data:image/png;base64,Zm9v".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Saved to: CWD".to_string(),
|
||||
},
|
||||
],
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
},
|
||||
@@ -475,10 +489,24 @@ fn for_prompt_rewrites_image_generation_calls_when_images_are_unsupported() {
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputText {
|
||||
text: "image content omitted because you do not support image input"
|
||||
.to_string(),
|
||||
}],
|
||||
content: vec![
|
||||
ContentItem::InputText {
|
||||
text: "Image Generation Call".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Image ID: ig_123".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Prompt: lobster".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "image content omitted because you do not support image input"
|
||||
.to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: "Saved to: CWD".to_string(),
|
||||
},
|
||||
],
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
},
|
||||
|
||||
@@ -215,17 +215,37 @@ pub(crate) fn rewrite_image_generation_calls_for_stateless_input(items: &mut Vec
|
||||
*items = original_items
|
||||
.into_iter()
|
||||
.map(|item| match item {
|
||||
ResponseItem::ImageGenerationCall { result, .. } => {
|
||||
ResponseItem::ImageGenerationCall {
|
||||
id,
|
||||
revised_prompt,
|
||||
result,
|
||||
..
|
||||
} => {
|
||||
let image_url = if result.starts_with("data:") {
|
||||
result
|
||||
} else {
|
||||
format!("data:image/png;base64,{result}")
|
||||
};
|
||||
let revised_prompt = revised_prompt.unwrap_or_default();
|
||||
|
||||
ResponseItem::Message {
|
||||
id: None,
|
||||
role: "user".to_string(),
|
||||
content: vec![ContentItem::InputImage { image_url }],
|
||||
content: vec![
|
||||
ContentItem::InputText {
|
||||
text: "Image Generation Call".to_string(),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: format!("Image ID: {id}"),
|
||||
},
|
||||
ContentItem::InputText {
|
||||
text: format!("Prompt: {revised_prompt}"),
|
||||
},
|
||||
ContentItem::InputImage { image_url },
|
||||
ContentItem::InputText {
|
||||
text: "Saved to: CWD".to_string(),
|
||||
},
|
||||
],
|
||||
end_turn: None,
|
||||
phase: None,
|
||||
}
|
||||
|
||||
@@ -2353,10 +2353,15 @@ impl ChatWidget {
|
||||
|
||||
fn on_image_generation_end(&mut self, event: ImageGenerationEndEvent) {
|
||||
self.flush_answer_stream_with_separator();
|
||||
let saved_to = event.saved_path.as_deref().and_then(|saved_path| {
|
||||
std::path::Path::new(saved_path)
|
||||
.parent()
|
||||
.map(|parent| parent.display().to_string())
|
||||
});
|
||||
self.add_to_history(history_cell::new_image_generation_call(
|
||||
event.call_id,
|
||||
event.status,
|
||||
event.revised_prompt,
|
||||
saved_to,
|
||||
));
|
||||
self.request_redraw();
|
||||
}
|
||||
|
||||
+3
-2
@@ -3,5 +3,6 @@ source: tui/src/chatwidget/tests.rs
|
||||
assertion_line: 5889
|
||||
expression: combined
|
||||
---
|
||||
• Generated Image
|
||||
└ completed: A tiny blue square
|
||||
• Generated Image:
|
||||
└ A tiny blue square
|
||||
└ Saved to: /tmp/project
|
||||
|
||||
@@ -6288,7 +6288,7 @@ async fn image_generation_call_adds_history_cell() {
|
||||
status: "completed".into(),
|
||||
revised_prompt: Some("A tiny blue square".into()),
|
||||
result: "Zm9v".into(),
|
||||
saved_path: None,
|
||||
saved_path: Some("/tmp/project/ig-1.png".into()),
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
@@ -2215,15 +2215,18 @@ pub(crate) fn new_view_image_tool_call(path: PathBuf, cwd: &Path) -> PlainHistor
|
||||
|
||||
pub(crate) fn new_image_generation_call(
|
||||
call_id: String,
|
||||
status: String,
|
||||
revised_prompt: Option<String>,
|
||||
saved_to: Option<String>,
|
||||
) -> PlainHistoryCell {
|
||||
let detail = revised_prompt.unwrap_or_else(|| call_id.clone());
|
||||
|
||||
let lines: Vec<Line<'static>> = vec![
|
||||
vec!["• ".dim(), "Generated Image".bold()].into(),
|
||||
vec![" └ ".dim(), format!("{status}: {detail}").dim()].into(),
|
||||
let mut lines: Vec<Line<'static>> = vec![
|
||||
vec!["• ".dim(), "Generated Image:".bold()].into(),
|
||||
vec![" └ ".dim(), detail.dim()].into(),
|
||||
];
|
||||
if let Some(saved_to) = saved_to {
|
||||
lines.push(vec![" └ ".dim(), format!("Saved to: {saved_to}").dim()].into());
|
||||
}
|
||||
|
||||
PlainHistoryCell { lines }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user