Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAIHttpException Fields [id, created, model, choices] are required #205

Open
cempo opened this issue Jun 26, 2023 · 5 comments
Open

OpenAIHttpException Fields [id, created, model, choices] are required #205

cempo opened this issue Jun 26, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@cempo
Copy link

cempo commented Jun 26, 2023

Description

The issue happened during openAI.chatCompletions(chatCompletionRequest) call. Not 100% but sometimes. Doesn't depend on requested message.

In the current implementation I use:

val chatCompletionRequest = ChatCompletionRequest(
            model = ModelId("gpt-3.5-turbo-0613"),
            messages = listOf(
                //Messages here
            )
        )
val responseMessage = openAI.chatCompletions(chatCompletionRequest)

If I make the same request one more time it works correct

Environment

  • com.aallam.openai:openai-client-bom version: 3.2.5, 3.3.0, 3.3.1
  • Kotlin version: 1.8.21
  • OS: Android

Additional Info

Fields [id, created, model, choices] are required for type with serial name 'com.aallam.openai.api.chat.ChatCompletionChunk', but they were missing at path: $
com.aallam.openai.api.exception.OpenAIHttpException: Fields [id, created, model, choices] are required for type with serial name 'com.aallam.openai.api.chat.ChatCompletionChunk', but they were missing at path: $
at com.aallam.openai.client.internal.http.HttpTransport.handleException(HttpTransport.kt:52)
at com.aallam.openai.client.internal.http.HttpTransport.perform(HttpTransport.kt:34)
at com.aallam.openai.client.internal.http.HttpTransport$perform$2.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
Caused by: kotlinx.serialization.MissingFieldException: Fields [id, created, model, choices] are required for type with serial name 'com.aallam.openai.api.chat.ChatCompletionChunk', but they were missing at path: $
at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:93)
at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107)
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invokeSuspend(ChatApi.kt:56)
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invoke(Unknown Source:8)
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invoke(Unknown Source:4)
at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:50)
at io.ktor.client.statement.HttpStatement$execute$1.invokeSuspend(Unknown Source:15)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) 
Caused by: kotlinx.serialization.MissingFieldException: Fields [id, created, model, choices] are required for type with serial name 'com.aallam.openai.api.chat.ChatCompletionChunk', but they were missing
at kotlinx.serialization.internal.PluginExceptionsKt.throwMissingFieldException(PluginExceptions.kt:20)
at com.aallam.openai.api.chat.ChatCompletionChunk.(ChatCompletionChunk.kt:14)
at com.aallam.openai.api.chat.ChatCompletionChunk.(Unknown Source:0)
at com.aallam.openai.api.chat.ChatCompletionChunk$$serializer.deserialize(ChatCompletionChunk.kt:14)
at com.aallam.openai.api.chat.ChatCompletionChunk$$serializer.deserialize(ChatCompletionChunk.kt:14)
at kotlinx.serialization.json.internal.StreamingJsonDecoder.decodeSerializableValue(StreamingJsonDecoder.kt:70)
at kotlinx.serialization.json.Json.decodeFromString(Json.kt:107) 
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invokeSuspend(ChatApi.kt:56) 
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invoke(Unknown Source:8) 
at com.aallam.openai.client.internal.api.ChatApi$chatCompletions$1$1.invoke(Unknown Source:4) 
at io.ktor.client.statement.HttpStatement.execute(HttpStatement.kt:50) 
at io.ktor.client.statement.HttpStatement$execute$1.invokeSuspend(Unknown Source:15) 
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) 
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) 
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) 
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) 

@aallam
Copy link
Owner

aallam commented Jun 28, 2023

Seems like some required fields are not returned by the API in stream mode! I will try to reproduce this.

@aallam aallam added the bug Something isn't working label Jun 28, 2023
@valbaca
Copy link

valbaca commented Jul 31, 2023

The fields are marked as nullable, but don't have a default of null, so they're still required but are just able to be null.

@aallam
Copy link
Owner

aallam commented Aug 2, 2023

Hey @valbaca, are you referring to the ChatCompletionChunk class?
By the way, the OpenAPI specification suggests that these fields are required, but sometimes the specification isn't up-to-date with the actual API :/

@paulotaylor
Copy link

I'm also seeing this, I think it happens when the tokens are maxed out but I'm not completely sure about this.

@lexpod
Copy link

lexpod commented Jan 16, 2024

The exception happens when Open AI returns an error instead of a regular response message. Currently, the library swallows error info from OpenAI replacing it with a serialization exception as noted in the title of the issue.

Example of openAI error message:
data: {"error":{"message":"The server had an error processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if you keep seeing this error. (Please include the request ID 214a587d9c29eb3136e10b9f1 in your email.)","type":"server_error","param":null,"code":null}}
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants