Text Generation
Transformers
Safetensors
English
llama
text-generation-inference
unsloth
trl
conversational
Instructions to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode") model = AutoModelForCausalLM.from_pretrained("hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode") 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]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode
- SGLang
How to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode" \ --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": "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
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 "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode" \ --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": "hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode", max_seq_length=2048, ) - Docker Model Runner
How to use hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode with Docker Model Runner:
docker model run hf.co/hiieu/Meta-Llama-3-8B-Instruct-function-calling-json-mode
Update README.md
Browse files
README.md
CHANGED
|
@@ -58,6 +58,10 @@ print(tokenizer.decode(response, skip_special_tokens=True))
|
|
| 58 |
```
|
| 59 |
|
| 60 |
### Function Calling
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
```python
|
| 62 |
functions_metadata = [
|
| 63 |
{
|
|
@@ -81,9 +85,41 @@ functions_metadata = [
|
|
| 81 |
}
|
| 82 |
]
|
| 83 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
messages = [
|
| 85 |
{ "role": "system", "content": f"""You are a helpful assistant with access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall>\n\nEdge cases you must handle:\n - If there are no functions that match the user request, you will respond politely that you cannot help."""},
|
| 86 |
{ "role": "user", "content": "What is the temperature in Tokyo right now?"},
|
|
|
|
| 87 |
{ "role": "assistant", "content": """<functioncall> {"name": "get_temperature", "arguments": '{"city": "Tokyo"}'} </functioncall>"""},
|
| 88 |
{ "role": "user", "content": """<function_response> {"temperature":30 C} </function_response>"""}
|
| 89 |
]
|
|
|
|
| 58 |
```
|
| 59 |
|
| 60 |
### Function Calling
|
| 61 |
+
Function calling requires two step inferences, below is the example:
|
| 62 |
+
|
| 63 |
+
## Step 1:
|
| 64 |
+
|
| 65 |
```python
|
| 66 |
functions_metadata = [
|
| 67 |
{
|
|
|
|
| 85 |
}
|
| 86 |
]
|
| 87 |
|
| 88 |
+
messages = [
|
| 89 |
+
{ "role": "system", "content": f"""You are a helpful assistant with access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall>\n\nEdge cases you must handle:\n - If there are no functions that match the user request, you will respond politely that you cannot help."""},
|
| 90 |
+
{ "role": "user", "content": "What is the temperature in Tokyo right now?"}
|
| 91 |
+
]
|
| 92 |
+
|
| 93 |
+
input_ids = tokenizer.apply_chat_template(
|
| 94 |
+
messages,
|
| 95 |
+
add_generation_prompt=True,
|
| 96 |
+
return_tensors="pt"
|
| 97 |
+
).to(model.device)
|
| 98 |
+
|
| 99 |
+
terminators = [
|
| 100 |
+
tokenizer.eos_token_id,
|
| 101 |
+
tokenizer.convert_tokens_to_ids("<|eot_id|>")
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
outputs = model.generate(
|
| 105 |
+
input_ids,
|
| 106 |
+
max_new_tokens=256,
|
| 107 |
+
eos_token_id=terminators,
|
| 108 |
+
do_sample=True,
|
| 109 |
+
temperature=0.6,
|
| 110 |
+
top_p=0.9,
|
| 111 |
+
)
|
| 112 |
+
response = outputs[0][input_ids.shape[-1]:]
|
| 113 |
+
print(tokenizer.decode(response, skip_special_tokens=True))
|
| 114 |
+
# >> <functioncall> {"name": "get_temperature", "arguments": '{"city": "Tokyo"}'} </functioncall>"""}
|
| 115 |
+
```
|
| 116 |
+
## Step 2:
|
| 117 |
+
|
| 118 |
+
```python
|
| 119 |
messages = [
|
| 120 |
{ "role": "system", "content": f"""You are a helpful assistant with access to the following functions: \n {str(functions_metadata)}\n\nTo use these functions respond with:\n<functioncall> {{ "name": "function_name", "arguments": {{ "arg_1": "value_1", "arg_1": "value_1", ... }} }} </functioncall>\n\nEdge cases you must handle:\n - If there are no functions that match the user request, you will respond politely that you cannot help."""},
|
| 121 |
{ "role": "user", "content": "What is the temperature in Tokyo right now?"},
|
| 122 |
+
// You will get the previous prediction, extract it will the tag <functioncall>, execute it and append it to the messages like below:
|
| 123 |
{ "role": "assistant", "content": """<functioncall> {"name": "get_temperature", "arguments": '{"city": "Tokyo"}'} </functioncall>"""},
|
| 124 |
{ "role": "user", "content": """<function_response> {"temperature":30 C} </function_response>"""}
|
| 125 |
]
|