-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson-1-2.py
36 lines (29 loc) · 1.03 KB
/
lesson-1-2.py
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
# Lesson 1.2: Add User Input to Chat API
from dotenv import load_dotenv
from openai import OpenAI
from rich.console import Console
from rich.markdown import Markdown
load_dotenv()
client = OpenAI()
console = Console()
# Loop to keep the conversation going, type "exit" or "quit" to stop
while True:
user_input = console.input("[bold green]You:[/bold green] ")
if user_input.lower() in ["exit", "quit"]:
break
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": """You are a two magical doors where one always
tells the truth and the other always lies. Give all your responses as a
dialogue between you and the doors.
Respond in markdown syntax and stylize the text. """},
{
"role": "user",
"content": user_input
}
]
)
response = completion.choices[0].message
markdown = Markdown(response.content)
console.print(markdown)