-
Notifications
You must be signed in to change notification settings - Fork 80
/
Copy pathgenarg.py
36 lines (32 loc) · 1.01 KB
/
genarg.py
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
# run as:
# PYTHONPATH=.. python genarg.py
import ujson
import pyaici._ast as ast
def main():
aa = {
"steps": [ast.fixed("Here's some JSON about J.R.Hacker from Seattle:\n")]
+ ast.json_to_steps(
{
"name": "",
"valid": True,
"description": "",
"type": "foo|bar|baz|something|else",
"address": {"street": "", "city": "", "state": "[A-Z][A-Z]"},
"age": 1,
"fraction": 1.5,
}
)
}
aa = {
"steps": [
ast.fixed("The word 'hello'"),
ast.label("lang", ast.fixed(" in French is translated as")),
ast.gen(rx=r" '[^']*'", max_tokens=15, set_var="french"),
ast.fixed(" or", following="lang"),
ast.gen(rx=r" '[^']*'", max_tokens=15, set_var="blah"),
ast.fixed("\nResults: {{french}} {{blah}}", expand_vars=True),
]
}
ast.clear_none(aa)
print(ujson.dumps(aa))
main()