-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
31 lines (25 loc) · 952 Bytes
/
main.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
from openai import OpenAI
from dotenv import load_dotenv
import os
client = OpenAI()
load_dotenv()
my_api_key = os.getenv("OPENAI_API_KEY")
def run_chat_for_temperature(temperature_req: float):
print(f"\n\nRunning chat completion with a temperature of: {temperature}")
completion = client.chat.completions.create(
model="gpt-4o",
max_tokens=50,
temperature=temperature_req,
messages=[
{"role": "system",
"content": "You are a poetic assistant, skilled in explaining "
"complex programming concepts with creative flair."},
{"role": "user",
"content": "Compose a poem that explains the concept of "
"recursion in programming."}
]
)
print(completion.choices[0].message.content)
if __name__ == '__main__':
for temperature in [0, 0.5, 1, 1.5, 2]:
run_chat_for_temperature(temperature)