forked from EricLBuehler/mistral.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlark_llg.py
More file actions
42 lines (37 loc) · 1.01 KB
/
lark_llg.py
File metadata and controls
42 lines (37 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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"],
)
# see https://github.com/guidance-ai/llguidance/blob/main/docs/syntax.md for docs on syntax
top_lark = r"""
start: "Reasoning: " /.+/ "\nJSON: " answer
answer: %json {
"type": "object",
"properties": {
"answer": {"type": "string", "enum": ["Yes", "No"]}
},
"required": ["answer"],
"additionalProperties": false
}
"""
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=100,
temperature=0.1,
grammar_type="lark",
grammar=top_lark,
)
)
print(res.choices[0].message.content)
print(res.usage)