Skip to content

[Feature Request: Brief Description] #403

@Anatolf

Description

@Anatolf

Hello. The com.aallam.openai library treats content as a string, not as an array of JSON objects.
As a result, the attached image is not parsed.

fun analyzeImageWithGPT(apiKey: String, imageUrl: String): String = runBlocking {
    val openAI = OpenAI(apiKey)
    
    val request = ChatCompletionRequest(
        model = ModelId("gpt-4o-mini"),
        messages = listOf(
            ChatMessage(
                role = ChatRole.User,
                content = """
                [
                    {
                        "type": "text",
                        "text": "What is in this image?"
                    },
                    {
                        "type": "image_url",
                        "image_url": {
                            "url": "$imageUrl"
                        }
                    }
                ]
            """.trimIndent()
            )
        ),
        maxTokens = 300
    )
    
    val response = openAI.chatCompletion(request)
    
    response.choices.firstOrNull()?.message?.content ?: "No response"
}

Maybe I'm not making the request correctly, please tell me?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions