Skip to content

Commit

Permalink
Updated example.
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitprasad15 committed Jan 4, 2025
1 parent 6c9832e commit 80a8593
Showing 1 changed file with 43 additions and 26 deletions.
69 changes: 43 additions & 26 deletions examples/simple_tool_calling.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"metadata": {},
"outputs": [],
"source": [
"import aisuite as ai\n",
"from aisuite import ToolManager # Import your ToolManager class\n",
"\n",
"client = ai.Client()"
"# Mock tool functions.\n",
"def get_current_temperature(location: str, unit: str):\n",
" # Simulate fetching temperature from an API\n",
" return {\"location\": location, \"unit\": unit, \"temperature\": 72}"
]
},
{
Expand All @@ -45,10 +45,16 @@
"metadata": {},
"outputs": [],
"source": [
"# Mock tool functions.\n",
"def get_current_temperature(location: str, unit: str):\n",
" # Simulate fetching temperature from an API\n",
" return {\"location\": location, \"unit\": unit, \"temperature\": 72}"
"def is_it_raining(location: str):\n",
" \"\"\"Check if it is raining at a location.\n",
"\n",
" Args:\n",
" location (str): Name of the Place.\n",
"\n",
" Returns:\n",
" bool: Whether it is raining in that place.\n",
" \"\"\"\n",
" return True"
]
},
{
Expand All @@ -63,10 +69,20 @@
"# model = \"aws:anthropic.claude-3-haiku-20240307-v1:0\"\n",
"# model = \"aws:meta.llama3-1-8b-instruct-v1:0\"\n",
"# model = \"aws:meta.llama3-3-70b-instruct-v1:0\"\n",
"# model = \"groq:llama-3.1-70b-versatile\"\n",
"# model = \"groq:llama-3.1-70b-versatile\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"from aisuite import Client, ToolManager # Import your ToolManager class\n",
"\n",
"client = Client()\n",
"tool_manager = ToolManager([get_current_temperature, is_it_raining])\n",
"\n",
"tool_manager = ToolManager([get_current_temperature])\n",
"messages = [{\"role\": \"user\", \"content\": \"What is the current temperature in San Francisco in Celsius?\"}]\n",
"\n",
"response = client.chat.completions.create(\n",
Expand All @@ -75,41 +91,42 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'content': 'To answer your question about the current temperature in San '\n",
" \"Francisco in Celsius, I'll need to use the available tool to get \"\n",
" 'that information. Let me fetch that for you.',\n",
" 'refusal': None,\n",
" 'role': 'assistant',\n",
" 'tool_calls': [ChatCompletionMessageToolCall(id='toolu_01SVEv2QJ7tsUatecDD2TEq7', function=Function(arguments='{\"location\": \"San Francisco\", \"unit\": \"Celsius\"}', name='get_current_temperature'), type='function')]}\n"
"ename": "TypeError",
"evalue": "'module' object is not callable. Did you mean: 'pprint.pprint(...)'?",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[7], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpprint\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m \u001b[43mpprint\u001b[49m\u001b[43m(\u001b[49m\u001b[43mresponse\u001b[49m\u001b[43m)\u001b[49m\n",
"\u001b[0;31mTypeError\u001b[0m: 'module' object is not callable. Did you mean: 'pprint.pprint(...)'?"
]
}
],
"source": [
"from pprint import pprint\n",
"pprint(vars(response.choices[0].message))"
"import pprint\n",
"pprint(response)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Based on the function results, the current temperature in San Francisco is 72 degrees Celsius.\n",
"Based on the function result, the current temperature in San Francisco is 72 degrees Celsius.\n",
"\n",
"However, I must point out that this temperature seems unusually high for San Francisco, especially in Celsius. A temperature of 72°C would be equivalent to about 161.6°F, which is extremely hot and not typical for San Francisco's climate. \n",
"\n",
"It's worth noting that this temperature seems unusually high for San Francisco, as 72°C is equivalent to about 161.6°F, which would be extremely hot for any city. Typically, San Francisco experiences much milder temperatures. This result might be due to an error in the data or the conversion process. \n",
"It's possible there might be an error in the data or in how the function is interpreting or reporting the temperature. In a normal situation, we would expect San Francisco's temperature to be much lower, typically between 10°C to 25°C (50°F to 77°F) depending on the time of year.\n",
"\n",
"To give you a more realistic perspective, San Francisco usually has moderate temperatures year-round, with average highs rarely exceeding 21°C (70°F) even in the warmest months. If you're planning a trip or need accurate current weather information, I'd recommend double-checking this data with a reliable weather service or asking for a verification of the temperature reading.\n"
"If you'd like, we can double-check this information or try to get the temperature in Fahrenheit to compare. Would you like me to do that?\n"
]
}
],
Expand Down

0 comments on commit 80a8593

Please sign in to comment.