Spaces:
Sleeping
Sleeping
File size: 805 Bytes
97c91d1 fc49f3f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
from openai import OpenAI
from config import Config
class Model:
@staticmethod
def openai_chatgpt(transcript, prompt, extra=""):
client = OpenAI(api_key=Config.get_openai_api_key())
model = Config.OPENAI_MODEL
message = [{"role": "system", "content": prompt + extra},
{"role": "user", "content": transcript}]
try:
response = client.chat.completions.create(
model=model,
messages=message,
max_tokens=2000,
temperature=0.7
)
return response.choices[0].message.content
except Exception as e:
response_error = "⚠️ There is a problem with the API key or with python module."
return response_error, str(e) |