openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI/AbsoluteLatest
MIT License
1.04k stars 99 forks source link

De-serialization error using AssistantClient streaming #200

Closed castroal closed 1 week ago

castroal commented 2 weeks ago

Confirm this is not an issue with the underlying OpenAI API

Confirm this is not an issue with Azure OpenAI

Describe the bug

Using the AssistantClient with file search enabled and streaming gives the error: The requested operation requires an element of type 'String', but the target element has type 'Object'.'

The exception is raised here: https://github.com/openai/openai-dotnet/blob/79014abc01a00e13d5a334d3f6529ed590b8ee98/src/Generated/Models/InternalRunStepDeltaStepDetailsToolCallsFileSearchObject.Serialization.cs#L115

To Reproduce

  1. Create and streaming enumerate a Run using an assistant with file search enabled.

Code snippets

var response = assistantClient.CreateRunStreamingAsync(
    threadId: "thread_id",
    assistantId: "assistant_id",
    options: new RunCreationOptions {},
    cancellationToken: cToken);

await foreach (var update in response.WithCancellation(cToken))
{
     //after a couple of updates, the error "InvalidOperationException The requested operation requires an element of type 'String', but the target element has type 'Object'." is raised.
}

OS

Windows 11

.NET version

net8.0

Library version

2.0.0-beta.10

span commented 2 weeks ago

Seeing this in beta.3 as well and tried upgrading to beta.10.

It seems to me there have been changes in the API, since beta.3 has been working very well for months.

I wrote a foum post in openai forums about this as well.

https://community.openai.com/t/invalid-json-in-assistants-streaming-with-annotations/926883

citron8000 commented 2 weeks ago

I am having the same problem since yesterday. It worked fine before for weeks. I'm with beta.7.

joseharriaga commented 2 weeks ago

Thank you for reaching out, @castroal ! I'm able to repro the issue. @span is correct that the issue is related to a recent change in the service's REST API exposing a latent bug in the library. We're working on a fix that we hope to release early next week.

joseharriaga commented 1 week ago

This has been fixed as part of this PR: 🔗 https://github.com/openai/openai-dotnet/pull/206

We also just pushed a release today, so the fix is now live starting with version 2.0.0-beta.11: 🔗 https://www.nuget.org/packages/OpenAI/2.0.0-beta.11

Thank you!

span commented 1 week ago

.On 4 Sept 2024 12:52, SatoshiMorinaga @.***> wrote: I tried it with beta11 and got the same error. Has anyone had the issue resolved with beta11?

Works great for me with 11