64bit / async-openai

Rust library for OpenAI
https://docs.rs/async-openai
MIT License
1.09k stars 161 forks source link

【help】Could you please give me an example of defining multiple functions? #217

Closed moom-en closed 2 months ago

moom-en commented 4 months ago

Why do I execute one function every time and not multiple functions? let request = CreateChatCompletionRequestArgs::default() .max_tokens(512u16) .model("gpt-3.5-turbo-0125") .messages("Can you tell me which doctors will be available the day after tomorrow?") .tools(vec![ChatCompletionToolArgs::default() .r#type(ChatCompletionToolType::Function) .function( FunctionObjectArgs::default() .name("register_list") .description("Query the doctor’s consultation registration information on a certain day") .parameters(json!({ "type": "object", "properties": { "date": { "type": "string", "description": "visit date,format:yyyy-MM-dd,e.g:2024-01-01", }, }, "required": ["date"], })) .build()?, ) .build()?, ChatCompletionToolArgs::default() .r#type(ChatCompletionToolType::Function) .function( FunctionObjectArgs::default() .name("now_time") .description("this is test, don't execute") .build()?, ) .build()? ]) .build()?; if let Some(tool_calls) = res_msg.tool_calls { println!("{:?}", tool_calls); // always execute now_time, omitting part of the code } fn calc_now_time() -> String { Local::now().naive_local().format("%Y-%m-%d %H:%M:%S").to_string() } fn erp_register_list(args: &str) -> String { "doctor one".to_string() } I want, now_time should be executed first to convert the date and then register_list

64bit commented 2 months ago

Please take a look at https://github.com/64bit/async-openai/tree/main/examples/assistants-func-call-stream it has multiple function calls, same idea can be applied for chat completions?

moom-en commented 2 months ago

Please take a look at https://github.com/64bit/async-openai/tree/main/examples/assistants-func-call-stream it has multiple function calls, same idea can be applied for chat completions?

Thanks, I defined multiple functions, but basically the first one will be executed every time. Others can also be executed, but the probability of triggering is not as high as the first one. I don't know why. Also, when I ask some regular questions that don't require function calls at all, she will also adjust a certain function, which also makes me confused. . .

64bit commented 2 months ago

Your queries are specific to behavior of the API, right channel for it is official OpenAI channels:

https://help.openai.com/en/

moom-en commented 2 months ago

Your queries are specific to behavior of the API, right channel for it is official OpenAI channels:

https://help.openai.com/en/

Thanks