I want to execute POST URLRequest but first I need to create request body. The body should look like this:
{
"model": "gpt-4-vision-preview",
"messages": [
{
"role": "user",
"content": [
{
"type": "text",
"text": <mutableStringValue>
},
{
"type": "image_url",
"image_url": {
"url": <mutableStringValue>
}
}
]
}
],
"max_tokens": 300
}
I cannot hardcode this as .json file because parameters "text" (under first "type") and "image_url" (under second "type") are given as function parameters.
I don't know how to handle two "type" keys.
As of now, I came up with something like this:
struct ImageInputRequestBody: Codable {
let model: String = "gpt-4-vision-preview"
let messages: [Message]
let maxTokens: Int = 300
enum CodingKeys: String, CodingKey {
case model, messages
case maxTokens = "max_tokens"
}
struct Message: Codable {
let role: String
let content: [Content]
}
struct Content: Codable {
let type: String
let text: String?
}
}
But here I'm missing second "type" and "image_url" content
You could try something simple like this:
Note, you need to add two (or more for multi-images)
Contentto theMessageobject.For example:
EDIT-1
Use it like this to post to OpenAI