Update README.md
Browse files
README.md
CHANGED
|
@@ -50,17 +50,20 @@ import json
|
|
| 50 |
from typing import Any, Dict, List
|
| 51 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 52 |
|
|
|
|
| 53 |
model_name = "katanemo/Arch-Agent-3B"
|
|
|
|
| 54 |
model = AutoModelForCausalLM.from_pretrained(
|
| 55 |
model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
|
| 56 |
)
|
| 57 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 58 |
|
| 59 |
-
|
|
|
|
| 60 |
TASK_PROMPT = (
|
| 61 |
"You are a helpful assistant designed to assist with the user query by making one or more function calls if needed."
|
| 62 |
"\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\n"
|
| 63 |
-
"You are provided with function signatures within <tools></tools> XML tags:\n<tools
|
| 64 |
"\n</tools>\n\nFor each function call, return a json object with function name and arguments within "
|
| 65 |
"""<tool_call></tool_call> XML tags:\n<tool_call>\n{{"name": <function-name>, """
|
| 66 |
""""arguments": <args-json-object>}}\n</tool_call>"""
|
|
@@ -108,12 +111,12 @@ messages = [
|
|
| 108 |
{"role": "user", "content": "What is the weather in Seattle?"},
|
| 109 |
]
|
| 110 |
|
|
|
|
| 111 |
model_inputs = tokenizer.apply_chat_template(
|
| 112 |
-
messages, add_generation_prompt=True, return_tensors="pt"
|
| 113 |
).to(model.device)
|
| 114 |
|
| 115 |
generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
|
| 116 |
-
|
| 117 |
generated_ids = [
|
| 118 |
output_ids[len(input_ids) :]
|
| 119 |
for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
|
|
|
| 50 |
from typing import Any, Dict, List
|
| 51 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 52 |
|
| 53 |
+
# Specify the desired model name here
|
| 54 |
model_name = "katanemo/Arch-Agent-3B"
|
| 55 |
+
|
| 56 |
model = AutoModelForCausalLM.from_pretrained(
|
| 57 |
model_name, device_map="auto", torch_dtype="auto", trust_remote_code=True
|
| 58 |
)
|
| 59 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 60 |
|
| 61 |
+
|
| 62 |
+
# Please use the recommended prompt for each model.
|
| 63 |
TASK_PROMPT = (
|
| 64 |
"You are a helpful assistant designed to assist with the user query by making one or more function calls if needed."
|
| 65 |
"\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\n"
|
| 66 |
+
"You are provided with function signatures within <tools></tools> XML tags:\n<tools>\n{tool_text}"
|
| 67 |
"\n</tools>\n\nFor each function call, return a json object with function name and arguments within "
|
| 68 |
"""<tool_call></tool_call> XML tags:\n<tool_call>\n{{"name": <function-name>, """
|
| 69 |
""""arguments": <args-json-object>}}\n</tool_call>"""
|
|
|
|
| 111 |
{"role": "user", "content": "What is the weather in Seattle?"},
|
| 112 |
]
|
| 113 |
|
| 114 |
+
#### 2.2.3 Run inference
|
| 115 |
model_inputs = tokenizer.apply_chat_template(
|
| 116 |
+
messages, add_generation_prompt=True, return_tensors="pt", return_dict=True
|
| 117 |
).to(model.device)
|
| 118 |
|
| 119 |
generated_ids = model.generate(**model_inputs, max_new_tokens=32768)
|
|
|
|
| 120 |
generated_ids = [
|
| 121 |
output_ids[len(input_ids) :]
|
| 122 |
for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|