Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -10,6 +10,21 @@ import time
|
|
10 |
import base64
|
11 |
import os
|
12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
#This function is typically used in Python to load environment variables from a .env file into the application's environment.
|
15 |
load_dotenv()
|
|
|
10 |
import base64
|
11 |
import os
|
12 |
|
13 |
+
class ChatOpenAI:
|
14 |
+
def __init__(self, api_key, model_name="gpt-3.5-turbo", temperature=0.9):
|
15 |
+
self.api_key = api_key
|
16 |
+
self.model_name = model_name
|
17 |
+
self.temperature = temperature
|
18 |
+
openai.api_key = self.api_key
|
19 |
+
|
20 |
+
def chat(self, prompt):
|
21 |
+
response = openai.ChatCompletion.create(
|
22 |
+
model=self.model_name,
|
23 |
+
messages=[{"role": "system", "content": "You are a helpful assistant."}, {"role": "user", "content": prompt}],
|
24 |
+
temperature=self.temperature
|
25 |
+
)
|
26 |
+
return response['choices'][0]['message']['content']
|
27 |
+
|
28 |
|
29 |
#This function is typically used in Python to load environment variables from a .env file into the application's environment.
|
30 |
load_dotenv()
|