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

Provide function call example using tool_calls #143

Closed
sloganking opened this issue Nov 10, 2023 · 4 comments
Closed

Provide function call example using tool_calls #143

sloganking opened this issue Nov 10, 2023 · 4 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@sloganking
Copy link

https://github.com/64bit/async-openai/blob/main/examples/function-call/src/main.rs

The current function call example uses the now deprecated ChatCompletionResponseMessage::function_call field. It was deprecated in favor of ChatCompletionResponseMessage::tool_calls. Can an example be provided using the new tool_calls method?

@SpaghettiFibonacci
Copy link

SpaghettiFibonacci commented Nov 10, 2023

Here is an example of how to use it meanwhile:

let tool = ChatCompletionToolArgs::default()
        .r#type(async_openai::types::ChatCompletionToolType::Function)
        .function(ChatCompletionFunctions { 
                name: "get_current_weather".to_string(), 
                description: Some("Get weather in location".to_string()), 
                parameters: json!({
                    "type": "object",
                    "properties": {
                        "location": {
                            "type": "string",
                            "description": "The city and state, e.g. San Francisco, CA",
                        },
                        "format": {
                            "type": "string",
                            "enum": ["celsius", "fahrenheit"],
                            "description": "The temperature unit to use. Infer this from the users location.",
                        },
                    },
                    "required": ["location", "format"],
                    
                }) 
            }).build()?;

and for the tool choice

        .tool_choice(ChatCompletionToolChoiceOption::Auto)

Though I am not sure it is working right now!

Error: ApiError(ApiError { message: "'$.tool_choice' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.", type: Some("invalid_request_error"), param: None, code: None })

@sloganking
Copy link
Author

Okay thanks, I will continue using the deprecated option for now and maybe come back to this when it has been tested further. or test it some on my own later.

@SpaghettiFibonacci
Copy link

SpaghettiFibonacci commented Nov 11, 2023

When leaving out

        .tool_choice(ChatCompletionToolChoiceOption::Auto)

it should work

@64bit
Copy link
Owner

64bit commented Nov 26, 2023

An example was added in #153. And the bug was fixed in #158

Seems like everything is resolved, hence closing the issue.

@64bit 64bit closed this as completed Nov 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants