Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
|
|
|
| 3 |
from langchain.chains import ConversationChain
|
| 4 |
from langchain.memory import ConversationBufferMemory
|
| 5 |
from langchain.llms.base import LLM
|
|
@@ -48,13 +49,25 @@ class CustomLLM(LLM):
|
|
| 48 |
"Authorization": f"Bearer {dubs_key}",
|
| 49 |
"Content-Type": "application/json",
|
| 50 |
}
|
| 51 |
-
payload = {"prompt": prompt}
|
| 52 |
|
| 53 |
try:
|
| 54 |
response = requests.post(SPACE_URL, json=payload, headers=headers, stream=True)
|
| 55 |
response.raise_for_status()
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
return result.get("response", "No response from the model.")
|
|
|
|
| 58 |
except requests.exceptions.HTTPError as e:
|
| 59 |
if response.status_code == 401:
|
| 60 |
return "Error: Unauthorized. Please check your Dubs Key."
|
|
@@ -110,4 +123,3 @@ if prompt := st.chat_input():
|
|
| 110 |
|
| 111 |
# Update the LangChain conversation to use the selected session's memory
|
| 112 |
st.session_state["conversation"].memory = memory
|
| 113 |
-
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import requests
|
| 3 |
+
import json
|
| 4 |
from langchain.chains import ConversationChain
|
| 5 |
from langchain.memory import ConversationBufferMemory
|
| 6 |
from langchain.llms.base import LLM
|
|
|
|
| 49 |
"Authorization": f"Bearer {dubs_key}",
|
| 50 |
"Content-Type": "application/json",
|
| 51 |
}
|
| 52 |
+
payload = {"prompt": prompt}
|
| 53 |
|
| 54 |
try:
|
| 55 |
response = requests.post(SPACE_URL, json=payload, headers=headers, stream=True)
|
| 56 |
response.raise_for_status()
|
| 57 |
+
|
| 58 |
+
# Debugging: Log the raw response
|
| 59 |
+
raw_response = response.text
|
| 60 |
+
print("Raw Response:", raw_response)
|
| 61 |
+
|
| 62 |
+
# Handle non-JSON responses
|
| 63 |
+
try:
|
| 64 |
+
result = response.json()
|
| 65 |
+
except json.JSONDecodeError:
|
| 66 |
+
return f"Error decoding response: {raw_response}"
|
| 67 |
+
|
| 68 |
+
# Extract and return the API's response content
|
| 69 |
return result.get("response", "No response from the model.")
|
| 70 |
+
|
| 71 |
except requests.exceptions.HTTPError as e:
|
| 72 |
if response.status_code == 401:
|
| 73 |
return "Error: Unauthorized. Please check your Dubs Key."
|
|
|
|
| 123 |
|
| 124 |
# Update the LangChain conversation to use the selected session's memory
|
| 125 |
st.session_state["conversation"].memory = memory
|
|
|