OpenAI has ClientResult`1 and there is no clue how to use that

I’ve noticed discussions about OpenAI in the WIP thread. And at first I wanted to say “why so complicated”, remembering my experience in 2023. A lot of things have really changed since then, neural networks have gotten smarter and APIs have changed a lot.

I downloaded OpenAI nuget, the official repository for C#, and decided to quickly build an example that I could show with the words “this is so simple”. But! I came across something that made my head spin a bit, and maybe you know how to work with something like this? I do not want to find out that it is impossible to work with it because of the wrapper over http request. The 2023 library worked fine.

It turns out that I can’t figure out how to get anything out of this ClientResult`1. The C# code should look like this:

using OpenAI.Chat;

ChatClient client = new(model: "gpt-4o", apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY"));

ChatCompletion completion = client.CompleteChat("Say 'this is a test.'");

Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");

I don’t know how to get this ClientResult`1 without an API key, but maybe you can have a look at the patch and see what I’ve missed?

openai_.vl (13.5 KB)

Not an answer to your question but there is also this unofficial client library for OpenAI.

1 Like

@bjoern Yeah, I know. In a way, it’s even better and maybe more suitable for use in Gamma. However, as if “official library” sounds better than “unofficial library”.

openai_dotnet_.vl (27.4 KB)

The original question still stands