Skip to content

Commit fb61255

Browse files
committed
Add Support for image generation tool
1 parent b011b77 commit fb61255

6 files changed

Lines changed: 73 additions & 4 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Sample guideline, please follow similar structure for guideline with code samples
2+
# 1. Suggest using streams instead of simple loops for better readability.
3+
# <example>
4+
# *Comment:
5+
# Category: Minor
6+
# Issue: Use streams instead of a loop for better readability.
7+
# Code Block:
8+
#
9+
# ```java
10+
# // Calculate squares of numbers
11+
# List<Integer> squares = new ArrayList<>();
12+
# for (int number : numbers) {
13+
# squares.add(number * number);
14+
# }
15+
# ```
16+
# Recommendation:
17+
#
18+
# ```java
19+
# // Calculate squares of numbers
20+
# List<Integer> squares = Arrays.stream(numbers)
21+
# .map(n -> n * n) // Map each number to its square
22+
# .toList();
23+
# ```
24+
# </example>

crates/protocols/src/responses.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ pub enum ResponseTool {
3636
#[serde(rename = "code_interpreter")]
3737
CodeInterpreter(CodeInterpreterTool),
3838

39+
/// Built-in tool.
40+
#[serde(rename = "image_generation")]
41+
ImageGeneration(ImageGenerationTool),
42+
3943
/// MCP server tool.
4044
#[serde(rename = "mcp")]
4145
Mcp(McpTool),
@@ -80,6 +84,17 @@ pub struct CodeInterpreterTool {
8084
pub container: Option<Value>,
8185
}
8286

87+
/// Built-in image generation tool.
88+
///
89+
/// The upstream API may add optional fields over time. We keep this tool shape
90+
/// open by preserving unknown key/value pairs.
91+
#[serde_with::skip_serializing_none]
92+
#[derive(Debug, Clone, Deserialize, Serialize, Default, schemars::JsonSchema)]
93+
pub struct ImageGenerationTool {
94+
#[serde(flatten)]
95+
pub options: HashMap<String, Value>,
96+
}
97+
8398
/// `require_approval` values.
8499
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Eq, schemars::JsonSchema)]
85100
#[serde(rename_all = "snake_case")]
@@ -314,6 +329,13 @@ pub enum ResponseOutputItem {
314329
queries: Vec<String>,
315330
results: Option<Vec<FileSearchResult>>,
316331
},
332+
#[serde(rename = "image_generation_call")]
333+
ImageGenerationCall {
334+
id: String,
335+
status: ImageGenerationCallStatus,
336+
#[serde(skip_serializing_if = "Option::is_none")]
337+
result: Option<String>,
338+
},
317339
}
318340

319341
// ============================================================================
@@ -389,6 +411,17 @@ pub enum FileSearchCallStatus {
389411
Failed,
390412
}
391413

414+
/// Status for image generation tool calls.
415+
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, schemars::JsonSchema)]
416+
#[serde(rename_all = "snake_case")]
417+
pub enum ImageGenerationCallStatus {
418+
InProgress,
419+
Generating,
420+
Completed,
421+
Incomplete,
422+
Failed,
423+
}
424+
392425
/// A result from file search.
393426
#[serde_with::skip_serializing_none]
394427
#[derive(Debug, Clone, Deserialize, Serialize, schemars::JsonSchema)]

model_gateway/src/routers/grpc/common/responses/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ pub(crate) async fn ensure_mcp_connection(
4444
t.iter().any(|tool| {
4545
matches!(
4646
tool,
47-
ResponseTool::WebSearchPreview(_) | ResponseTool::CodeInterpreter(_)
47+
ResponseTool::WebSearchPreview(_)
48+
| ResponseTool::CodeInterpreter(_)
49+
| ResponseTool::ImageGeneration(_)
4850
)
4951
})
5052
})

model_gateway/src/routers/grpc/harmony/builder.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ pub(crate) fn convert_harmony_logprobs(proto_logprobs: &ProtoOutputLogProbs) ->
6060
}
6161

6262
/// Built-in tools that are added to the system message
63-
const BUILTIN_TOOLS: &[&str] = &["web_search_preview", "code_interpreter", "container"];
63+
const BUILTIN_TOOLS: &[&str] = &[
64+
"web_search_preview",
65+
"code_interpreter",
66+
"image_generation",
67+
"container",
68+
];
6469

6570
/// Trait for tool-like objects that can be converted to Harmony ToolDescription
6671
trait ToolLike {
@@ -80,7 +85,7 @@ impl ToolLike for Tool {
8085
fn is_builtin(&self) -> bool {
8186
matches!(
8287
self.tool_type.as_str(),
83-
"web_search_preview" | "code_interpreter" | "container"
88+
"web_search_preview" | "code_interpreter" | "image_generation" | "container"
8489
)
8590
}
8691

@@ -102,7 +107,9 @@ impl ToolLike for ResponseTool {
102107
fn is_builtin(&self) -> bool {
103108
matches!(
104109
self,
105-
ResponseTool::WebSearchPreview(_) | ResponseTool::CodeInterpreter(_)
110+
ResponseTool::WebSearchPreview(_)
111+
| ResponseTool::CodeInterpreter(_)
112+
| ResponseTool::ImageGeneration(_)
106113
)
107114
}
108115

@@ -425,6 +432,7 @@ impl HarmonyBuilder {
425432
ResponseTool::Function(_) => "function",
426433
ResponseTool::WebSearchPreview(_) => "web_search_preview",
427434
ResponseTool::CodeInterpreter(_) => "code_interpreter",
435+
ResponseTool::ImageGeneration(_) => "image_generation",
428436
ResponseTool::Mcp(_) => "mcp",
429437
})
430438
.collect()

model_gateway/src/routers/openai/responses/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ pub(super) fn response_tool_to_value(tool: &ResponseTool) -> Option<Value> {
230230
}
231231
ResponseTool::WebSearchPreview(_) => serde_json::to_value(tool).ok(),
232232
ResponseTool::CodeInterpreter(_) => serde_json::to_value(tool).ok(),
233+
ResponseTool::ImageGeneration(_) => serde_json::to_value(tool).ok(),
233234
ResponseTool::Function(_) => None,
234235
}
235236
}

oracle-schema-config.local.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
auto_migrate: true

0 commit comments

Comments
 (0)