openai / openai-dotnet

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

CreateThreadAndRunAsync does not use RunCreationOptions.AdditionalInstructions #77

Open Blackbaud-TimMcVicker opened 1 week ago

Blackbaud-TimMcVicker commented 1 week ago

Calling CreateThreadAndRunAsync with a RunCreationOptions parameter that sets AdditionalInstructions does not set that on the actual run. Creating the Thread and Run separately works correctly.

Package version: OpenAI 2.0.0-beta.5.

In both of the following examples, the Instructions on my assistant are "Be serious".

The following code results in a threadRun with Instructions set to “Be serious”:

var threadRun = await assistantClient.CreateThreadAndRunAsync(assistant, new ThreadCreationOptions
{
    InitialMessages =
    {
        new ThreadInitializationMessage(
            new List<MessageContent>
            {
                request.InitialMessage
            })
    },
}, new RunCreationOptions
{
    AdditionalInstructions = "You need to be funny."
});

The following code results in a threadRun with Instructions set to “Be serious You need to be funny.”:

var thread = await assistantClient.CreateThreadAsync(new ThreadCreationOptions
{
    InitialMessages =
    {
        new ThreadInitializationMessage(
            new List<MessageContent>
            {
                request.InitialMessage
            })
    },
}, cancellationToken);

var threadRun = await assistantClient.CreateRunAsync(thread.Value.Id, assistant.Id, new RunCreationOptions
{
    AdditionalInstructions = "You need to be funny."
}, cancellationToken);
trrwilson commented 1 week ago

Thanks, @Blackbaud-TimMcVicker, great find!

The root of this issue is that AdditionalInstructions isn't part of the specified request body parameters for the operation, as you can see in the API reference -- I strongly suspect this was just an oversight (AdditionalInstructions was added a bit later) and hope that'll get addressed; it makes much more sense for CreateThreadAndRun to take options for a thread and options for a run than it does to have an entirely new options type that just selectively omits one thing!

In the interim while that discrepancy is still being resolved at the spec level, you can of course create the thread and run separately -- the CreateThread operation does properly honor the AdditionalInstructions.