C#C
C#3y ago
18 replies
Sebastian

No error log - app quits (async problem?)

Hey,

I am working on an app that has multiple background workers:
List<Tasks> tasks = [];
foreach (var item in items)
{ 
    // Could be I am doing this wrong? I am learning async as I go
    tasks.Add(Task
        .Run(async () => await StepOne(foo))
        .ContinueWith(async x => await StepTwo(boo));
} 

await Task.WhenAll(tasks);
// End app


StepOne works correctly, in StepTwo I am calling OpenAI API via this NuGet (https://github.com/OkGoDoIt/OpenAI-API-dotnet).
// OAI is just wrapper around OpenAPI NuGet
await OAI.Service.TextToSpeech.SaveSpeechToFileAsync(new TextToSpeechRequest()
{
    Input = "Lorem ipsum",
    ResponseFormat = ResponseFormats.MP3,
    Model = Model.TTS_HD,
    Voice = Voices.Shimmer,
    Speed = 1.1,
}, outputFile);


On this line my app (Console application) just turns off - no error log, nothing.
So I tried doing try-catch block - nothing.

I debugged and figured out problem is here (L133):
https://github.com/OkGoDoIt/OpenAI-API-dotnet/blob/5f7c23a928be39da87e89d5105a044ecb7401727/OpenAI_API/EndpointBase.cs#L133

It's being called with following:
req: {Method: POST, RequestUri: 'https://api.openai.com/v1/audio/speech', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Content-Type: application/json; charset=utf-8
}}
streaming: false

Seems to be correct (calling other endpoint with same NuGet - e.g. chat completion works)

I cloned the repo, put try-catch block around that line - still nothing.
When trying to debug the HttpClient method my debugger is just jumping all around place without sense.

I guess I would have to get the code of HttpClient locally and do it like that - but at that point I am wondering.

Anyone has idea why this is happening? I expect it's because of how I use Tasks?
I am clueless here, not getting any output or error anywhere :/
Was this page helpful?