0

I am trying to send an image for ChatCompletion using the Microsoft provided Azure OpenAi java sdk "com.azure:azure-ai-openai:1.0.0-beta.9".

val cco = ChatCompletionsOptions(
        mutableListOf(
        ChatRequestSystemMessage("You are an assistant which does Optical Character Recognition    on scanned medical documents."),
        ChatRequestUserMessage(mutableListOf<ChatMessageContentItem>(
            ChatMessageTextContentItem("Read text from the scanned medical document. Only respond with the text content."),
            ChatMessageImageContentItem(ChatMessageImageUrl("data:${contentType};base64,${Base64.getEncoder().encodeToString(bytes)}"
        ))
    ))))

The content is however not being sent correctly. It seems that the Microsoft provided client is not encoding the content correctly. Can someone confirm if this implementation works. The same code works with kotlin-openai and other libraries.

"error": {
    "message": "This model's maximum context length is 128000 tokens. However, your messages resulted in 291246 tokens. Please reduce the length of the messages.",
    "type": "invalid_request_error",
    "param": "messages",
    "code": "context_length_exceeded"
} 

Someone to help with a issued faced during coding nd confirm if the specified library does indeed work.

1
  • What is the model you are using? Commented Jul 3, 2024 at 5:42

1 Answer 1

0

The issue has been raised on Github and agreed as a bug in azure-ai-openai SDK for Java, version 1.0.0-beta.9 - see github issue: https://github.com/Azure/azure-sdk-for-java/issues/40900

The fix has been pulled: https://github.com/Azure/azure-sdk-for-java/pull/40687 and based on the last comment, it looks like it is now included in version 1.0.0-beta.10 (see in maven)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.