mzbac/function-calling-llama-3-format-v1.1
Viewer β’ Updated β’ 112k β’ 77 β’ 29
How to use mzbac/llama-3-8B-Instruct-function-calling-v0.2 with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="mzbac/llama-3-8B-Instruct-function-calling-v0.2")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("mzbac/llama-3-8B-Instruct-function-calling-v0.2")
model = AutoModelForCausalLM.from_pretrained("mzbac/llama-3-8B-Instruct-function-calling-v0.2")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use mzbac/llama-3-8B-Instruct-function-calling-v0.2 with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "mzbac/llama-3-8B-Instruct-function-calling-v0.2"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "mzbac/llama-3-8B-Instruct-function-calling-v0.2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/mzbac/llama-3-8B-Instruct-function-calling-v0.2
How to use mzbac/llama-3-8B-Instruct-function-calling-v0.2 with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "mzbac/llama-3-8B-Instruct-function-calling-v0.2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "mzbac/llama-3-8B-Instruct-function-calling-v0.2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "mzbac/llama-3-8B-Instruct-function-calling-v0.2" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "mzbac/llama-3-8B-Instruct-function-calling-v0.2",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use mzbac/llama-3-8B-Instruct-function-calling-v0.2 with Docker Model Runner:
docker model run hf.co/mzbac/llama-3-8B-Instruct-function-calling-v0.2
This model has been fine-tuned based on Meta-Llama/Meta-Llama-3-8B-Instruct using the mlx-lm with a cleaned-up function calling dataset that removed invalid JSON data and single quotes around argument values.
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
model_id = "mzbac/llama-3-8B-Instruct-function-calling-v0.2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto",
)
tool = {
"name": "search_web",
"description": "Perform a web search for a given search terms.",
"parameter": {
"type": "object",
"properties": {
"search_terms": {
"type": "array",
"items": {"type": "string"},
"description": "The search queries for which the search is performed.",
"required": True,
}
}
},
}
messages = [
{
"role": "system",
"content": f"You are a helpful assistant with access to the following functions. Use them if required - {str(tool)}",
},
{"role": "user", "content": "Today's news in Melbourne, just for your information, today is April 27, 2014."},
]
input_ids = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
return_tensors="pt"
).to(model.device)
terminators = [
tokenizer.eos_token_id,
tokenizer.convert_tokens_to_ids("<|eot_id|>")
]
outputs = model.generate(
input_ids,
max_new_tokens=256,
eos_token_id=terminators,
do_sample=True,
temperature=0.1,
)
response = outputs[0]
print(tokenizer.decode(response))
# <|begin_of_text|><|start_header_id|>system<|end_header_id|>
# You are a helpful assistant with access to the following functions. Use them if required - {'name':'search_web', 'description': 'Perform a web search for a given search terms.', 'parameter': {'type': 'object', 'properties': {'search_terms': {'type': 'array', 'items': {'type':'string'}, 'description': 'The search queries for which the search is performed.','required': True}}}}<|eot_id|><|start_header_id|>user<|end_header_id|>
# Today's news in Melbourne, just for your information, today is April 27, 2014.<|eot_id|><|start_header_id|>assistant<|end_header_id|>
# <functioncall> {"name": "search_web", "arguments": {"search_terms": ["Melbourne news", "April 27, 2014"]}}<|eot_id|>