Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new tool choices to the ChatCompletionCreateRequest and ChatMessa… #432

Merged
merged 6 commits into from
Dec 5, 2023

Conversation

shanepowell
Copy link
Contributor

Add new tool choices to the ChatCompletionCreateRequest and ChatMessage response messages.
Mark the old function api as Obsolete.
Added playground tests to test the new function calling and also get the streaming function calling example working (in a messy way).

…ge response messages.

Mark the old function api as Obsolete.
Added playground tests to test the new function calling and also get the streaming function calling example working (in a messy way).
shanepowell and others added 2 commits December 5, 2023 06:59
Support has been added for passing as object to the function field in the tool.
@kayhantolga
Copy link
Member

Hi, I made some changes. I removed support for legacy functions as they can easily be converted to tools, which will make the SDK cleaner. I also added support for AsObject to the functionDefination in ToolDefinition, as some may need it. I have only one comment, please take a look. I think you may have forgotten to remove that class by mistake.If yes, please remove it. If no, could you please clarify what it is?

@kayhantolga kayhantolga added this to the 7.4.2 milestone Dec 4, 2023
@shanepowell
Copy link
Contributor Author

Your changes looks good to me.

What class are you referring to by 'may have forgotten to remove that class by mistake'?

Do you mean the class ToolChoiceFunction?

This is meant to be used with the ChatCompletionCreateRequest.ToolChoice field.
That field can be a string, e.g.

request.ToolChoice = StaticValues.CompletionStatics.ToolChoice.Auto;

or

request.ToolChoice = StaticValues.CompletionStatics.ToolChoice.None;

or a ToolChoiceFunction instance.
e.g.

request.ToolChoice = new ToolChoiceFunction() { Function = new FunctionTool() { Name = "get_current_weather" }};

That is why I setup the ToolChoice as a object.

You can see I tested it by commenting out the code bits in this block of the RunChatFunctionCallTest method:

            ConsoleExtensions.WriteLine("Chat Function Call Test:", ConsoleColor.DarkCyan);
            var completionResult = await sdk.ChatCompletion.CreateCompletion(new ChatCompletionCreateRequest
            {
                Messages = new List<ChatMessage>
                {
                    ChatMessage.FromSystem("Don't make assumptions about what values to plug into functions. Ask for clarification if a user request is ambiguous."),
                    ChatMessage.FromUser("Give me a weather report for Chicago, USA, for the next 5 days.")
                },
                Tools = new List<ToolDefinition> { new() { Function = fn1 }, new() { Function = fn2 }, new() { Function = fn3 }, new() { Function = fn4 }, new() { Function = fn4 } },
                // optionally, to force a specific function:
                // ToolChoice = new ToolChoiceFunction() { Function = new FunctionTool() { Name = "get_current_weather" }},
                // or auto tool choice:
                // ToolChoice = StaticValues.CompletionStatics.ToolChoice.Auto,
                MaxTokens = 50,
                Model = Models.Gpt_3_5_Turbo
            });

…es, updated playground regarding changes. Updated some documentation.
@kayhantolga
Copy link
Member

Oh, I see. That makes sense. I have made some changes to the usage. I don't like the given object as a default field because it may leave developers in the dark about which objects are acceptable. I will be merging these changes. Please leave a comment if you disagree with any of my changes so that we can further improve this pull request and merge again.

(I removed default tool values, etc., because in the future, I think OpenAI will introduce different types, and using functions as defaults will lose its purpose and may create confusion for both new and existing developers.)

@kayhantolga kayhantolga merged commit 816e64d into betalgo:dev Dec 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants