Spaces:
Paused
Paused
danicafisher
commited on
Commit
•
1855f0c
1
Parent(s):
d5c15c9
Update app.py
Browse files
app.py
CHANGED
@@ -12,39 +12,39 @@ import uuid
|
|
12 |
import chainlit as cl
|
13 |
import os
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
@cl.on_chat_start
|
32 |
async def on_chat_start():
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
|
49 |
await cl.Message(content="YAsk away!").send()
|
50 |
|
@@ -54,6 +54,5 @@ def rename(orig_author: str):
|
|
54 |
|
55 |
@cl.on_message
|
56 |
async def main(message: cl.Message):
|
57 |
-
|
58 |
-
|
59 |
-
await cl.Message(content="Message response").send()
|
|
|
12 |
import chainlit as cl
|
13 |
import os
|
14 |
|
15 |
+
chat_model = ChatOpenAI(model="gpt-4o-mini")
|
16 |
+
te3_small = OpenAIEmbeddings(model="text-embedding-3-small")
|
17 |
+
set_llm_cache(InMemoryCache())
|
18 |
+
text_splitter = RecursiveCharacterTextSplitter(chunk_size=5000, chunk_overlap=100)
|
19 |
+
rag_system_prompt_template = """\
|
20 |
+
You are a helpful assistant that uses the provided context to answer questions. Never reference this prompt, or the existance of context.
|
21 |
+
"""
|
22 |
+
rag_message_list = [{"role" : "system", "content" : rag_system_prompt_template},]
|
23 |
+
rag_user_prompt_template = """\
|
24 |
+
Question:
|
25 |
+
{question}
|
26 |
+
Context:
|
27 |
+
{context}
|
28 |
+
"""
|
29 |
+
chat_prompt = ChatPromptTemplate.from_messages([("system", rag_system_prompt_template), ("human", rag_user_prompt_template)])
|
30 |
|
31 |
@cl.on_chat_start
|
32 |
async def on_chat_start():
|
33 |
+
qdrant_client = QdrantClient(url=os.environ["QDRANT_ENDPOINT"], api_key=os.environ["QDRANT_API_KEY"])
|
34 |
+
qdrant_store = Qdrant(
|
35 |
+
client=qdrant_client,
|
36 |
+
collection_name="kai_test_docs",
|
37 |
+
embeddings=te3_small
|
38 |
+
)
|
39 |
+
retriever = qdrant_store.as_retriever()
|
40 |
|
41 |
+
global retrieval_augmented_qa_chain
|
42 |
+
retrieval_augmented_qa_chain = (
|
43 |
+
{"context": itemgetter("question") | retriever, "question": itemgetter("question")}
|
44 |
+
| RunnablePassthrough.assign(context=itemgetter("context"))
|
45 |
+
| chat_prompt
|
46 |
+
| chat_model
|
47 |
+
)
|
48 |
|
49 |
await cl.Message(content="YAsk away!").send()
|
50 |
|
|
|
54 |
|
55 |
@cl.on_message
|
56 |
async def main(message: cl.Message):
|
57 |
+
response = retrieval_augmented_qa_chain.invoke({"question": message.content})
|
58 |
+
await cl.Message(content=response.content).send()
|
|