Views
No views yet
pip install transformers1[
2 {
3 "role": "System",
4 "content": "Function:\ndef random_advice():\n \"\"\"\n Returns a random advice slip as a slip object.\n \"\"\"\n\nFunction:\ndef advice_by_id(slip_id:str):\n \"\"\"\n If an advice slip is found with the corresponding {slip_id}, a slip object is returned.\n\n Args:\n slip_id (string): The unique ID of this advice slip.\n \"\"\"\n\nFunction:\ndef search_advice(query:str):\n \"\"\"\n If an advice slip is found, containing the corresponding search term in {query}, an array of slip objects is returned inside a search object.\n\n Args:\n query (string): The search query provided.\n \"\"\"\n\nFunction:\ndef ask_to_user(question:str):\n \"\"\"\n You can ask user for guidance when you think you need more information to handle the task, but you should use this tool as less as you can.\n\n Args:\n question (string): The question you want to ask to user.\n \"\"\"\n\nFunction:\ndef finish(answer:str):\n \"\"\"\n Finish the task and give your answer.\n\n Args:\n answer (string): Your answer for the task.\n \"\"\"\n\n"
5 },
6 {
7 "role": "User",
8 "content": "Could you give me some advice about 'love'?"
9 },
10 {
11 "role": "Assistant",
12 "content": "search_advice(query = 'love') "
13 },
14 {
15 "role": "Output",
16 "content": "..."
17 }
18]{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '\nAssistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '\n' }}{% endif %}{% endfor %}1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3model_path = "Junjie-Ye/TL-CodeLLaMA-2"
4
5data = [
6 {
7 "role": "System",
8 "content": "Function:\ndef random_advice():\n \"\"\"\n Returns a random advice slip as a slip object.\n \"\"\"\n\nFunction:\ndef advice_by_id(slip_id:str):\n \"\"\"\n If an advice slip is found with the corresponding {slip_id}, a slip object is returned.\n\n Args:\n slip_id (string): The unique ID of this advice slip.\n \"\"\"\n\nFunction:\ndef search_advice(query:str):\n \"\"\"\n If an advice slip is found, containing the corresponding search term in {query}, an array of slip objects is returned inside a search object.\n\n Args:\n query (string): The search query provided.\n \"\"\"\n\nFunction:\ndef ask_to_user(question:str):\n \"\"\"\n You can ask user for guidance when you think you need more information to handle the task, but you should use this tool as less as you can.\n\n Args:\n question (string): The question you want to ask to user.\n \"\"\"\n\nFunction:\ndef finish(answer:str):\n \"\"\"\n Finish the task and give your answer.\n\n Args:\n answer (string): Your answer for the task.\n \"\"\"\n\n"
9 },
10 {
11 "role": "User",
12 "content": "Could you give me some advice about 'love'?"
13 }
14]
15
16chat_template = "{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '\nAssistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '\n' }}{% endif %}{% endfor %}"
17
18model = AutoModelForCausalLM.from_pretrained(
19 model_path,
20 torch_dtype="auto",
21 device_map="auto",
22 trust_remote_code=True
23).eval()
24
25tokenizer = AutoTokenizer.from_pretrained(model_path,
26 padding_side="left",
27 trust_remote_code=True)
28if tokenizer.pad_token_id is None:
29 tokenizer.pad_token_id = tokenizer.eos_token_id
30
31text = tokenizer.apply_chat_template(
32 data,
33 tokenize=False,
34 chat_template=chat_template,
35 add_generation_prompt=add_generation_prompt
36 )
37model_inputs = tokenizer(
38 [text], return_tensors="pt", padding=True).to("cuda")
39
40generated_ids = model.generate(
41 max_new_tokens=1024,
42 **model_inputs,
43)
44generated_ids = [
45 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
46]
47response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
48
49print(response)1@inproceedings{TL-Training,
2 author = {Junjie Ye and
3 Yilong Wu and
4 Sixian Li and
5 Yuming Yang and
6 Zhiheng Xi and
7 Tao Gui and
8 Qi Zhang and
9 Xuanjing Huang and
10 Peng Wang and
11 Zhongchao Shi and
12 Jianping Fan and
13 Zhengyin Du},
14 editor = {Christos Christodoulopoulos and
15 Tanmoy Chakraborty and
16 Carolyn Rose and
17 Violet Peng},
18 title = {TL-Training: {A} Task-Feature-Based Framework for Training Large Language
19 Models in Tool Use},
20 booktitle = {Findings of the Association for Computational Linguistics: {EMNLP}
21 2025, Suzhou, China, November 4-9, 2025},
22 pages = {239--258},
23 publisher = {Association for Computational Linguistics},
24 year = {2025},
25 url = {https://aclanthology.org/2025.findings-emnlp.15/},
26 timestamp = {Fri, 20 Feb 2026 08:07:46 +0100},
27 biburl = {https://dblp.org/rec/conf/emnlp/YeWLYXGZHWSFD25.bib},
28 bibsource = {dblp computer science bibliography, https://dblp.org}
29}