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