Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -19,13 +19,17 @@ from langchain.schema import BaseOutputParser, OutputParserException
|
|
| 19 |
from htmlTemplates import css, bot_template, user_template
|
| 20 |
from langchain.llms import HuggingFaceHub
|
| 21 |
|
| 22 |
-
class ReferenceOutputParser(BaseOutputParser):
|
| 23 |
-
def parse(self, text: str) ->
|
| 24 |
try:
|
| 25 |
result, references = text.split("References:")
|
| 26 |
-
return
|
|
|
|
|
|
|
|
|
|
| 27 |
except ValueError:
|
| 28 |
raise OutputParserException(f"Could not parse output: {text}")
|
|
|
|
| 29 |
|
| 30 |
def get_pdf_text(pdf_docs):
|
| 31 |
text = ""
|
|
@@ -91,8 +95,8 @@ def handle_userinput(user_question):
|
|
| 91 |
response = st.session_state.conversation({"question": user_question})
|
| 92 |
st.session_state.chat_history = response["chat_history"]
|
| 93 |
|
| 94 |
-
result = response
|
| 95 |
-
references = response["references"]
|
| 96 |
|
| 97 |
st.write("//_^ User: " + user_question)
|
| 98 |
st.write("🤖 ChatBot: " + result)
|
|
|
|
| 19 |
from htmlTemplates import css, bot_template, user_template
|
| 20 |
from langchain.llms import HuggingFaceHub
|
| 21 |
|
| 22 |
+
class ReferenceOutputParser(BaseOutputParser[ChatGeneration]):
|
| 23 |
+
def parse(self, text: str) -> ChatGeneration:
|
| 24 |
try:
|
| 25 |
result, references = text.split("References:")
|
| 26 |
+
return ChatGeneration(
|
| 27 |
+
result=result.strip(),
|
| 28 |
+
extra_info={"references": [ref.strip() for ref in references.split("\n") if ref.strip()]}
|
| 29 |
+
)
|
| 30 |
except ValueError:
|
| 31 |
raise OutputParserException(f"Could not parse output: {text}")
|
| 32 |
+
|
| 33 |
|
| 34 |
def get_pdf_text(pdf_docs):
|
| 35 |
text = ""
|
|
|
|
| 95 |
response = st.session_state.conversation({"question": user_question})
|
| 96 |
st.session_state.chat_history = response["chat_history"]
|
| 97 |
|
| 98 |
+
result = response.result
|
| 99 |
+
references = response.extra_info["references"]
|
| 100 |
|
| 101 |
st.write("//_^ User: " + user_question)
|
| 102 |
st.write("🤖 ChatBot: " + result)
|