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

Example of multiple function calls #151

Closed
ysimonson opened this issue Nov 20, 2023 · 2 comments
Closed

Example of multiple function calls #151

ysimonson opened this issue Nov 20, 2023 · 2 comments

Comments

@ysimonson
Copy link

GPT-4 Turbo supports multiple function calls, but I couldn't any examples of this in async-openai yet. It took me a little while to stitch together how to do this since it's a bit divergent from single function calls, so maybe this minimal demonstration will be helpful to someone else:

let request = CreateChatCompletionRequestArgs::default()
    .model("gpt-4-1106-preview")
    .messages([
        ChatCompletionRequestUserMessageArgs::default()
            .content(prompt)
            .build()?
            .into(),
        ChatCompletionRequestSystemMessageArgs::default()
            .content(SYSTEM_PROMPT)
            .build()?
            .into(),
    ])
    .max_tokens(512u16)
    .stream(false)
    .tools([
        ChatCompletionToolArgs::default()
            .r#type(ChatCompletionToolType::Function)
            .function(
                // ... build ChatCompletionFunctions here ...
            )
            .build()?,
        ...
    ])
    .build()?;

if let Some(tool_calls) = response_message.tool_calls {
    tool_calls
        .into_iter()
        .map(|tool_call| ...)
        .collect()?;
}
@64bit 64bit added help wanted Extra attention is needed good first issue Good for newcomers and removed help wanted Extra attention is needed good first issue Good for newcomers labels Nov 26, 2023
@64bit
Copy link
Owner

64bit commented Nov 26, 2023

Seems like this was addressed in #153? yes?

@ysimonson
Copy link
Author

Yup!

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

No branches or pull requests

2 participants