Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit fec67ee

Browse files
committed
add Guidance prompt design tutorials
1 parent 9738c42 commit fec67ee

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.env
22
notes.md
33
academy/
4-
*_x.py
4+
*_x.py
5+
.vscode/

12_guidance_roles.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from dotenv import load_dotenv
2+
import guidance
3+
4+
load_dotenv()
5+
6+
chat = guidance.llms.OpenAI("gpt-3.5-turbo")
7+
guidance.llm = chat
8+
9+
program = guidance(
10+
"""
11+
{{#system}}You are a CS Professor teaching {{os}} systems administration to your students.{{/system}}
12+
13+
{{#user~}}
14+
What are some of the most common commands used in the {{os}} operating system? Provide a one-liner description.
15+
List the commands and their descriptions one per line. Number them starting from 1.
16+
{{~/user}}
17+
18+
{{#assistant~}}
19+
{{gen 'commands' max_tokens=100}}
20+
{{~/assistant}}
21+
22+
{{#user~}}
23+
Which among these commands are beginners most likely to get wrong? Explain why the command might be confusing. Show example code to illustrate your point.
24+
{{~/user}}
25+
26+
{{#assistant~}}
27+
{{gen 'confusing_commands' max_tokens=100}}
28+
{{~/assistant}}
29+
""",
30+
llm=chat,
31+
)
32+
33+
34+
result = program(os="Linux")
35+
36+
print(result["commands"])
37+
print("===")
38+
print(result)

12_guidance_syntax.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import random
2+
from dotenv import load_dotenv
3+
import guidance
4+
5+
load_dotenv()
6+
7+
# set the default language model that execute guidance programs
8+
guidance.llm = guidance.llms.OpenAI("text-davinci-003")
9+
# guidance.llm = guidance.llms.Transformers(
10+
# "stabilityai/stablelm-base-alpha-3b", device="cpu"
11+
# )
12+
13+
14+
program = guidance(
15+
"""What are the top ten most common commands used in the {{os}} operating system? Provide
16+
a one-liner description for each command.
17+
{{#block hidden=True}}
18+
A few example commands would be:
19+
[1]: pwd prints the current working directory
20+
[2]: mv moves the file and can be used to rename a file
21+
{{gen 'example' n=2 stop='"' max_tokens=20 temperature=0.8}}
22+
{{/block}}
23+
24+
Here are the common commands:
25+
{{#geneach 'commands' num_iterations=10}}
26+
[{{@index}}]: "{{gen 'this' stop='"'}}", Description: "{{gen 'description' stop='"'}}"
27+
{{/geneach}}
28+
29+
{{select 'flavor' options=quizflavor}}
30+
Explain the following commands for 🥇 {{randomPts}} points:
31+
{{#each (pickthree commands)}}
32+
{{@index+1}}. "{{this}}"
33+
{{/each}}
34+
35+
Use the commands you listed above as input, generate a valid JSON object that maps each command to its description.
36+
"{
37+
"{{os}}": [
38+
{{#geneach 'commands' num_iterations=1}}{{#unless @first}},{{/unless}}
39+
"{{gen 'this'}}"
40+
{{/geneach}}
41+
"""
42+
)
43+
44+
quizflavor = [
45+
"Quiz of the day!",
46+
"Test your knowledge!",
47+
"Here is a quiz!",
48+
"You think you know Unix?",
49+
]
50+
51+
result = program(
52+
os="Linux",
53+
pickthree=lambda x: list(set(x))[:3],
54+
randomPts=random.randint(1, 5),
55+
quizflavor=quizflavor,
56+
)
57+
58+
print(result["example"])
59+
print("===")
60+
print(result["commands"])
61+
print("===")
62+
print(result)

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ A set of instructional materials, code samples and Python scripts featuring LLMs
44
<!-- <img src="assets/youtube.png" width="50%" alt="LangChain youtube tutorials" /> -->
55
![LangChain youtube tutorials](assets/llmseries.png)
66

7-
Learn LangChain from my YouTube channel (~7 hours of LLM hands-on building tutorials); Each lesson is accompanied by the corresponding code in this repo and is designed to be self-contained -- while still focused on some key concepts in LLM (large language model) development and tooling.
7+
Learn LangChain from my YouTube channel (~8 hours of LLM hands-on building tutorials); Each lesson is accompanied by the corresponding code in this repo and is designed to be self-contained -- while still focused on some key concepts in LLM (large language model) development and tooling.
88

99
Feel free to pick and choose your starting point based on your learning goals:
1010

@@ -21,6 +21,7 @@ Feel free to pick and choose your starting point based on your learning goals:
2121
| 9 | Building a queryable journal 💬 w/ OpenAI, markdown & LlamaIndex 🦙 | [Tutorial Video](https://youtu.be/OzDhJOR5IfQ) | 40:29 |
2222
| 10 | Making a Sci-Fi game w/ Cohere LLM + Stability.ai: Generative AI tutorial | [Tutorial Video](https://youtu.be/uR93yTNGtP4) | 1:02:20 |
2323
| 11 | GPT builds entire party invitation app from prompt (ft. SMOL Developer) | [Tutorial Video](https://www.youtube.com/watch?v=Ll_VIsIjuFg) | 41:33 |
24+
| 12 | A language for LLM prompt design: Guidance | [Tutorial Video](https://youtu.be/k4Ejc3bLQiU) | 43:15 |
2425

2526

2627
The full lesson playlist can be found [here](https://www.youtube.com/playlist?list=PLXsFtK46HZxUQERRbOmuGoqbMD-KWLkOS).

0 commit comments

Comments
 (0)