openai / openai-dotnet

The official .NET library for the OpenAI API
https://www.nuget.org/packages/OpenAI
MIT License
1.13k stars 113 forks source link

Should OpenAIModelFactory be public? #46

Closed Blackbaud-TimMcVicker closed 2 months ago

Blackbaud-TimMcVicker commented 3 months ago

In the initial Azure.Ai.OpenAi versions of this library, we could use AzureOpenAIModelFactory to create objects to use in our mocks, per this issue https://github.com/Azure/azure-sdk-for-net/issues/36462. This was useful when writing tests that mocked out the OpenAIClient.

The new version of that seems to be marked internal instead of public. Is that intentional? If so, what should we be using to create those objects in our mocks?

KrzysztofCwalina commented 3 months ago

We will be adding an official way to create models for mocking, but for now you can use the following workaround:

        ChatCompletion completion = ModelReaderWriter.Read<ChatCompletion>(BinaryData.FromObjectAsJson(new {
            id = "1234",
            choices = new object[]
            {
                new {
                    finish_reason = "stop",
                    index = 0,
                    message = new {
                        content = "It's a nice day today!",
                        role = "assistant"
                    }
                }
            },
            created = DateTimeOffset.Now.ToUnixTimeSeconds(),
            model = "model",
            system_fingerprint = "N/A",
            @object = "N/A",
            usage = (object)null
        }));
joseharriaga commented 2 months ago

I have created the following issue to track the work needed to add support for mocking: 🔗 https://github.com/openai/openai-dotnet/issues/121

I will close the present issue so that we can follow up in one single place. 😊 Thank you, @Blackbaud-TimMcVicker !