-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchat.py
More file actions
27 lines (21 loc) · 828 Bytes
/
chat.py
File metadata and controls
27 lines (21 loc) · 828 Bytes
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
#import openai
apikey = "" # https://platform.openai.com/account/api-keys
#openai.api_key = apikey
#completion = openai.ChatCompletion.create(
# model="gpt-3.5-turbo",
# messages=[
# {"role": "user", "content": "Wie kann man in Python eine Datei einlesen?"}
# ]
#)
###
# API Request with requests
import requests # https://requests.readthedocs.io/en/latest/
response = requests.post('https://api.openai.com/v1/chat/completions',
headers={'Authorization': f'Bearer {apikey}'},
json = {
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}
)
completion = response.json()
print(completion['choices'][0]['message'])