Spaces:
Runtime error
Runtime error
ambrosfitz
commited on
Commit
•
2b8a170
1
Parent(s):
006cc46
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,7 @@ import os
|
|
4 |
import time
|
5 |
|
6 |
# Initialize the OpenAI Client with your API key and endpoint
|
7 |
-
api_key = os.environ.get("RUNPOD_API_KEY") #
|
8 |
client = OpenAI(
|
9 |
api_key=api_key,
|
10 |
base_url="https://api.runpod.ai/v2/vllm-k0g4c60zor9xuu/openai/v1",
|
@@ -14,9 +14,9 @@ def get_response(user_message, history):
|
|
14 |
# Format the history for OpenAI
|
15 |
history_openai_format = []
|
16 |
for human, assistant in history:
|
17 |
-
if human:
|
18 |
history_openai_format.append({"role": "user", "content": human})
|
19 |
-
if assistant:
|
20 |
history_openai_format.append({"role": "assistant", "content": assistant})
|
21 |
history_openai_format.append({"role": "user", "content": user_message})
|
22 |
|
@@ -28,8 +28,11 @@ def get_response(user_message, history):
|
|
28 |
max_tokens=150
|
29 |
)
|
30 |
|
31 |
-
#
|
32 |
-
|
|
|
|
|
|
|
33 |
return bot_message
|
34 |
|
35 |
with gr.Blocks() as demo:
|
|
|
4 |
import time
|
5 |
|
6 |
# Initialize the OpenAI Client with your API key and endpoint
|
7 |
+
api_key = os.environ.get("RUNPOD_API_KEY") # Ensure your API key is correctly loaded from environment variables
|
8 |
client = OpenAI(
|
9 |
api_key=api_key,
|
10 |
base_url="https://api.runpod.ai/v2/vllm-k0g4c60zor9xuu/openai/v1",
|
|
|
14 |
# Format the history for OpenAI
|
15 |
history_openai_format = []
|
16 |
for human, assistant in history:
|
17 |
+
if human:
|
18 |
history_openai_format.append({"role": "user", "content": human})
|
19 |
+
if assistant:
|
20 |
history_openai_format.append({"role": "assistant", "content": assistant})
|
21 |
history_openai_format.append({"role": "user", "content": user_message})
|
22 |
|
|
|
28 |
max_tokens=150
|
29 |
)
|
30 |
|
31 |
+
# Properly access the text response
|
32 |
+
if response.choices:
|
33 |
+
bot_message = response.choices[0].text.strip() if response.choices[0].text.strip() else "No response generated."
|
34 |
+
else:
|
35 |
+
bot_message = "No response generated."
|
36 |
return bot_message
|
37 |
|
38 |
with gr.Blocks() as demo:
|