forked from onlyphantom/llm-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12_guidance_syntax.py
More file actions
56 lines (43 loc) · 1.51 KB
/
12_guidance_syntax.py
File metadata and controls
56 lines (43 loc) · 1.51 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import random
from dotenv import load_dotenv
import guidance
from guidance import models, gen, system, user, assistant
load_dotenv()
# set the default language model that execute guidance programs
lm = models.OpenAI("gpt-3.5-turbo")
quizflavor = [
"Quiz of the day!",
"Test your knowledge!",
"Here is a quiz!",
"You think you know Unix?",
]
def program(lm):
with system():
lm += "You are a Linux systems expert creating educational content about command line tools."
with user():
lm += "What are the top ten most common commands used in the Linux operating system? Provide a one-liner description for each command."
with assistant():
lm += gen('example', max_tokens=20, temperature=0.8)
with user():
lm += "Here are the common commands:"
with assistant():
lm += gen('commands', max_tokens=500)
with user():
flavor = random.choice(quizflavor)
points = random.randint(1, 5)
lm += f"{flavor} Explain the following commands for {points} points:"
with assistant():
lm += gen('confusing_commands', max_tokens=300)
return lm
result = program(lm)
print("Generated example:")
print(result.get("example", "No example generated"))
print("===")
print("Generated commands:")
print(result.get("commands", "No commands generated"))
print("===")
print("Confusing commands:")
print(result.get("confusing_commands", "No confusing commands generated"))
print("===")
print("Full result:")
print(result)