OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 433 forks source link

[UNITY] Chat Streaming Error: WebException: The request was aborted: The request was canceled. #188

Closed barryyip0625 closed 10 months ago

barryyip0625 commented 10 months ago

I am using the chat streaming function in UNITY. I added the example code to my function

private async void ChatStreaming(string question){
        var chat = api.Chat.CreateConversation();
        chat.Model = Model.GPT4_Turbo;
        chat.RequestParameters.Temperature = TEMPERATURE;
        chat.AppendUserInput(question);

        await foreach (var res in chat.StreamResponseEnumerableFromChatbotAsync())
        {
                textbox.text += res.ToString();
        };
}

But when I click the play button, the WebException: The request was aborted: The request was canceled occur.


System.Net.HttpWebRequest.RunWithTimeoutWorker[T] (System.Threading.Tasks.Task`1[TResult] workerTask, System.Int32 timeout, System.Action abort, System.Func`1[TResult] aborted, System.Threading.CancellationTokenSource cts) (at <d054a9182977441aa432503a474315ba>:0)
System.Net.WebResponseStream.ReadAsync (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Threading.CancellationToken cancellationToken) (at <d054a9182977441aa432503a474315ba>:0)
System.IO.StreamReader.ReadBufferAsync () (at <787acc3c9a4c471ba7d971300105af24>:0)
System.IO.StreamReader.ReadLineAsyncInternal () (at <787acc3c9a4c471ba7d971300105af24>:0)
OpenAI_API.EndpointBase+<HttpStreamingRequest>d__17`1[T].MoveNext () (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAI_API.EndpointBase+<HttpStreamingRequest>d__17`1[T].System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (System.Int16 token) (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAI_API.Chat.Conversation+<StreamResponseEnumerableFromChatbotAsync>d__33.MoveNext () (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAI_API.Chat.Conversation+<StreamResponseEnumerableFromChatbotAsync>d__33.System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (System.Int16 token) (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAI_API.Chat.Conversation.StreamResponseFromChatbotAsync (System.Action`1[T] resultHandler) (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAI_API.Chat.Conversation.StreamResponseFromChatbotAsync (System.Action`1[T] resultHandler) (at <dfbbd232ee2d407d9a091311aec7200c>:0)
OpenAIService.ChatStreaming (System.String question) (at Assets/ChatGPT/Scripts/OpenAIService.cs:62)
System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state) (at <787acc3c9a4c471ba7d971300105af24>:0)
UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0)
UnityEngine.UnitySynchronizationContext.Exec () (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0)
UnityEngine.UnitySynchronizationContext.ExecuteTasks () (at <3b24cc7fa9794ed8ab04312c53e6dedd>:0)```
JiangongChen commented 10 months ago

Exactly the same issue. BTW, chat.GetResponseFromChatbotAsync() works well.

SlumberPenguin commented 10 months ago

same

barryyip0625 commented 10 months ago

I solved this issue by using this package https://github.com/srcnalt/OpenAI-Unity/tree/master

Ayfel commented 2 months ago

Seeing the same, any idea what the incompatibility is or where the issue originates from?