FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
llama-cpp-python/tests/test_llama_grammar.py at main · eseedo/llama-cpp-python · GitHub
eseedo
/
llama-cpp-python
Public
forked from
abetlen/llama-cpp-python
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
llama-cpp-python
/
tests
/
test_llama_grammar.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
78 lines (64 loc) · 1.86 KB
Breadcrumbs
llama-cpp-python
/
tests
/
test_llama_grammar.py
Copy path
File metadata and controls
78 lines (64 loc) · 1.86 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import
llama_cpp
import
json
tree
=
"""
leaf ::= "."
node ::= leaf | "(" node node ")"
root ::= node
"""
def
test_grammar_from_string
():
grammar
=
llama_cpp
.
LlamaGrammar
.
from_string
(
tree
)
# assert grammar._n_rules == 3
# assert grammar._start_rule_index == 2
# assert grammar.grammar is not None
def
test_composed_pydantic_grammar
():
"""
from pydantic import BaseModel
class A(BaseModel):
a: int
class B(BaseModel):
a: A
b: int
"""
# This schema corresponds to the grammar in the comment above.
# We don't use the pydantic models directly to avoid the dependency.
schema
=
{
"$defs"
: {
"A"
: {
"properties"
: {
"a"
: {
"title"
:
"A"
,
"type"
:
"integer"
}},
"required"
: [
"a"
],
"title"
:
"A"
,
"type"
:
"object"
,
}
},
"properties"
: {
"a"
: {
"$ref"
:
"#/$defs/A"
},
"b"
: {
"title"
:
"B"
,
"type"
:
"integer"
},
},
"required"
: [
"a"
,
"b"
],
"title"
:
"B"
,
"type"
:
"object"
,
}
grammar
=
llama_cpp
.
LlamaGrammar
.
from_json_schema
(
json
.
dumps
(
schema
))
# assert grammar.grammar is not None
def
test_grammar_anyof
():
sch
=
{
"properties"
: {
"temperature"
: {
"description"
:
"The temperature mentioned"
,
"type"
:
"number"
,
},
"unit"
: {
"anyOf"
: [
{
"description"
:
"Unit for temperature"
,
"enum"
: [
"celsius"
,
"fahrenheit"
],
"type"
:
"string"
,
},
{
"type"
:
"null"
},
],
},
},
"type"
:
"object"
,
}
grammar
=
llama_cpp
.
LlamaGrammar
.
from_json_schema
(
json
.
dumps
(
sch
))
# assert grammar.grammar is not None
Back
|
FazBrowse Home
|
New Git URL