-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChatGPT_API.py
More file actions
35 lines (31 loc) · 1018 Bytes
/
ChatGPT_API.py
File metadata and controls
35 lines (31 loc) · 1018 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
28
29
30
31
32
33
34
35
import os
import re
import pandas as pd
from api_keys import ChatGPT_key
from openai import OpenAI, RateLimitError
# API-Key setzen
os.environ["OPENAI_API_KEY"] = ChatGPT_key
# OpenAI-Client initialisieren (ohne Argumente!)
client = OpenAI()
########################################################################################################################
#Dependencies
# pip install openai
#pip install openpyxl
#pip install tabulate
# https://platform.openai.com/api-keys
def gpt_chat(prompt):
try:
response = client.chat.completions.create(
model="gpt-5",
messages=[{"role": "user", "content": prompt}]
)
return response.choices[0].message.content.strip()
except RateLimitError as e:
return f"Rate Limit überschritten: {e}"
if __name__ == '__main__':
while True:
user_input = str(input("You: "))
if user_input.lower() in ['exit', 'bye']:
break
response = gpt_chat(user_input)
print(response)