update README
Browse files- README.md +100 -1
- config.json +1 -1
README.md
CHANGED
|
@@ -4,4 +4,103 @@ language:
|
|
| 4 |
- en
|
| 5 |
base_model:
|
| 6 |
- codellama/CodeLlama-7b-hf
|
| 7 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
- en
|
| 5 |
base_model:
|
| 6 |
- codellama/CodeLlama-7b-hf
|
| 7 |
+
---
|
| 8 |
+
# **TL-CodeLLaMA-2**
|
| 9 |
+
|
| 10 |
+
TL-CodeLLaMA-2 is a model designed for tool use, built upon CodeLLaMA-7b. It is trained on 1,217 data samples using the *TL-Training* framework and demonstrates effective performance across a variety of tool use tasks. More information can be found in the paper "[TL-Training: A Task-Feature-Based Framework for Training Large Language Models in Tool Use](https://www.arxiv.org/abs/2412.15495)".
|
| 11 |
+
|
| 12 |
+
# Model Use
|
| 13 |
+
|
| 14 |
+
## Requirements
|
| 15 |
+
|
| 16 |
+
To use this model, please make sure to install transformers:
|
| 17 |
+
```bash
|
| 18 |
+
pip install transformers
|
| 19 |
+
```
|
| 20 |
+
|
| 21 |
+
## Data Orgnization
|
| 22 |
+
|
| 23 |
+
The data needs to be organized in the following format:
|
| 24 |
+
|
| 25 |
+
```json
|
| 26 |
+
[
|
| 27 |
+
{
|
| 28 |
+
"role": "System",
|
| 29 |
+
"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"
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"role": "User",
|
| 33 |
+
"content": "Could you give me some advice about 'love'?"
|
| 34 |
+
},
|
| 35 |
+
{
|
| 36 |
+
"role": "Assistant",
|
| 37 |
+
"content": "search_advice(query = 'love') "
|
| 38 |
+
},
|
| 39 |
+
{
|
| 40 |
+
"role": "Output",
|
| 41 |
+
"content": "..."
|
| 42 |
+
}
|
| 43 |
+
]
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
## Chat Template
|
| 47 |
+
|
| 48 |
+
The chat template is:
|
| 49 |
+
|
| 50 |
+
```jinja
|
| 51 |
+
{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '\nAssistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '\n' }}{% endif %}{% endfor %}
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
## Inference
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 58 |
+
|
| 59 |
+
model_path = "Junjie-Ye/TL-CodeLLaMA-2"
|
| 60 |
+
|
| 61 |
+
data = [
|
| 62 |
+
{
|
| 63 |
+
"role": "System",
|
| 64 |
+
"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"
|
| 65 |
+
},
|
| 66 |
+
{
|
| 67 |
+
"role": "User",
|
| 68 |
+
"content": "Could you give me some advice about 'love'?"
|
| 69 |
+
}
|
| 70 |
+
]
|
| 71 |
+
|
| 72 |
+
chat_template = "{% for message in messages %}{{message['role'] + ': ' + message['content']}}{% if loop.last %}{% if add_generation_prompt %}{{ '\nAssistant:' }}{% else %}{{ '</s>'}}{% endif %}{% else %}{{ '\n' }}{% endif %}{% endfor %}"
|
| 73 |
+
|
| 74 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 75 |
+
model_path,
|
| 76 |
+
torch_dtype="auto",
|
| 77 |
+
device_map="auto",
|
| 78 |
+
trust_remote_code=True
|
| 79 |
+
).eval()
|
| 80 |
+
|
| 81 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path,
|
| 82 |
+
padding_side="left",
|
| 83 |
+
trust_remote_code=True)
|
| 84 |
+
if tokenizer.pad_token_id is None:
|
| 85 |
+
tokenizer.pad_token_id = tokenizer.eos_token_id
|
| 86 |
+
|
| 87 |
+
text = tokenizer.apply_chat_template(
|
| 88 |
+
data,
|
| 89 |
+
tokenize=False,
|
| 90 |
+
chat_template=chat_template,
|
| 91 |
+
add_generation_prompt=add_generation_prompt
|
| 92 |
+
)
|
| 93 |
+
model_inputs = tokenizer(
|
| 94 |
+
[text], return_tensors="pt", padding=True).to("cuda")
|
| 95 |
+
|
| 96 |
+
generated_ids = model.generate(
|
| 97 |
+
max_new_tokens=1024,
|
| 98 |
+
**model_inputs,
|
| 99 |
+
)
|
| 100 |
+
generated_ids = [
|
| 101 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 102 |
+
]
|
| 103 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
|
| 104 |
+
|
| 105 |
+
print(response)
|
| 106 |
+
```
|
config.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
{
|
| 2 |
-
"_name_or_path": "/
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|
|
|
|
| 1 |
{
|
| 2 |
+
"_name_or_path": "codellama/CodeLlama-7b-hf",
|
| 3 |
"architectures": [
|
| 4 |
"LlamaForCausalLM"
|
| 5 |
],
|