Spaces:
Runtime error
Runtime error
put the reranker in async function call
Browse files
app.py
CHANGED
@@ -85,11 +85,11 @@ reranker = FlagEmbeddingReranker(
|
|
85 |
model="BAAI/bge-reranker-large",
|
86 |
)
|
87 |
|
88 |
-
recursive_query_engine = recursive_index_faiss.as_query_engine(
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
)
|
93 |
|
94 |
|
95 |
# ChatOpenAI Templates
|
@@ -102,6 +102,16 @@ You are a helpful assistant who always speaks in a pleasant tone! """
|
|
102 |
user_template = """ Think through your response step by step."""
|
103 |
|
104 |
#user_query = "Who are the E-VP, Operations - and how old are they?"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
107 |
async def main(message: cl.Message):
|
@@ -109,7 +119,7 @@ async def main(message: cl.Message):
|
|
109 |
|
110 |
user_query = message.content
|
111 |
|
112 |
-
response = await
|
113 |
str_resp ="{}".format(response)
|
114 |
msg = cl.Message(content= str_resp)
|
115 |
await msg.send()
|
|
|
85 |
model="BAAI/bge-reranker-large",
|
86 |
)
|
87 |
|
88 |
+
# recursive_query_engine = recursive_index_faiss.as_query_engine(
|
89 |
+
# similarity_top_k=5,
|
90 |
+
# node_postprocessors=[reranker],
|
91 |
+
# verbose=True
|
92 |
+
# )
|
93 |
|
94 |
|
95 |
# ChatOpenAI Templates
|
|
|
102 |
user_template = """ Think through your response step by step."""
|
103 |
|
104 |
#user_query = "Who are the E-VP, Operations - and how old are they?"
|
105 |
+
# prompt=system_template + user_query + user_template
|
106 |
+
|
107 |
+
async def recursive_fn_call(reranker, system_template, user_template, user_query=None):
|
108 |
+
recursive_query_engine = recursive_index_faiss.as_query_engine(
|
109 |
+
similarity_top_k=5,
|
110 |
+
node_postprocessors=[reranker],
|
111 |
+
verbose=True
|
112 |
+
)
|
113 |
+
response = recursive_query_engine.query(system_template + user_query + user_template)
|
114 |
+
return response
|
115 |
|
116 |
@cl.on_message # marks a function that should be run each time the chatbot receives a message from a user
|
117 |
async def main(message: cl.Message):
|
|
|
119 |
|
120 |
user_query = message.content
|
121 |
|
122 |
+
response = await recursive_fn_call(reranker, system_template, user_template, user_query=user_query)
|
123 |
str_resp ="{}".format(response)
|
124 |
msg = cl.Message(content= str_resp)
|
125 |
await msg.send()
|