Views
No views yet
1prompt = """<|user|>
2You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions.Here are the available tools:<tools> [{'type': 'function', 'function': {'name': 'convert_currency', 'description': 'Convert from one currency to another', 'parameters': {'type': 'object', 'properties': {'amount': {'type': 'number', 'description': 'The amount to convert'}, 'from_currency': {'type': 'string', 'description': 'The currency to convert from'}, 'to_currency': {'type': 'string', 'description': 'The currency to convert to'}}, 'required': ['amount', 'from_currency', 'to_currency']}}}, {'type': 'function', 'function': {'name': 'calculate_distance', 'description': 'Calculate the distance between two locations', 'parameters': {'type': 'object', 'properties': {'start_location': {'type': 'string', 'description': 'The starting location'}, 'end_location': {'type': 'string', 'description': 'The ending location'}}, 'required': ['start_location', 'end_location']}}}] </tools>Use the following pydantic model json schema for each tool call you will make: {'title': 'FunctionCall', 'type': 'object', 'properties': {'arguments': {'title': 'Arguments', 'type': 'object'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['arguments', 'name']}For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
3<tool_call>
4{tool_call}
5</tool_call>Also, before making a call to a function take the time to plan the function to take. Make that thinking process between <think>{your thoughts}</think>
6
7Hi, I need to convert 500 USD to Euros. Can you help me with that?<|end|>
8<|assistant|>
9<think>"""
10
11eos_token_id = tokenizer.encode('<|endoftext|>')[0]
12
13inputs = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
14inputs = {k: v.to("cuda") for k,v in inputs.items()}
15outputs = model.generate(**inputs,
16 max_new_tokens=300,# Adapt as necessary
17 do_sample=True,
18 top_p=0.95,
19 temperature=0.01,
20 repetition_penalty=1.0,
21 eos_token_id=eos_token_id)
22
23print(tokenizer.decode(outputs[0]))1<|user|> You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags.You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions.Here are the available tools:<tools> [{'type': 'function', 'function': {'name': 'convert_currency', 'description': 'Convert from one currency to another', 'parameters': {'type': 'object', 'properties': {'amount': {'type': 'number', 'description': 'The amount to convert'}, 'from_currency': {'type': 'string', 'description': 'The currency to convert from'}, 'to_currency': {'type': 'string', 'description': 'The currency to convert to'}}, 'required': ['amount', 'from_currency', 'to_currency']}}}, {'type': 'function', 'function': {'name': 'calculate_distance', 'description': 'Calculate the distance between two locations', 'parameters': {'type': 'object', 'properties': {'start_location': {'type': 'string', 'description': 'The starting location'}, 'end_location': {'type': 'string', 'description': 'The ending location'}}, 'required': ['start_location', 'end_location']}}}] </tools> Use the following pydantic model json schema for each tool call you will make: {'title': 'FunctionCall', 'type': 'object', 'properties': {'arguments': {'title': 'Arguments', 'type': 'object'}, 'name': {'title': 'Name', 'type': 'string'}}, 'required': ['arguments', 'name']}For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:
2<tool_call>
3{tool_call}
4</tool_call> Also, before making a call to a function take the time to plan the function to take. Make that thinking process between <think> {your thoughts}</think>
5
6Hi, I need to convert 500 USD to Euros. Can you help me with that?<|end|><|assistant|><think> Okay, so the user is asking to convert 500 USD to Euros. I need to figure out which function to use. Looking at the available tools, there's a function called convert_currency that does exactly that. It requires the amount, the currency to convert from, and the currency to convert to. The user provided all these details: 500 USD to Euros. So, I'll call the convert_currency function with those parameters.
7
8I should make sure to format the function call correctly, using the specified JSON schema. The function name is 'convert_currency', and the arguments are amount: 500, from_currency: 'USD', and to_currency: 'EUR'. That should do it.
9
10Alright, I think that's all I need to do here. The user's request is straightforward, and the function is perfectly suited for this task.
11<|tool|><|tool|>
12{'name': 'convert_currency', 'arguments': {'amount': 500, 'from_currency': 'USD', 'to_currency': 'EUR'}}
13<|tool|><|end|><|tool|>
14<tool_response>
15{'converted_amount': 425.5, 'from_currency': 'USD', 'to_currency': 'EUR'}
16</tool_response><|end|><|assistant|> Sure, 500 USD is approximately 425.50 Euros.<|end|>1@misc{vonwerra2022trl,
2 title = {{TRL: Transformer Reinforcement Learning}},
3 author = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallouédec},
4 year = 2020,
5 journal = {GitHub repository},
6 publisher = {GitHub},
7 howpublished = {\url{https://github.com/huggingface/trl}}
8}