(req: &StructuredRequest, mode: StructuredMode)
| 924 | } |
| 925 | |
| 926 | fn build_initial_messages(req: &StructuredRequest, mode: StructuredMode) -> Vec<Message> { |
| 927 | match mode { |
| 928 | StructuredMode::Tool => { |
| 929 | // For tool mode, the prompt is the user message; the LLM will respond |
| 930 | // with a tool call whose input is the structured object. |
| 931 | vec![Message::user(&req.prompt)] |
| 932 | } |
| 933 | StructuredMode::Prompt | StructuredMode::Json => { |
| 934 | // Prompt mode and json_object mode both need the schema in the prompt: |
| 935 | // json_object only guarantees *syntactic* validity, so the model still |
| 936 | // has to be told the shape it should produce. |
| 937 | let augmented = format!( |
| 938 | "{}\n\nYou MUST respond with ONLY a valid JSON object (no markdown, no explanation) that conforms to this JSON Schema:\n\n```json\n{}\n```", |
| 939 | req.prompt, |
| 940 | serde_json::to_string_pretty(&req.schema).unwrap_or_default() |
| 941 | ); |
| 942 | vec![Message::user(&augmented)] |
| 943 | } |
| 944 | _ => { |
| 945 | // Strict mode: the schema constraint is enforced by the provider via |
| 946 | // response_format.json_schema, so the user message is just the prompt. |
| 947 | vec![Message::user(&req.prompt)] |
| 948 | } |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | fn build_system_prompt(req: &StructuredRequest, mode: StructuredMode) -> String { |
| 953 | let base = req.system.as_deref().unwrap_or(""); |
no outgoing calls
no test coverage detected