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

ChatCompletionAsStream() throws PlatformNotSupportedException on iOS #622

Open
ChaseIngersol opened this issue Sep 3, 2024 · 2 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@ChaseIngersol
Copy link
Contributor

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
@kayhantolga
Copy link
Member

Interesting. If I recall correctly, we had a similar issue previously, but it was fixed. Since then, we haven't seen the problem recur. If you could create a sample repository that I can use to reproduce the issue, I'd be able to look into this quickly.

@kayhantolga kayhantolga added bug Something isn't working enhancement New feature or request question Further information is requested and removed enhancement New feature or request labels Sep 6, 2024
@kayhantolga
Copy link
Member

Hi @ChaseIngersol,

I've noticed something in your stack trace: you have a dependency on OpenAI.GPT3, but you also mentioned you're using version 8.6.2. Version 8.6.2 shouldn't have any dependency on the legacy "OpenAI.GPT3" code. 🤔

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

No branches or pull requests

2 participants