OpenAI-API-dotnet icon indicating copy to clipboard operation
OpenAI-API-dotnet copied to clipboard

WebException: The request was aborted: The request was canceled.

Open frankcarey opened this issue 2 years ago • 4 comments

After upgrading from 1.2.0 to 1.6.0, I now get this exception. I just reverted and the older version works appropriately for our usecase. We get back the first word in the StreamCompletionAsync and then this exception, so that we don't get the full response. Anyone have some ideas?

Context is it's running in Unity 2022.2.12f. Again, this was working fine and the API only changed slightly to use model vs engine, so I'm guessing this is somehow related to something that changed between 1.2.0 and 1.6.0?

Here's the stack trace..

WebException: The request was aborted: The request was canceled.
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 <ea6e75a573bd4813a6e91970c73a6145>:0)
System.Net.WebResponseStream.ReadAsync (System.Byte[] buffer, System.Int32 offset, System.Int32 count, System.Threading.CancellationToken cancellationToken) (at <ea6e75a573bd4813a6e91970c73a6145>:0)
System.IO.StreamReader.ReadBufferAsync () (at <27586baf39bf4babbfd8a2caabe8e228>:0)
System.IO.StreamReader.ReadLineAsyncInternal () (at <27586baf39bf4babbfd8a2caabe8e228>:0)
OpenAI_API.EndpointBase+<HttpStreamingRequest>d__16`1[T].MoveNext () (at <a810dcbac798453c99b7645a591c752c>:0)
OpenAI_API.EndpointBase+<HttpStreamingRequest>d__16`1[T].System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult (System.Int16 token) (at <a810dcbac798453c99b7645a591c752c>:0)
OpenAI_API.Completions.CompletionEndpoint.StreamCompletionAsync (OpenAI_API.Completions.CompletionRequest request, System.Action`1[T] resultHandler) (at <a810dcbac798453c99b7645a591c752c>:0)
OpenAI_API.Completions.CompletionEndpoint.StreamCompletionAsync (OpenAI_API.Completions.CompletionRequest request, System.Action`1[T] resultHandler) (at <a810dcbac798453c99b7645a591c752c>:0)

frankcarey avatar Mar 29 '23 22:03 frankcarey

I'm getting the same thing. Also with the new chat streaming. Btw for unity I commented out the IHttp interface line. Did you include it?

CameronBonde avatar Apr 11 '23 14:04 CameronBonde

Same problem here. If you mean the HttpClientFactory. I commented this out, too.

robertdoehler avatar Jun 22 '23 13:06 robertdoehler

mhh yea indeed it is a problem with the factory. if you dive deeper into this problem this seems not so trivial. But I found I very detailed article about it. And if you implement this version of a hacked HttpFactory, streaming will work.

See in section "Writing the Unity HttpClient factory"

https://ticehurst.com/2021/08/27/unity-httpclient.html

robertdoehler avatar Jun 22 '23 13:06 robertdoehler

Stuck at the same problem for a whiiiiilleeee now, could you solve it? and if yes, how? I could not find the HttpFactory part that will make streaming work. Heeeelp please @robertdoehler @CameronBonde @frankcarey

DaliaDawod avatar Aug 25 '23 10:08 DaliaDawod