-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy path12_guidance_syntax.py
More file actions
48 lines (38 loc) · 1.58 KB
/
12_guidance_syntax.py
File metadata and controls
48 lines (38 loc) · 1.58 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
# ====================================================================================
# MIGRATED FROM GUIDANCE 0.x TO 1.x (Major API changes)
# ====================================================================================
# Original code used advanced Handlebars features ({{#geneach}}, {{select}}, etc.)
# New guidance 1.x uses Python loops and simplified API
# Some features simplified due to API changes
# ====================================================================================
import random
from dotenv import load_dotenv
from guidance import models, gen, user, assistant
load_dotenv()
# Initialize model (guidance 1.x syntax)
llm = models.OpenAI("gpt-3.5-turbo") # Updated from text-davinci-003
os_name = "Linux"
# Select quiz flavor
quizflavor = [
"Quiz of the day!",
"Test your knowledge!",
"Here is a quiz!",
"You think you know Unix?",
]
flavor = random.choice(quizflavor)
randomPts = random.randint(1, 5)
# Build the prompt (all text must be within role contexts)
with user():
lm = llm + f"What are the top ten most common commands used in the {os_name} operating system? Provide a one-liner description for each command. List them numbered from 1-10."
with assistant():
lm += gen("commands_list", max_tokens=300)
with user():
lm += f"\n{flavor}\nExplain the following commands for 🥇 {randomPts} points (pick 3 from the list above):"
with assistant():
lm += gen("quiz_explanation", max_tokens=200)
# Print results
print("Generated commands:")
print(lm["commands_list"])
print("\n===")
print("Quiz explanation:")
print(lm["quiz_explanation"])