diff --git a/Cargo.lock b/Cargo.lock index d733eb8..1a2b982 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1191,7 +1191,6 @@ dependencies = [ "tokio", "tokio-util", "tower 0.4.13", - "tower-http", "tracing", "tracing-subscriber", "urlencoding", diff --git a/furumi-agent/src/ingest/normalize.rs b/furumi-agent/src/ingest/normalize.rs index 1de02a1..541fb6f 100644 --- a/furumi-agent/src/ingest/normalize.rs +++ b/furumi-agent/src/ingest/normalize.rs @@ -131,6 +131,14 @@ struct ChatMessage { struct ChatResponseFormat { #[serde(rename = "type")] kind: String, + json_schema: JsonSchemaWrapper, +} + +#[derive(Serialize)] +struct JsonSchemaWrapper { + name: String, + strict: bool, + schema: serde_json::Value, } #[derive(Deserialize)] @@ -171,7 +179,30 @@ pub async fn call_ollama( content: user_message.to_owned(), }, ], - response_format: ChatResponseFormat { kind: "json_object".to_owned() }, + response_format: ChatResponseFormat { + kind: "json_schema".to_owned(), + json_schema: JsonSchemaWrapper { + name: "normalized_metadata".to_owned(), + strict: true, + schema: serde_json::json!({ + "type": "object", + "properties": { + "artist": { "type": ["string", "null"] }, + "album": { "type": ["string", "null"] }, + "title": { "type": ["string", "null"] }, + "year": { "type": ["integer", "null"] }, + "track_number": { "type": ["integer", "null"] }, + "genre": { "type": ["string", "null"] }, + "featured_artists": { "type": "array", "items": { "type": "string" } }, + "release_type": { "type": ["string", "null"] }, + "confidence": { "type": ["number", "null"] }, + "notes": { "type": ["string", "null"] } + }, + "required": ["artist", "album", "title", "year", "track_number", "genre", "featured_artists", "release_type", "confidence", "notes"], + "additionalProperties": false + }), + }, + }, stream: false, temperature: 0.1, };