objectiveai_sdk/agent/completions/request/
response_format.rs1use std::hash::{Hash, Hasher};
4use indexmap::IndexMap;
5use serde::{Deserialize, Serialize};
6use schemars::JsonSchema;
7
8#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
10#[serde(tag = "type", rename_all = "snake_case")]
11#[schemars(rename = "agent.completions.request.ResponseFormat")]
12pub enum ResponseFormat {
13 #[schemars(title = "Text")]
15 Text,
16 #[schemars(title = "JsonObject")]
18 JsonObject,
19 #[schemars(title = "JsonSchema")]
21 JsonSchema {
22 schema: IndexMap<String, serde_json::Value>,
24 },
25 #[schemars(title = "Grammar")]
27 Grammar { grammar: String },
28 #[schemars(title = "Python")]
30 Python,
31 #[schemars(title = "ToolCall")]
33 ToolCall {
34 name: String,
36 description: String,
38 schema: IndexMap<String, serde_json::Value>,
40 #[serde(skip_serializing_if = "Option::is_none")]
42 #[schemars(extend("omitempty" = true))]
43 required: Option<bool>,
44 },
45}
46
47impl ResponseFormat {
48 pub fn tool_key(&self) -> String {
49 let json = serde_json::to_string(self).unwrap_or_default();
50 let mut h = std::collections::hash_map::DefaultHasher::new();
51 json.hash(&mut h);
52 format!("{:x}", h.finish())
53 }
54}
55
56pub type PerAgentResponseFormat = IndexMap<String, ResponseFormat>;
58
59#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
61#[serde(untagged)]
62#[schemars(rename = "agent.completions.request.ResponseFormatParam")]
63pub enum ResponseFormatParam {
64 #[schemars(title = "Single")]
66 Single(ResponseFormat),
67 #[schemars(title = "PerAgent")]
69 PerAgent(PerAgentResponseFormat),
70}