import (
"context"
"encoding/json"
"fmt"
"github.com/curaious/uno/pkg/llm/responses"
"github.com/curaious/uno/internal/utils"
)
func main() {
// ... client and model initialization ...
// Define schema for extracting contact information
contactSchema := map[string]any{
"type": "object",
"properties": map[string]any{
"contacts": map[string]any{
"type": "array",
"items": map[string]any{
"type": "object",
"properties": map[string]any{
"name": map[string]any{
"type": "string",
},
"phone": map[string]any{
"type": "string",
},
"email": map[string]any{
"type": "string",
},
},
"required": []string{"name"},
},
},
},
"required": []string{"contacts"},
}
resp, err := model.NewResponses(context.Background(), &responses.Request{
Instructions: utils.Ptr("You are a data extraction assistant. Extract contact information from the given text."),
Input: responses.InputUnion{
OfString: utils.Ptr("Contact John at 555-1234 or john@example.com, and Sarah at 555-5678."),
},
Parameters: responses.Parameters{
Text: &responses.TextFormat{
Format: map[string]any{
"type": "json_schema",
"name": "structured_output",
"strict": false,
"schema": contactSchema,
},
},
},
})
if err != nil {
panic(err)
}
// Parse the structured output
for _, output := range resp.Output {
if output.OfOutputMessage != nil {
for _, content := range output.OfOutputMessage.Content {
if content.OfOutputText != nil {
var result map[string]any
if err := json.Unmarshal([]byte(content.OfOutputText.Text), &result); err == nil {
fmt.Printf("Extracted data: %+v\n", result)
}
}
}
}
}
}