OkGoDoIt / OpenAI-API-dotnet

An unofficial C#/.NET SDK for accessing the OpenAI GPT-3 API
https://www.nuget.org/packages/OpenAI/
Other
1.86k stars 432 forks source link

[Request] Add support to tool and tool_choice for Chat DefaultCompletionRequestArgs #218

Closed pedroaurelli closed 5 months ago

pedroaurelli commented 5 months ago

Issue create to request support to tool and tool_choice functions to Chat completion body requests.

Example using nodejs by openAi documentation:

import OpenAI from "openai";

const openai = new OpenAI();

async function main() {
  const messages = [{"role": "user", "content": "What's the weather like in Boston today?"}];
  const tools = [
      {
        "type": "function",
        "function": {
          "name": "get_current_weather",
          "description": "Get the current weather in a given location",
          "parameters": {
            "type": "object",
            "properties": {
              "location": {
                "type": "string",
                "description": "The city and state, e.g. San Francisco, CA",
              },
              "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
            },
            "required": ["location"],
          },
        }
      }
  ];

  const response = await openai.chat.completions.create({
    model: "gpt-4-turbo",
    messages: messages,
    tools: tools,
    tool_choice: "auto",
  });

  console.log(response);
}

main();

OpenAI documentation: https://platform.openai.com/docs/api-reference/chat/create

#

Suggest

OkGoDoIt commented 5 months ago

The new beta version of the package supports this, see https://devblogs.microsoft.com/dotnet/openai-dotnet-library/ for the announcement