mirror of
https://github.com/zenlm/engine.git
synced 2026-10-30 15:00:05 +00:00
* Add model * Update loader * Fix llama config usage * Docs * Fix config no_rope_layers * Fix tie_word_embeddings default * Add chat template * Embed the chat templates * Fix embedding template * enable_thinking default true * Update examples * XML tools for smollm3 * Add smollm3 docs * Fix openai examples * Clippy --------- Co-authored-by: Eric Buehler <[email protected]>
96 lines
2.5 KiB
Python
96 lines
2.5 KiB
Python
from mistralrs import Runner, Which, ChatCompletionRequest, VisionArchitecture
|
|
|
|
# Non-MoE model
|
|
runner = Runner(
|
|
which=Which.VisionPlain(
|
|
model_id="https://huggingface.co/Qwen/Qwen3-4B",
|
|
arch=VisionArchitecture.Qwen3,
|
|
),
|
|
in_situ_quant="Q4K",
|
|
)
|
|
|
|
# MoE model
|
|
# runner = Runner(
|
|
# which=Which.VisionPlain(
|
|
# model_id="https://huggingface.co/Qwen/Qwen3-30B-A3B",
|
|
# arch=VisionArchitecture.Qwen3Moe,
|
|
# ),
|
|
# in_situ_quant="Q4K",
|
|
# )
|
|
|
|
messages = [
|
|
{
|
|
"role": "user",
|
|
"content": "Hello! How many rs in strawberry?",
|
|
},
|
|
]
|
|
|
|
# ------------------------------------------------------------------
|
|
# First question, thinking mode is enabled by default
|
|
# ------------------------------------------------------------------
|
|
completion = runner.send_chat_completion_request(
|
|
ChatCompletionRequest(
|
|
model="default",
|
|
messages=messages,
|
|
max_tokens=1024,
|
|
frequency_penalty=1.0,
|
|
top_p=0.1,
|
|
temperature=0,
|
|
)
|
|
)
|
|
resp = completion.choices[0].message.content
|
|
print(resp)
|
|
|
|
messages.append({"role": "assistant", "content": completion.choices[0].message.content})
|
|
|
|
messages = [
|
|
{
|
|
"role": "user",
|
|
"content": "How many rs in blueberry? /no_think",
|
|
},
|
|
]
|
|
|
|
# ------------------------------------------------------------------
|
|
# Second question, disable thinking mode with explicit or /no_think
|
|
# ------------------------------------------------------------------
|
|
completion = runner.send_chat_completion_request(
|
|
ChatCompletionRequest(
|
|
model="default",
|
|
messages=messages,
|
|
max_tokens=1024,
|
|
frequency_penalty=1.0,
|
|
top_p=0.1,
|
|
temperature=0,
|
|
# enable_thinking=False
|
|
)
|
|
)
|
|
resp = completion.choices[0].message.content
|
|
print(resp)
|
|
|
|
|
|
messages.append({"role": "assistant", "content": completion.choices[0].message.content})
|
|
|
|
messages = [
|
|
{
|
|
"role": "user",
|
|
"content": "Are you sure? /think",
|
|
},
|
|
]
|
|
|
|
# ------------------------------------------------------------------
|
|
# Third question, reenable thinking mode with explicit or /think
|
|
# ------------------------------------------------------------------
|
|
completion = runner.send_chat_completion_request(
|
|
ChatCompletionRequest(
|
|
model="default",
|
|
messages=messages,
|
|
max_tokens=1024,
|
|
frequency_penalty=1.0,
|
|
top_p=0.1,
|
|
temperature=0,
|
|
# enable_thinking=False
|
|
)
|
|
)
|
|
resp = completion.choices[0].message.content
|
|
print(resp)
|