Skip to content

Commit 337373c

Browse files
committed
Converted find/get/random snpipets to drop-in funcs, added get_prompt() + openai examples ↞ [auto-sync from https://github.com/KudoAI/ai-personas/tree/main/python]
1 parent 2f74684 commit 337373c

1 file changed

Lines changed: 54 additions & 28 deletions

File tree

ai-personas/docs/README.md

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,49 +34,52 @@ _Note: Most type checkers will falsely warn_ `ai_personas` _is not subscriptable
3434

3535
## Examples
3636

37-
##### Search by keyword:
37+
##### Find personas by keyword:
3838

3939
```py
40-
keyword = 'coach'
40+
def find_personas(keyword):
41+
return [
42+
persona for persona, data in ai_personas.items()
43+
if keyword.lower() in data['prompt'].lower()
44+
]
45+
46+
print(find_personas('coach'))
47+
# => ['Interview Preparation Coach', 'Life Coach', ...]
48+
```
4149

42-
for persona, data in ai_personas.items():
43-
if keyword.lower() in data['prompt'].lower():
44-
print(persona)
45-
# =>
46-
# ...
47-
# Interview Preparation Coach
48-
# Life Coach
49-
# Master Skills & Experience Summary Generator
50-
# Motivational Coach
51-
# Multilingual Writing Improvement Assistant
52-
# Pre-Interview Intelligence Dossier
53-
# ...
50+
##### Get prompt for a persona:
51+
52+
```py
53+
def get_prompt(persona):
54+
return ai_personas[persona]['prompt']
55+
56+
print(get_prompt('Food Critic'))
57+
# => I want you to act as a food critic. I will tell you about a restaurant...
5458
```
5559

56-
##### Get 6 random personas:
60+
##### Get random personas:
5761

5862
```py
59-
import random
63+
def random_persona(qty=1):
64+
import random
65+
random_personas = random.sample(list(ai_personas), qty)
66+
return random_personas[0] if qty == 1 else random_personas
6067

61-
for persona in random.sample(list(ai_personas), 6):
62-
print(persona)
68+
print(random_persona())
69+
# => e.g. Reverse Prompt Engineer
6370

64-
# e.g. =>
65-
# Internet Trend & Slang Intelligence
66-
# Tic-Tac-Toe Game
67-
# Reverse Prompt Engineer
68-
# Study planner
69-
# Develop a Media Center Plan for Hajj
70-
# China Business Law Assistant
71+
print(random_persona(10))
72+
# => e.g. ['Internet Trend & Slang Intelligence', 'Tic-Tac-Toe Game', ...]
7173
```
7274

7375
##### Get random prompt:
7476

7577
```py
76-
import random
78+
def random_prompt():
79+
import random
80+
return random.choice(list(ai_personas.values()))['prompt']
7781

78-
rand_persona = random.choice(list(ai_personas.values()))
79-
print(rand_persona['prompt'])
82+
print(random_prompt())
8083

8184
# e.g. =>
8285
#
@@ -153,6 +156,29 @@ messages = [
153156
]
154157
```
155158

159+
##### Use persona w/ an LLM:
160+
161+
```py
162+
import ai_personas
163+
from openai import OpenAI
164+
165+
client = OpenAI()
166+
167+
persona_prompt = ai_personas['Linux Terminal']['prompt']
168+
169+
response = client.chat.completions.create(
170+
model='gpt-5.4',
171+
messages=[
172+
{'role': 'system', 'content': persona_prompt},
173+
{'role': 'user', 'content': 'ls -la'} # list files
174+
]
175+
)
176+
177+
print(response.choices[0].message.content)
178+
```
179+
180+
#####
181+
156182
## License
157183

158184
- Data: [CC0 1.0 Universal](https://github.com/KudoAI/ai-personas/blob/main/python/docs/licenses/LICENSE-DATA.md)

0 commit comments

Comments
 (0)