Instructions to use wannaphong/plaifon-3b-chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use wannaphong/plaifon-3b-chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="wannaphong/plaifon-3b-chat") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("wannaphong/plaifon-3b-chat") model = AutoModelForCausalLM.from_pretrained("wannaphong/plaifon-3b-chat", 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=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use wannaphong/plaifon-3b-chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "wannaphong/plaifon-3b-chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "wannaphong/plaifon-3b-chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/wannaphong/plaifon-3b-chat
- SGLang
How to use wannaphong/plaifon-3b-chat 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 "wannaphong/plaifon-3b-chat" \ --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": "wannaphong/plaifon-3b-chat", "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 "wannaphong/plaifon-3b-chat" \ --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": "wannaphong/plaifon-3b-chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use wannaphong/plaifon-3b-chat with Docker Model Runner:
docker model run hf.co/wannaphong/plaifon-3b-chat
PlaiFon 3B Chat
English-Thai small lm
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
from transformers import pipeline
model_id="wannaphong/plaifon-3b-chat"
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="cuda",
)
tokenizer = AutoTokenizer.from_pretrained(model_id,use_fast=False)
pipe=pipeline("text-generation",model=model,tokenizer=tokenizer)
Chat
q="แมวคืออะไร"
chat = [
{"role": "user", "content": q}
]
response = pipe(chat, max_new_tokens=4096)
print(response[0]["generated_text"][-1]["content"])
Output:
แมว (Cat) เป็นสัตว์เลี้ยงลูกด้วยนมในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือและสิงโต แมวเป็นสัตว์ที่มีขนปกคลุมร่างกาย มีหูที่สามารถปรับทิศทางได้ มีตาที่สามารถมองเห็นในที่มืดได้ดี และมีเล็บที่สามารถปรับเปลี่ยนรูปทรงได้ตามความเหมาะสมในการจับเหยื่อหรือปีนป่าย
แมวเป็นสัตว์ที่มีความฉลาดและสามารถเรียนรู้ได้เร็ว แมวสามารถจดจำเจ้าของได้และมีความผูกพันกับเจ้าของอย่างลึกซึ้ง แมวเป็นสัตว์ที่มีความเป็นอิสระสูงและมักจะใช้เวลาส่วนใหญ่ในการนอนหลับหรือเล่นกับของเล่น
แมวเป็นสัตว์ที่มีความสำคัญต่อมนุษย์ในหลายด้าน เช่น เป็นสัตว์เลี้ยงที่ช่วยควบคุมประชากรหนูและสัตว์อื่นๆ ที่เป็นศัตรูพืช และยังเป็นสัตว์ที่มีความสวยงามและน่ารัก ทำให้เป็นที่นิยมในการเลี้ยงเป็นสัตว์เลี้ยงในบ้าน
แมวมีหลายสายพันธุ์ เช่น แมวไทย แมวเปอร์เซีย แมวอเมริกันช็อตแฮร์ แมวเบงกอล และแมวสกอตติชโฟลด์ เป็นต้น แต่ละสายพันธุ์มีลักษณะและพฤติกรรมที่แตกต่างกันไป ทำให้การเลี้ยงแมวเป็นเรื่องที่ต้องใช้ความรักและความเอาใจใส่ในการดูแลอย่างเหมาะสม
Thinking:
chat = [
{"role": "user", "content": "แมวคืออะไร"}
]
text = tokenizer.apply_chat_template(
chat,
tokenize=False,
add_generation_prompt=True,
# tools=tool,
enable_thinking=True # Switches between thinking and non-thinking modes. Default is True.
)#.strip()+"\n<think>"
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=4096
)
index=0
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=False).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=False).strip("\n")
# print("thinking content:", thinking_content)
print("content:", content)
Output:
ได้เลย ผู้ใช้ถามว่า "แมวคืออะไร" ซึ่งแปลว่า "แมวคืออะไร" ในภาษาไทย ฉันต้องอธิบายว่าแมวคือสัตว์เลี้ยงลูกด้วยนมที่เป็นสัตว์เลี้ยงลูกด้วยนมที่มีขน อยู่ในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือและสิงโต แมวมีลักษณะเด่นคือมีหูที่แหลมคม ดวงตาที่ใหญ่ และเล็บที่แหลมคม พวกมันมีความฉลาดและสามารถฝึกฝนได้ แมวมีหลายสายพันธุ์ เช่น แมวบ้าน แมวป่า และแมวป่า แมวมีบทบาทสำคัญในวัฒนธรรมและเป็นสัตว์เลี้ยงที่นิยมมาก ฉันควรระบุว่าแมวเป็นสัตว์ที่มีความเป็นอิสระและมีพฤติกรรมที่น่าสนใจ อาจเพิ่มข้อมูลเกี่ยวกับการดูแลแมวและการเลี้ยงแมวเพื่อให้ครอบคลุมทุกแง่มุม ฉันต้องแน่ใจว่าคำตอบชัดเจนและครอบคลุมประเด็นหลักโดยไม่ใช้คำศัพท์ทางเทคนิคที่ซับซ้อนเกินไป ตรวจสอบว่ามีข้อมูลใดที่ขาดหายไปหรือไม่ เช่น บทบาทของแมวในวัฒนธรรม หรือความแตกต่างระหว่างแมวบ้านกับแมวป่า ดีแล้ว นี่ควรจะครอบคลุมทุกอย่างที่จำเป็นแล้ว
</think>
แมว (Cat) คือสัตว์เลี้ยงลูกด้วยนมที่มีขน อยู่ในวงศ์ Felidae ซึ่งเป็นวงศ์เดียวกับเสือ สิงโต และแมวป่า แมวมีลักษณะเด่นคือมีหูที่แหลมคม ดวงตาที่ใหญ่ และเล็บที่แหลมคม พวกมันมีความฉลาด สามารถฝึกฝนได้ และมีพฤติกรรมที่น่าสนใจ เช่น การเล่น การนอนหลับ และการล่าสัตว์ แมวมีหลายสายพันธุ์ เช่น แมวบ้าน (Domestic Cat) ที่เลี้ยงเป็นสัตว์เลี้ยง แมวป่า (Wild Cat) ที่อาศัยอยู่ในธรรมชาติ และแมวป่า (Feral Cat) ที่อาศัยอยู่ในพื้นที่ที่ไม่มีมนุษย์ดูแล แมวมีบทบาทสำคัญในวัฒนธรรมและเป็นสัตว์เลี้ยงที่นิยมมากทั่วโลก แมวมักถูกเลี้ยงเป็นสัตว์เลี้ยงในบ้าน แต่ก็มีบางสายพันธุ์ที่ถูกเลี้ยงในป่าหรือที่อยู่อาศัยของมนุษย์ แมวมีความเป็นอิสระและมีความสัมพันธ์ที่ดีกับมนุษย์ แต่ก็มีพฤติกรรมที่ต้องการการดูแลและฝึกฝนอย่างเหมาะสมเพื่อให้พวกมันมีสุขภาพดีและมีความสุขในชีวิตประจำวัน<|im_end|>
Tool
tool=[
{
"type": "function",
"function": {
"name": "get_current_temperature",
"description": "Get current temperature at a location.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get the temperature for, in the format \"City, State, Country\"."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "The unit to return the temperature in. Defaults to \"celsius\"."
}
},
"required": [
"location"
]
}
}
},
{
"type": "function",
"function": {
"name": "get_temperature_date",
"description": "Get temperature at a location and date.",
"parameters": {
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The location to get the temperature for, in the format \"City, State, Country\"."
},
"date": {
"type": "string",
"description": "The date to get the temperature for, in the format \"Year-Month-Day\"."
},
"unit": {
"type": "string",
"enum": [
"celsius",
"fahrenheit"
],
"description": "The unit to return the temperature in. Defaults to \"celsius\"."
}
},
"required": [
"location",
"date"
]
}
}
}
]
chat = [
{"role": "user", "content": "อุณหภูมิที่กรุงเทพเป็นเท่าไร"}
]
text = tokenizer.apply_chat_template(
chat,
tokenize=False,
add_generation_prompt=True,
tools=tool,
enable_thinking=False # Switches between thinking and non-thinking modes. Default is True.
).strip()
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
# conduct text completion
generated_ids = model.generate(
**model_inputs,
max_new_tokens=4096
)
index=0
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
# thinking_content = tokenizer.decode(output_ids[:index], skip_special_tokens=False).strip("\n")
content = tokenizer.decode(output_ids[index:], skip_special_tokens=False).strip("\n")
# print("thinking content:", thinking_content)
print("content:", content)
Output:
content: <tool_call>
{"name": "get_current_temperature", "arguments": "{\"location\": \"กรุงเทพ\", \"unit\": \"celsius\"}"}
</tool_call><|im_end|>
- Downloads last month
- -
Model tree for wannaphong/plaifon-3b-chat
Base model
Qwen/Qwen2.5-7B