weather_tool = {
"type": "function",
"strict": True,
"function": {
"name": "get_current_weather",
"description": "Get the current weather in a given location",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA"
},
"unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}
},
"required": ["location"]
}
}
}
available_functions = {
"get_current_weather": get_current_weather,
}
maitai_client = maitai.MaitaiAsync()
response = await maitai_client.chat.completions.create(
messages=messages,
model="llama3-groq-70b-8192-tool-use-preview", ## Remove this line to set model in Portal
session_id="YOUR_SESSION_ID",
intent="CONVERSATION",
application="demo_app",
tool_choice="auto",
tools=[weather_tool],
}
for tool_call in response.choices[0].message.tool_calls:
function_to_call = available_functions[tool_call.function.name]
function_args = json.loads(tool_call.function.arguments)
function_response = function_to_call(**function_args)