Skip to content

Commit d91e39c

Browse files
Update dynamic_system_prompt.py example to use dataclass for simiplicity (#1774)
Co-authored-by: Kazuhiro Sera <seratch@openai.com>
1 parent e47b47a commit d91e39c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

examples/basic/dynamic_system_prompt.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import asyncio
22
import random
3+
from dataclasses import dataclass
34
from typing import Literal
45

56
from agents import Agent, RunContextWrapper, Runner
67

78

9+
@dataclass
810
class CustomContext:
9-
def __init__(self, style: Literal["haiku", "pirate", "robot"]):
10-
self.style = style
11+
style: Literal["haiku", "pirate", "robot"]
1112

1213

1314
def custom_instructions(
@@ -27,11 +28,9 @@ def custom_instructions(
2728
instructions=custom_instructions,
2829
)
2930

30-
3131
async def main():
32-
choice: Literal["haiku", "pirate", "robot"] = random.choice(["haiku", "pirate", "robot"])
33-
context = CustomContext(style=choice)
34-
print(f"Using style: {choice}\n")
32+
context = CustomContext(style=random.choice(["haiku", "pirate", "robot"]))
33+
print(f"Using style: {context.style}\n")
3534

3635
user_message = "Tell me a joke."
3736
print(f"User: {user_message}")
@@ -43,6 +42,7 @@ async def main():
4342
if __name__ == "__main__":
4443
asyncio.run(main())
4544

45+
4646
"""
4747
$ python examples/basic/dynamic_system_prompt.py
4848

0 commit comments

Comments
 (0)