Text Generation
Transformers
Safetensors
English
gemma
text-generation-inference
unsloth
trl
sft
conversational
Instructions to use hiieu/vi-gemma-1.1-2b-it-function-calling with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use hiieu/vi-gemma-1.1-2b-it-function-calling with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="hiieu/vi-gemma-1.1-2b-it-function-calling") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("hiieu/vi-gemma-1.1-2b-it-function-calling") model = AutoModelForCausalLM.from_pretrained("hiieu/vi-gemma-1.1-2b-it-function-calling", device_map="auto") 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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use hiieu/vi-gemma-1.1-2b-it-function-calling with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "hiieu/vi-gemma-1.1-2b-it-function-calling" # 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/vi-gemma-1.1-2b-it-function-calling", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/hiieu/vi-gemma-1.1-2b-it-function-calling
- SGLang
How to use hiieu/vi-gemma-1.1-2b-it-function-calling 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/vi-gemma-1.1-2b-it-function-calling" \ --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/vi-gemma-1.1-2b-it-function-calling", "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/vi-gemma-1.1-2b-it-function-calling" \ --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/vi-gemma-1.1-2b-it-function-calling", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Desktop
- Docker Model Runner
How to use hiieu/vi-gemma-1.1-2b-it-function-calling with Docker Model Runner:
docker model run hf.co/hiieu/vi-gemma-1.1-2b-it-function-calling
Update README.md
Browse files
README.md
CHANGED
|
@@ -12,6 +12,57 @@ tags:
|
|
| 12 |
- sft
|
| 13 |
---
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
# Uploaded model
|
| 16 |
|
| 17 |
- **Developed by:** hiieu
|
|
|
|
| 12 |
- sft
|
| 13 |
---
|
| 14 |
|
| 15 |
+
functions_metadata = [
|
| 16 |
+
{
|
| 17 |
+
"type": "function",
|
| 18 |
+
"function": {
|
| 19 |
+
"name": "get_temperature",
|
| 20 |
+
"description": "get temperature of a city",
|
| 21 |
+
"parameters": {
|
| 22 |
+
"type": "object",
|
| 23 |
+
"properties": {
|
| 24 |
+
"city": {
|
| 25 |
+
"type": "string",
|
| 26 |
+
"description": "name"
|
| 27 |
+
}
|
| 28 |
+
},
|
| 29 |
+
"required": [
|
| 30 |
+
"city"
|
| 31 |
+
]
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
]
|
| 36 |
+
|
| 37 |
+
```python
|
| 38 |
+
messages = [
|
| 39 |
+
{ "role": "user", "content": f"""Bạn là một trợ lý hữu ích có quyền truy cập vào các chức năng sau. Sử dụng chúng nếu cần -\n{str(functions_metadata)}"""},
|
| 40 |
+
{ "role": "user", "content": "What is the temperature in Tokyo right now?"},
|
| 41 |
+
# You will get the previous prediction, extract it will the tag <functioncall>
|
| 42 |
+
# execute the function and append it to the messages like below:
|
| 43 |
+
{ "role": "assistant", "content": """<functioncall> {"name": "get_temperature", "arguments": '{"city": "Tokyo"}'} </functioncall>"""},
|
| 44 |
+
{ "role": "user", "content": """<function_response> {"temperature":30 C} </function_response>"""}
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
input_ids = tokenizer.apply_chat_template(
|
| 48 |
+
messages,
|
| 49 |
+
add_generation_prompt=True,
|
| 50 |
+
return_tensors="pt"
|
| 51 |
+
).to(model.device)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
outputs = model.generate(
|
| 55 |
+
input_ids,
|
| 56 |
+
max_new_tokens=256,
|
| 57 |
+
do_sample=True,
|
| 58 |
+
temperature=0.6,
|
| 59 |
+
top_p=0.9,
|
| 60 |
+
)
|
| 61 |
+
response = outputs[0][input_ids.shape[-1]:]
|
| 62 |
+
print(tokenizer.decode(response, skip_special_tokens=True))
|
| 63 |
+
# >> The current temperature in Tokyo is 30 degrees Celsius.
|
| 64 |
+
```
|
| 65 |
+
|
| 66 |
# Uploaded model
|
| 67 |
|
| 68 |
- **Developed by:** hiieu
|