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]>
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from mistralrs import Runner, Which, ChatCompletionRequest, Architecture
|
|
from json import dumps
|
|
|
|
runner = Runner(
|
|
which=Which.Plain(
|
|
model_id="microsoft/Phi-3.5-mini-instruct",
|
|
),
|
|
num_device_layers=["500"],
|
|
)
|
|
|
|
# In fact, JSON object can be also defined in the grammar itself, see
|
|
# lark_llg.py and https://github.com/guidance-ai/llguidance/blob/main/docs/syntax.md#inline-json-schemas
|
|
|
|
# @myobj will reference the JSON schema defined below (see grammars = [ ... ])
|
|
top_lark = r"""
|
|
start: "Reasoning: " /.+/ "\nJSON: " @myobj
|
|
"""
|
|
|
|
answer_schema = {
|
|
"type": "object",
|
|
"properties": {
|
|
"answer": {"type": "string", "enum": ["Yes", "No"]},
|
|
},
|
|
"required": ["answer"],
|
|
"additionalProperties": False,
|
|
}
|
|
|
|
grammars = [
|
|
{"lark_grammar": top_lark},
|
|
{"name": "myobj", "json_schema": answer_schema},
|
|
]
|
|
|
|
res = runner.send_chat_completion_request(
|
|
ChatCompletionRequest(
|
|
model="default",
|
|
messages=[
|
|
{
|
|
"role": "user",
|
|
"content": "If all dogs are mammals, and all mammals are animals, are dogs animals?",
|
|
}
|
|
],
|
|
max_tokens=30,
|
|
temperature=0.1,
|
|
grammar_type="llguidance",
|
|
grammar=dumps({"grammars": grammars}),
|
|
)
|
|
)
|
|
print(res.choices[0].message.content)
|
|
print(res.usage)
|