Spaces:
Sleeping
Sleeping
Commit
·
5189775
1
Parent(s):
18257e4
solved the json error
Browse files
app.py
CHANGED
@@ -17,9 +17,9 @@ from langchain_core.prompts import ChatPromptTemplate
|
|
17 |
from langchain.schema.runnable.passthrough import RunnableAssign
|
18 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
19 |
from langchain_huggingface import HuggingFaceEmbeddings
|
20 |
-
from
|
|
|
21 |
from langchain.docstore.document import Document
|
22 |
-
from langchain.retrievers import BM25Retriever
|
23 |
from langchain_openai import ChatOpenAI
|
24 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
25 |
|
@@ -248,10 +248,15 @@ def hybrid_retrieve(inputs, exclude_terms=None):
|
|
248 |
}
|
249 |
|
250 |
def safe_json_parse(s: str) -> Dict:
|
251 |
-
|
252 |
-
"valid_chunks"
|
253 |
-
|
254 |
-
|
|
|
|
|
|
|
|
|
|
|
255 |
}
|
256 |
|
257 |
# Rewrite generation
|
@@ -384,6 +389,7 @@ with gr.Blocks(css="""
|
|
384 |
"Where did Krishna work?",
|
385 |
"What did he study at Virginia Tech?"
|
386 |
],
|
|
|
387 |
)
|
388 |
|
389 |
demo.launch()
|
|
|
17 |
from langchain.schema.runnable.passthrough import RunnableAssign
|
18 |
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
19 |
from langchain_huggingface import HuggingFaceEmbeddings
|
20 |
+
from langchain_community.vectorstores import FAISS
|
21 |
+
from langchain_community.retrievers import BM25Retriever
|
22 |
from langchain.docstore.document import Document
|
|
|
23 |
from langchain_openai import ChatOpenAI
|
24 |
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
|
25 |
|
|
|
248 |
}
|
249 |
|
250 |
def safe_json_parse(s: str) -> Dict:
|
251 |
+
try:
|
252 |
+
if isinstance(s, str) and "valid_chunks" in s:
|
253 |
+
return json.loads(s)
|
254 |
+
except json.JSONDecodeError:
|
255 |
+
pass
|
256 |
+
return {
|
257 |
+
"valid_chunks": [],
|
258 |
+
"is_out_of_scope": True,
|
259 |
+
"justification": "Fallback due to invalid or missing LLM output"
|
260 |
}
|
261 |
|
262 |
# Rewrite generation
|
|
|
389 |
"Where did Krishna work?",
|
390 |
"What did he study at Virginia Tech?"
|
391 |
],
|
392 |
+
type= "messages",
|
393 |
)
|
394 |
|
395 |
demo.launch()
|