I'm sending the following API request to ChatGPT for which I need the structured result:
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are an art expert."
},
{
"role": "user",
"content": "List similar artists to Pablo Picasso."
}
],
"functions": [
{
"name": "get_similar_artists",
"description": "Similar artists",
"parameters": {
"type": "object",
"properties": {
"similarArtists": {
"type": "array",
"description": "Similar artists",
"items": {
"type": "string",
"desctiption": "Artist name"
}
}
}
}
}
]
}
The result always list just one artist, the Pablo Picasso itself.
{
"id": "chatcmpl-8FzRKhdvnNmeQlKqO706oahxZd2Rl",
"object": "chat.completion",
"created": 1698821786,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": null,
"function_call": {
"name": "get_similar_artists",
"arguments": "{\n \"similarArtists\": [\"Pablo Picasso\"]\n}"
}
},
"finish_reason": "function_call"
}
],
"usage": {
"prompt_tokens": 64,
"completion_tokens": 22,
"total_tokens": 86
}
}
But if I remove the functions
section from the original request, the response correctly lists 10 different artists like this:
{
"id": "chatcmpl-8FzXpEyhGGoO0CIRbHQlQdHsv9Pvx",
"object": "chat.completion",
"created": 1698822189,
"model": "gpt-3.5-turbo-0613",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "1. Georges Braque - Braque was a close friend and collaborator of Picasso, often considered the co-founder of Cubism along with him.\n\n2. Juan Gris - Gris was another prominent figure of Cubism and was greatly influenced by Picasso's work. His paintings often showcased geometric shapes and fragmented forms.\n\n3. Fernand Léger - Léger, like Picasso, experimented with various styles throughout his career. His works often displayed bold colors, simplified forms, and elements of Cubism.\n\n4. Salvador Dali - While Dali's style differs from Picasso's, both artists were significant figures in the Surrealist movement. Dali's dreamlike and fantastical imagery set him apart, but he, like Picasso, had a profound impact on modern art.\n\n5. Joan Miró - Miró's unique and imaginative style shared certain themes with Picasso's work. Both artists often used symbolism and abstraction to convey their ideas, with Miró focusing more on a sense of playfulness and childlike wonder.\n\n6. Marc Chagall - Chagall's vibrant and dreamlike paintings often expressed a sense of nostalgia and folklore. Although his style differs from Picasso's, their shared interest in expressing emotion through color and form makes them comparable.\n\n7. Henri Matisse - Matisse, known for his bold use of color and expressive brushwork, was a contemporary of Picasso and a leading figure of Fauvism. While their styles differ, both artists were known for pushing the boundaries of traditional art.\n\n8. Wassily Kandinsky - Kandinsky was a pioneer of abstract art and a co-founder of the Blue Rider movement. His emphasis on color, shape, and spirituality aligns with Picasso's exploration of unconventional styles and subjects.\n\n9. Max Ernst - Ernst, a German artist associated with Surrealism and Dadaism, shared Picasso's interest in experimental techniques and subject matter. Both artists often incorporated elements of collage and symbolism in their works.\n\n10. Francis Bacon - Bacon, an Irish-born artist, was heavily influenced by Picasso's distorted and emotive depictions of the human figure. Bacon's paintings often conveyed a sense of anguish and existentialism, much like Picasso's works during his Blue and Rose periods."
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 24,
"completion_tokens": 454,
"total_tokens": 478
}
}
I don't quite understand what am I doing wrong and what should I do to get a structured JSON response with the names of these 10 similar artists?
It looks like you aren't using the API properly. From the docs, take a look at the function calling code, where you can see examples of how to use this feature.
Your function definitions need to be passed as an array of objects under the
tools
parameter. See the docs for more. Hope this helps!