From 56d423d261cfe5bad323e52fb1156032745fb7be Mon Sep 17 00:00:00 2001 From: John Costa Date: Wed, 19 Mar 2025 09:46:42 +0000 Subject: [PATCH] feat: adding events and locations to json schema --- backend/ai_response.json | 82 +++++++++++++++++++++++++++ backend/openai.go | 116 +++++++++++++++++++++++++++------------ 2 files changed, 164 insertions(+), 34 deletions(-) create mode 100644 backend/ai_response.json diff --git a/backend/ai_response.json b/backend/ai_response.json new file mode 100644 index 0000000..b862fad --- /dev/null +++ b/backend/ai_response.json @@ -0,0 +1,82 @@ +{ + "name": "schema_description", + "schema": { + "type": "object", + "properties": { + "tags": { + "type": "array", + "description": "A list of tags you think the image is relevant to.", + "items": { + "type": "string" + } + }, + "text": { + "type": "array", + "description": "A list of sentences the image contains.", + "items": { + "type": "string" + } + }, + "links": { + "type": "array", + "description": "A list of all the links you can find in the image.", + "items": { + "type": "string" + } + }, + "events": { + "type": "array", + "description": "A list of events you see on the image, mostly there usually only 1 or 0 events", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "location": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "coordinates": { + "type": ["string", "null"] + }, + "address": { + "type": ["string", "null"] + }, + "description": { + "type": ["string", "null"] + } + } + } + } + } + }, + "locations": { + "type": "array", + "description": "A list of locations you see on the image, usually theres only 1 or 0 locations", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "coordinates": { + "type": ["string", "null"] + }, + "address": { + "type": ["string", "null"] + }, + "description": { + "type": ["string", "null"] + } + } + } + } + }, + "required": ["tags", "text", "links", "events", "locations"], + "additionalProperties": false + }, + "strict": true +} diff --git a/backend/openai.go b/backend/openai.go index 170e493..b3481f8 100644 --- a/backend/openai.go +++ b/backend/openai.go @@ -149,40 +149,86 @@ Use generic tags. const RESPONSE_FORMAT = ` { - "name": "schema_description", - "schema": { - "type": "object", - "properties": { - "tags": { - "type": "array", - "description": "A list of tags you think the image is relevant to.", - "items": { - "type": "string" - } - }, - "text": { - "type": "array", - "description": "A list of sentences the image contains.", - "items": { - "type": "string" - } - }, - "links": { - "type": "array", - "description": "A list of all the links you can find in the image.", - "items": { - "type": "string" - } - } - }, - "required": [ - "tags", - "text", - "links" - ], - "additionalProperties": false - }, - "strict": true + "name": "schema_description", + "schema": { + "type": "object", + "properties": { + "tags": { + "type": "array", + "description": "A list of tags you think the image is relevant to.", + "items": { + "type": "string" + } + }, + "text": { + "type": "array", + "description": "A list of sentences the image contains.", + "items": { + "type": "string" + } + }, + "links": { + "type": "array", + "description": "A list of all the links you can find in the image.", + "items": { + "type": "string" + } + }, + "events": { + "type": "array", + "description": "A list of events you see on the image, mostly there usually only 1 or 0 events", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "location": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "coordinates": { + "type": ["string", "null"] + }, + "address": { + "type": ["string", "null"] + }, + "description": { + "type": ["string", "null"] + } + } + } + } + } + }, + "locations": { + "type": "array", + "description": "A list of locations you see on the image, usually theres only 1 or 0 locations", + "items": { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "coordinates": { + "type": ["string", "null"] + }, + "address": { + "type": ["string", "null"] + }, + "description": { + "type": ["string", "null"] + } + } + } + } + }, + "required": ["tags", "text", "links", "events", "locations"], + "additionalProperties": false + }, + "strict": true } ` @@ -319,5 +365,7 @@ func (client OpenAiClient) GetImageInfo(imageName string, imageData []byte) (Ima return ImageInfo{}, err } + log.Println(string(response)) + return parseOpenAiResponse(response) }