Spaces:
Runtime error
Runtime error
Update rag_engine.py
Browse files- rag_engine.py +17 -0
rag_engine.py
CHANGED
@@ -11,6 +11,8 @@ from langchain.docstore.document import Document
|
|
11 |
import pinecone
|
12 |
import chainlit as cl
|
13 |
from chainlit.types import AskFileResponse
|
|
|
|
|
14 |
from dotenv import load_dotenv
|
15 |
load_dotenv()
|
16 |
|
@@ -112,12 +114,27 @@ async def start():
|
|
112 |
chat_memory=message_history,
|
113 |
return_messages=True,
|
114 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
|
|
|
116 |
chain = RetrievalQA.from_chain_type(
|
117 |
ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0, streaming=True, openai_api_key=openai_api_key),
|
118 |
chain_type="stuff",
|
119 |
retriever=docsearch.as_retriever(),
|
120 |
return_source_documents=True,
|
|
|
121 |
)
|
122 |
|
123 |
# Let the user know that the system is ready
|
|
|
11 |
import pinecone
|
12 |
import chainlit as cl
|
13 |
from chainlit.types import AskFileResponse
|
14 |
+
from langchain.prompts import PromptTemplate
|
15 |
+
|
16 |
from dotenv import load_dotenv
|
17 |
load_dotenv()
|
18 |
|
|
|
114 |
chat_memory=message_history,
|
115 |
return_messages=True,
|
116 |
)
|
117 |
+
PROMPT = PromptTemplate(
|
118 |
+
template="""Your name is Skandhaar docchat and you are working for Skandhaar org. and your job is to answer the user question from the given context. You are not allowed make an answer and create something that's not there in the context. You strictly follow the context and give extractive answers.
|
119 |
+
Respond for user greetings. If you encounter with out of context questions reply with I'm here to help you with given knowledge source, i can't assist with that.
|
120 |
+
|
121 |
+
context:{context}
|
122 |
+
|
123 |
+
question:{question}
|
124 |
+
|
125 |
+
Answer in the Markdown.
|
126 |
+
|
127 |
+
""",
|
128 |
+
input_variables=["context", "question"]
|
129 |
+
)
|
130 |
|
131 |
+
chain_type_kwargs = {"prompt": PROMPT}
|
132 |
chain = RetrievalQA.from_chain_type(
|
133 |
ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0, streaming=True, openai_api_key=openai_api_key),
|
134 |
chain_type="stuff",
|
135 |
retriever=docsearch.as_retriever(),
|
136 |
return_source_documents=True,
|
137 |
+
chain_type_kwargs=chain_type_kwargs
|
138 |
)
|
139 |
|
140 |
# Let the user know that the system is ready
|