openai / openai-dotnet

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

stream_options is included in every request even though it is optional #207

Open markwallace-microsoft opened 1 week ago

markwallace-microsoft commented 1 week ago

Confirm this is not an issue with the OpenAI Python Library

Confirm this is not an issue with the underlying OpenAI API

Confirm this is not an issue with Azure OpenAI

Describe the bug

In the OpenAI document stream_options is optional and defaults to null. In the library it has a default value and is always sent when streaming is enabled.

The ask here is to update the implementation to match the API specification so that unnecessary properties are not being sent by default.

To Reproduce

  1. Make a streaming chat completion requests
  2. Inspect the request being generated and you will see stream_options is included.
{
  "messages": [
    {
      "role": "user",
      "content": "Can you help me tell the time in Seattle right now?"
    }
  ],
  "model": "gpt-4o",
  "stream": true,
  "stream_options": {
    "include_usage": true
  }
}

Code snippets

No response

OS

winOS

.NET version

8.0

Library version

2.0.0-beta.10

joseharriaga commented 1 week ago

Thank you for reaching out, @markwallace-microsoft ! Could you please provide more context about why making stream_options optional to match the REST API is important to you?

The reason why we always set it to true in the library on behalf of the user is because:

  1. Our current hypothesis is that there is no scenario for someone actually wanting to turn it off.
  2. Our understanding is that the reason why it is optional in the REST API is for app compatibility, but since this .NET library is new, then there is no existing code written using this library that we need app compatibility for.
  3. By always defaulting this property to true in the background, we can simplify the library's API. In other words, we can make it one less thing that users need to learn how to use.

We would love to hear your thoughts!