-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathtest_openai.py
43 lines (36 loc) · 959 Bytes
/
test_openai.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
37
38
39
40
41
42
43
"""
Make sure to use latest version of openai python package
```
pip install openai --upgrade
```
"""
from openai import OpenAI
from keys import OPENAI_KEY
client = OpenAI(
api_key=OPENAI_KEY,
# LauzHack
organization="org-bcv27ooZj8JyXgpgj5sed8rH",
)
# -- chat
response = client.chat.completions.create(
model="gpt-3.5-turbo",
# giving history of chat
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
# extract text
print(response.choices[0].message.content)
# # -- image
# response = client.images.generate(
# model="dall-e-3",
# prompt="a white siamese cat",
# size="1024x1024",
# quality="standard",
# n=1,
# )
# image_url = response.data[0].url
# print(image_url)