Skip to content

HttpStreamingRequest reads the headers again for each loop #47

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

Closed
KeithHenry opened this issue Feb 15, 2023 · 1 comment
Closed

HttpStreamingRequest reads the headers again for each loop #47

KeithHenry opened this issue Feb 15, 2023 · 1 comment

Comments

@KeithHenry
Copy link

In a while ((line = await reader.ReadLineAsync()) != null) loop the response headers are read each time:

try
{
res.Organization = response.Headers.GetValues("Openai-Organization").FirstOrDefault();
res.RequestId = response.Headers.GetValues("X-Request-ID").FirstOrDefault();
res.ProcessingTime = TimeSpan.FromMilliseconds(int.Parse(response.Headers.GetValues("Openai-Processing-Ms").First()));
res.OpenaiVersion = response.Headers.GetValues("Openai-Version").FirstOrDefault();
if (string.IsNullOrEmpty(res.Model))
res.Model = response.Headers.GetValues("Openai-Model").FirstOrDefault();
}
catch (Exception e)
{
Debug.Print($"Issue parsing metadata of OpenAi Response. Url: {url}, Error: {e.ToString()}, Response: {resultAsString}. This is probably ignorable.");
}

These don't change and are in a try-catch that is expensive when a throw happens.

@OkGoDoIt
Copy link
Owner

good catch, fixing now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants