-
Notifications
You must be signed in to change notification settings - Fork 269
/
12_guidance_syntax.py
62 lines (52 loc) · 1.72 KB
/
12_guidance_syntax.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
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
import random
from dotenv import load_dotenv
import guidance
load_dotenv()
# set the default language model that execute guidance programs
guidance.llm = guidance.llms.OpenAI("text-davinci-003")
# guidance.llm = guidance.llms.Transformers(
# "stabilityai/stablelm-base-alpha-3b", device="cpu"
# )
program = guidance(
"""What are the top ten most common commands used in the {{os}} operating system? Provide
a one-liner description for each command.
{{#block hidden=True}}
A few example commands would be:
[1]: pwd prints the current working directory
[2]: mv moves the file and can be used to rename a file
{{gen 'example' n=2 stop='"' max_tokens=20 temperature=0.8}}
{{/block}}
Here are the common commands:
{{#geneach 'commands' num_iterations=10}}
[{{@index}}]: "{{gen 'this' stop='"'}}", Description: "{{gen 'description' stop='"'}}"
{{/geneach}}
{{select 'flavor' options=quizflavor}}
Explain the following commands for 🥇 {{randomPts}} points:
{{#each (pickthree commands)}}
{{@index+1}}. "{{this}}"
{{/each}}
Use the commands you listed above as input, generate a valid JSON object that maps each command to its description.
"{
"{{os}}": [
{{#geneach 'commands' num_iterations=1}}{{#unless @first}},{{/unless}}
"{{gen 'this'}}"
{{/geneach}}
"""
)
quizflavor = [
"Quiz of the day!",
"Test your knowledge!",
"Here is a quiz!",
"You think you know Unix?",
]
result = program(
os="Linux",
pickthree=lambda x: list(set(x))[:3],
randomPts=random.randint(1, 5),
quizflavor=quizflavor,
)
print(result["example"])
print("===")
print(result["commands"])
print("===")
print(result)