Update app.py
Browse files
app.py
CHANGED
@@ -111,9 +111,8 @@ if 'chat_history' not in st.session_state:
|
|
111 |
# CustomLanguageModel class with proper context argument
|
112 |
class CustomLanguageModel:
|
113 |
def generate(self, prompt, context):
|
114 |
-
#
|
115 |
-
|
116 |
-
return f"Generated response based on '{prompt}' and context provided."
|
117 |
|
118 |
# Submit button for chat
|
119 |
if st.button("Submit Query"):
|
@@ -150,15 +149,19 @@ if st.button("Submit Query"):
|
|
150 |
# Initialize the language model
|
151 |
custom_llm = CustomLanguageModel()
|
152 |
|
|
|
|
|
|
|
|
|
153 |
rag_chain = (
|
154 |
-
{"context":
|
155 |
| prompt
|
156 |
-
| custom_llm.generate
|
157 |
| StrOutputParser()
|
158 |
)
|
159 |
|
160 |
# Generate the answer using the user's query
|
161 |
-
result = rag_chain.invoke(query)
|
162 |
|
163 |
# Store query and response in session for chat history
|
164 |
st.session_state['chat_history'].append((query, result))
|
|
|
111 |
# CustomLanguageModel class with proper context argument
|
112 |
class CustomLanguageModel:
|
113 |
def generate(self, prompt, context):
|
114 |
+
# Implement logic to generate a response based on prompt and context
|
115 |
+
return f"Generated response based on prompt: '{prompt}' and context: '{context}'."
|
|
|
116 |
|
117 |
# Submit button for chat
|
118 |
if st.button("Submit Query"):
|
|
|
149 |
# Initialize the language model
|
150 |
custom_llm = CustomLanguageModel()
|
151 |
|
152 |
+
# Extract context from the retriever
|
153 |
+
retrieved_docs = retriever.retrieve(query)
|
154 |
+
context = format_docs(retrieved_docs)
|
155 |
+
|
156 |
rag_chain = (
|
157 |
+
{"context": context, "question": query}
|
158 |
| prompt
|
159 |
+
| (lambda data: custom_llm.generate(data["question"], data["context"]))
|
160 |
| StrOutputParser()
|
161 |
)
|
162 |
|
163 |
# Generate the answer using the user's query
|
164 |
+
result = rag_chain.invoke({"question": query, "context": context})
|
165 |
|
166 |
# Store query and response in session for chat history
|
167 |
st.session_state['chat_history'].append((query, result))
|