cai/examples/basic/function_calling.py

20 lines
394 B
Python

from cai import CAI, Agent
client = CAI()
def get_weather(location) -> str:
return "{'temp':67, 'unit':'F'}"
agent = Agent(
name="Agent",
instructions="You are a helpful agent.",
functions=[get_weather],
)
messages = [{"role": "user", "content": "What's the weather in NYC?"}]
response = client.run(agent=agent, messages=messages)
print(response.messages[-1]["content"])