Hello,
This issue could be reproduced in android platform.
Based on this Tutorial: Create a recommendation app with .NET MAUI and ChatGPT, it will create a .NET MAUI app for **Windows ** in Visual Studio that calls OpenAI's ChatGPT APIs, android platforms do not include it.
You can open an issue in the openai dotnet, confirm with PG about will this nuget package support for android platform.
However, you can call REST API by HttpClient to do it.
var apiKey = "sk-xxxxxxxxxxxxx"; // input your API Key
var endpoint = "https://api.openai.com/v1/chat/completions";
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");
var requestBody = new
{
model = "gpt-3.5-turbo",
messages = new[]
{
new { role = "user", content = "Say a quote" }
}
};
var requestContent = new StringContent(
JsonSerializer.Serialize(requestBody),
Encoding.UTF8,
"application/json"
);
var response = await httpClient.PostAsync(endpoint, requestContent);
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.