LLM - Tools¶
Install packages
Import packages
Define Weather Tool
Define tools specification
Define messages
- System message, defined once
- User messages
Get chat completion
Call the function and append its result to messages list
[{'role': 'system', 'content': "You're a helpful weather assistant."},
{'role': 'user', 'content': "What's the weather like in Paris today?"},
Message(content=None, role='assistant', tool_calls=[ChatCompletionMessageToolCall(index=0, function=Function(arguments='{"reasoning": "I want to know the weather in Paris.", "location": "Paris"}', name='get_weather'), id='call_854f6a5249554dc3a0674da8dd2f', type='function')], function_call=None, images=[], thinking_blocks=[], provider_specific_fields=None),
{'role': 'tool',
'tool_call_id': 'call_854f6a5249554dc3a0674da8dd2f',
'content': 'The temperature in Paris is 20°C.'}]
Define output structure
Supply results and call the model again