Skip to content

ChatCompletionAsStream() throws PlatformNotSupportedException on iOS #622

@ChaseIngersol

Description

@ChaseIngersol

We have a Blazor Maui Hybrid app that's currently running on Windows, macOS, iOS, and Android. When making a call to OpenAIService.CreateCompletionAsStream() on an iOS device, the following exception occurs:

System.PlatformNotSupportedException: Operation is not supported on this platform.
   at System.Net.Http.HttpClientHandler.Send(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpMessageInvoker.Send(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.Send(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken)
   at OpenAI.GPT3.Extensions.HttpClientExtensions.PostAsStreamAsync(HttpClient client, String uri, Object requestModel, CancellationToken cancellationToken)
   at OpenAI.GPT3.Managers.OpenAIService.CreateCompletionAsStream(ChatCompletionCreateRequest chatCompletionCreateRequest, String modelId, CancellationToken cancellationToken)+MoveNext()
   at OpenAI.GPT3.Managers.OpenAIService.CreateCompletionAsStream(ChatCompletionCreateRequest chatCompletionCreateRequest, String modelId, CancellationToken cancellationToken)+System.Threading.Tasks.Sources.IValueTaskSource<System.Boolean>.GetResult()

The problem appears to be that iOS does not support synchronous HTTP operations, so calling return client.Send(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken); in HttpClientExtensions.PostAsStreamAsync() results in an exception.

I'll look into this more deeply when I have a few minutes free, but from a cursor glance it looks like fixing this would require a significant refactor to make this operation truly asynchronous.

  • OS: iOS 18.0 (22A5350a)
  • Language: C#
  • Version: 8.6.2

Metadata

Metadata

Labels

bugSomething isn't workingquestionFurther information is requested

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions