Created
May 5, 2025 05:56
-
-
Save zainhas/d5b4c54e73df1d6424e0ec5fdf09ed7c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import together | |
client = together.Together() | |
#tools | |
book_travel_tickets = { | |
"type": "function", | |
"function": { | |
"name": "book_travel_tickets", | |
"description": "Books travel tickets for the user", | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"destination": { | |
"type": "string", | |
"description": "The destination of the travel" | |
}, | |
"travel_dates": { | |
"type": "string", | |
"description": "The dates of travel" | |
}, | |
"number_of_passengers": { | |
"type": "integer", | |
"description": "The number of passengers" | |
}, | |
"travel_class": { | |
"type": "string", | |
"description": "The preferred travel class (e.g., economy, business)" | |
} | |
}, | |
"required": ["destination", "travel_dates", "number_of_passengers"] | |
} | |
} | |
} | |
check_weather = { | |
"type": "function", | |
"function": { | |
"name": "check_weather", | |
"description": "Checks the current weather for a specified location", | |
"parameters": { | |
"type": "object", | |
"properties": { | |
"location": { | |
"type": "string", | |
"description": "The location to check the weather for" | |
} | |
}, | |
"required": ["location"] | |
} | |
} | |
} | |
tools = [book_travel_tickets, check_weather] | |
#tool call | |
messages = [ | |
{ | |
"role": "system", | |
"content": "You are a helpful assistant that can access external functions. The responses from these function calls will be appended to this dialogue. Please provide responses based on the information from these function calls." | |
}, | |
{ | |
"role": "user", | |
"content": [ | |
{ | |
"type": "image_url", | |
"image_url": { | |
"url": "https://huggingface.co/datasets/patrickvonplaten/random_img/resolve/main/yosemite.png" | |
} | |
}, | |
{ | |
"type": "text", | |
"text": "Book me tickets to go the place shown in this photo." | |
} | |
] | |
} | |
] | |
response = client.chat.completions.create( | |
model="meta-llama/Llama-4-Maverick-17B-128E-Instruct-FP8", | |
messages=messages, | |
tools=tools, | |
tool_choice="auto", | |
) | |
print(json.dumps(response.choices[0].message.model_dump()['tool_calls'], indent=2)) | |
#[ | |
# { | |
# "id": "call_y5sawjer1nid1rchvhmmhrm1", | |
# "type": "function", | |
# "function": { | |
# "name": "book_travel_tickets", | |
# "arguments": "{\"destination\":\"Paris\",\"number_of_passengers\":1,\"travel_dates\":\"2021-01-01 to 2021-01-07\"}" | |
# }, | |
# "index": 0 | |
# } | |
#] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment