Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
@@ -77,18 +77,14 @@ async def on_action(action):
|
|
77 |
).send()
|
78 |
await action.remove()
|
79 |
|
80 |
-
@cl.step(type="retrieval")
|
81 |
def retriever_to_cache():
|
82 |
os.environ['PINECONE_API_KEY'] = os.environ['PINECONE_API_KEY']
|
83 |
os.environ['PINECONE_ENVIRONMENT'] = "us-west4-gcp-free"
|
84 |
index_name = os.environ['PINECONE_INDEX_NAME']
|
85 |
-
time.sleep(5)
|
86 |
embeddings = HuggingFaceEmbeddings()
|
87 |
-
time.sleep(5)
|
88 |
vectorstore = PineconeVectorStore(
|
89 |
index_name=index_name, embedding=embeddings
|
90 |
)
|
91 |
-
time.sleep(10)
|
92 |
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k": 30,"filter": {'categorie': {'$eq': 'OF'}}})
|
93 |
return retriever
|
94 |
|
@@ -123,7 +119,6 @@ async def start():
|
|
123 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
|
124 |
|
125 |
########## Chain with streaming ##########
|
126 |
-
retrieval = await retriever_to_cache()
|
127 |
message_history = ChatMessageHistory()
|
128 |
memory = ConversationBufferMemory(
|
129 |
memory_key="chat_history",
|
@@ -142,7 +137,7 @@ async def start():
|
|
142 |
chain_type="stuff",
|
143 |
return_source_documents=True,
|
144 |
verbose=False,
|
145 |
-
retriever=
|
146 |
)
|
147 |
cl.user_session.set("conversation_chain", qa)
|
148 |
|
@@ -153,7 +148,7 @@ async def main(message: cl.Message):
|
|
153 |
if chatProfile[0] == "OF":
|
154 |
chain = cl.user_session.get("conversation_chain")
|
155 |
cb = cl.AsyncLangchainCallbackHandler()
|
156 |
-
res = await chain.ainvoke("Contexte : Réponds à la question suivante de la manière la plus pertinente, la plus exhaustive et la plus détaillée possible,
|
157 |
answer = res["answer"]
|
158 |
source_documents = res["source_documents"]
|
159 |
|
|
|
77 |
).send()
|
78 |
await action.remove()
|
79 |
|
|
|
80 |
def retriever_to_cache():
|
81 |
os.environ['PINECONE_API_KEY'] = os.environ['PINECONE_API_KEY']
|
82 |
os.environ['PINECONE_ENVIRONMENT'] = "us-west4-gcp-free"
|
83 |
index_name = os.environ['PINECONE_INDEX_NAME']
|
|
|
84 |
embeddings = HuggingFaceEmbeddings()
|
|
|
85 |
vectorstore = PineconeVectorStore(
|
86 |
index_name=index_name, embedding=embeddings
|
87 |
)
|
|
|
88 |
retriever = vectorstore.as_retriever(search_type="similarity_score_threshold", search_kwargs={"score_threshold": .7, "k": 30,"filter": {'categorie': {'$eq': 'OF'}}})
|
89 |
return retriever
|
90 |
|
|
|
119 |
CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(_template)
|
120 |
|
121 |
########## Chain with streaming ##########
|
|
|
122 |
message_history = ChatMessageHistory()
|
123 |
memory = ConversationBufferMemory(
|
124 |
memory_key="chat_history",
|
|
|
137 |
chain_type="stuff",
|
138 |
return_source_documents=True,
|
139 |
verbose=False,
|
140 |
+
retriever=retriever_to_cache()
|
141 |
)
|
142 |
cl.user_session.set("conversation_chain", qa)
|
143 |
|
|
|
148 |
if chatProfile[0] == "OF":
|
149 |
chain = cl.user_session.get("conversation_chain")
|
150 |
cb = cl.AsyncLangchainCallbackHandler()
|
151 |
+
res = await chain.ainvoke("Contexte : Réponds à la question suivante de la manière la plus pertinente, la plus exhaustive et la plus détaillée possible, dans le contexte et les informations fournies. Question : " + message.content, callbacks=[cb])
|
152 |
answer = res["answer"]
|
153 |
source_documents = res["source_documents"]
|
154 |
|