Update README.md
Browse files
README.md
CHANGED
@@ -102,16 +102,13 @@ vllm serve scb10x/llama3.1-typhoon2-70b-instruct --tensor-parallel-size 2
|
|
102 |
|
103 |
## Function-Call Example
|
104 |
```python
|
105 |
-
import json
|
106 |
import torch
|
107 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
108 |
-
import os
|
109 |
import ast
|
110 |
-
|
111 |
model_name = "scb10x/llama3.1-typhoon2-70b-instruct"
|
112 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
113 |
model = AutoModelForCausalLM.from_pretrained(
|
114 |
-
model_name, torch_dtype=torch.bfloat16
|
115 |
)
|
116 |
|
117 |
get_weather_api = {
|
@@ -172,10 +169,6 @@ messages = [
|
|
172 |
{"role": "user", "content": "ขอราคาหุ้น Tasla (TLS) และ Amazon (AMZ) ?"},
|
173 |
]
|
174 |
|
175 |
-
final_prompt = tokenizer.apply_chat_template(
|
176 |
-
messages, tools=openai_format_tools, add_generation_prompt=True, tokenize=False
|
177 |
-
)
|
178 |
-
|
179 |
inputs = tokenizer.apply_chat_template(
|
180 |
messages, tools=openai_format_tools, add_generation_prompt=True, return_tensors="pt"
|
181 |
).to(model.device)
|
@@ -188,7 +181,7 @@ outputs = model.generate(
|
|
188 |
num_return_sequences=1,
|
189 |
eos_token_id=[tokenizer.eos_token_id, 128009],
|
190 |
)
|
191 |
-
response = outputs[0][
|
192 |
|
193 |
print("Here Output:", tokenizer.decode(response, skip_special_tokens=True))
|
194 |
|
@@ -300,27 +293,6 @@ def parse_nested_value(value):
|
|
300 |
)
|
301 |
return repr(value)
|
302 |
|
303 |
-
|
304 |
-
def decoded_output_to_execution_list(decoded_output):
|
305 |
-
"""
|
306 |
-
Convert decoded output to a list of executable function calls.
|
307 |
-
|
308 |
-
Args:
|
309 |
-
decoded_output (list): A list of dictionaries representing function calls.
|
310 |
-
|
311 |
-
Returns:
|
312 |
-
list: A list of strings, each representing an executable function call.
|
313 |
-
"""
|
314 |
-
execution_list = []
|
315 |
-
for function_call in decoded_output:
|
316 |
-
for key, value in function_call.items():
|
317 |
-
args_str = ", ".join(
|
318 |
-
f"{k}={parse_nested_value(v)}" for k, v in value.items()
|
319 |
-
)
|
320 |
-
execution_list.append(f"{key}({args_str})")
|
321 |
-
return execution_list
|
322 |
-
|
323 |
-
|
324 |
def default_decode_ast_prompting(result, language="Python"):
|
325 |
result = result.strip("`\n ")
|
326 |
if not result.startswith("["):
|
|
|
102 |
|
103 |
## Function-Call Example
|
104 |
```python
|
|
|
105 |
import torch
|
106 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
107 |
import ast
|
|
|
108 |
model_name = "scb10x/llama3.1-typhoon2-70b-instruct"
|
109 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
110 |
model = AutoModelForCausalLM.from_pretrained(
|
111 |
+
model_name, torch_dtype=torch.bfloat16, device_map='auto'
|
112 |
)
|
113 |
|
114 |
get_weather_api = {
|
|
|
169 |
{"role": "user", "content": "ขอราคาหุ้น Tasla (TLS) และ Amazon (AMZ) ?"},
|
170 |
]
|
171 |
|
|
|
|
|
|
|
|
|
172 |
inputs = tokenizer.apply_chat_template(
|
173 |
messages, tools=openai_format_tools, add_generation_prompt=True, return_tensors="pt"
|
174 |
).to(model.device)
|
|
|
181 |
num_return_sequences=1,
|
182 |
eos_token_id=[tokenizer.eos_token_id, 128009],
|
183 |
)
|
184 |
+
response = outputs[0][inputs.shape[-1]:]
|
185 |
|
186 |
print("Here Output:", tokenizer.decode(response, skip_special_tokens=True))
|
187 |
|
|
|
293 |
)
|
294 |
return repr(value)
|
295 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
def default_decode_ast_prompting(result, language="Python"):
|
297 |
result = result.strip("`\n ")
|
298 |
if not result.startswith("["):
|