# 第一步:定义函数声明 schedule_meeting_function = { "name":"schedule_meeting", "description":"Schedules a meeting with specified attendees at a given time and date.", "parameters": { "type":"object", "properties": { "attendees": { "type":"array", "items": {"type":"string"}, "description":"List of people attending the meeting.", }, "date": { "type":"string", "description":"Date of the meeting (e.g., '2024-07-29')", }, "time": { "type":"string", "description":"Time of the meeting (e.g., '15:00')", }, "topic": { "type":"string", "description":"The subject or topic of the meeting.", }, }, "required": ["attendees","date","time","topic"], }, }
# 第三步:发送请求 response = client.models.generate_content( model="gemini-2.5-flash", contents="Schedule a meeting with Bob and Alice for 03/14/2025 at 10:00 AM about the Q3 planning.", config=config, )
# 第四步:处理响应 ifresponse.candidates[0].content.parts[0].function_call: function_call = response.candidates[0].content.parts[0].function_call print(f"Function to call:{function_call.name}") print(f"Arguments:{function_call.args}") # 在实际应用中,这里会调用真实的函数 # result = schedule_meeting(**function_call.args) else: print("No function call found in the response.") print(response.text)