Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -25,26 +25,19 @@ class RamsayGPT:
|
|
25 |
def __init__(self, api_key):
|
26 |
openai.api_key = api_key
|
27 |
self.context = context
|
28 |
-
self.chat_log = [{'role': '
|
29 |
|
30 |
def ramsay_response(self, user_message):
|
31 |
self.chat_log.append({"role": "user", "content": user_message})
|
32 |
try:
|
33 |
response = openai.chat.completions.create(
|
34 |
-
model="
|
35 |
-
|
36 |
-
max_tokens=150, # Adjust the token limit as needed
|
37 |
-
temperature=0.7 # Adjust the creativity level
|
38 |
)
|
39 |
-
assistant_response = response.choices[0].
|
40 |
except Exception as e:
|
41 |
assistant_response = f"Something went wrong, you donkey! Error: {str(e)}"
|
42 |
-
return assistant_response
|
43 |
-
|
44 |
-
def construct_prompt(self):
|
45 |
-
# Construct the prompt based on the chat log
|
46 |
-
prompt = "\n".join([f"{entry['role'].capitalize()}: {entry['content']}" for entry in self.chat_log])
|
47 |
-
return prompt + "\nAssistant:"
|
48 |
|
49 |
def chat(self):
|
50 |
print("Say hello to Chef Ramsay!")
|
|
|
25 |
def __init__(self, api_key):
|
26 |
openai.api_key = api_key
|
27 |
self.context = context
|
28 |
+
self.chat_log = [{'role': 'assistant', 'content': self.context}]
|
29 |
|
30 |
def ramsay_response(self, user_message):
|
31 |
self.chat_log.append({"role": "user", "content": user_message})
|
32 |
try:
|
33 |
response = openai.chat.completions.create(
|
34 |
+
model="gpt-4",
|
35 |
+
messages=self.chat_log
|
|
|
|
|
36 |
)
|
37 |
+
assistant_response = response.choices[0].message.content
|
38 |
except Exception as e:
|
39 |
assistant_response = f"Something went wrong, you donkey! Error: {str(e)}"
|
40 |
+
return assistant_response.strip()
|
|
|
|
|
|
|
|
|
|
|
41 |
|
42 |
def chat(self):
|
43 |
print("Say hello to Chef Ramsay!")
|