2 years ago
#58456
user1144596
Calling remote API with "async" in ASMX webservice not working
I am trying to call a remote API from OpenAI. However, I want to call the remote API via my C# ASMX web service. (ASP.NET webforms project .NET 4.7)
The problem I am facing is the the remote call does not completed, i.e. the execution does not go beyond "Result", and there is no error or anything else. It just hangs.
Any ideas?
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public async Task<string> InitializeAI(string question) {
string OpenAIKey = ConfigurationManager.AppSettings["OpenAI-APIKey"].ToString();
OpenAIAPI api = new OpenAIAPI(OpenAIKey);
var t = "AI:Hi, how are you.\nHuman:I am well.";
try
{
CompletionResult Result = await api.Completions.CreateCompletionAsync(new CompletionRequest(t, temperature: 0.1, stopSequences: " Human:, AI:")).Wait();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
}
return await Task.FromResult("ascb");
}
c#
web-services
asmx
openai-api
0 Answers
Your Answer