-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlesson-1-1.py
31 lines (26 loc) · 955 Bytes
/
lesson-1-1.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
# Getting Started: Lesson 1.1 - Introduction to OpenAI Chat API
from dotenv import load_dotenv
from openai import OpenAI
from rich.console import Console
from rich.markdown import Markdown
# Loads the environment variables from .env file
load_dotenv()
client = OpenAI()
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": "Is the moon made of cheese?"
}
]
)
console = Console()
response = completion.choices[0].message
# Make the output look nice by converting the Markdown to a Rich Markdown object
markdown = Markdown(response.content)
console.print(markdown)