Update app.py
Browse files
app.py
CHANGED
@@ -120,7 +120,10 @@ def generate_response(query, history, model, temperature, max_tokens, top_p, see
|
|
120 |
retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 16})
|
121 |
llm = ChatGroq(groq_api_key=os.environ.get("GROQ_API_KEY"), model=model)
|
122 |
custom_rag_prompt = PromptTemplate.from_template(template)
|
123 |
-
|
|
|
|
|
|
|
124 |
rag_chain = (
|
125 |
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
126 |
| custom_rag_prompt
|
@@ -130,7 +133,7 @@ def generate_response(query, history, model, temperature, max_tokens, top_p, see
|
|
130 |
|
131 |
response = rag_chain.invoke(query)
|
132 |
|
133 |
-
return response
|
134 |
|
135 |
|
136 |
|
@@ -159,15 +162,16 @@ with gr.Blocks(theme="Nymbo/Alyx_Theme") as demo:
|
|
159 |
|
160 |
with gr.Tab("Chatbot"):
|
161 |
with gr.Row():
|
162 |
-
with gr.Column(
|
163 |
gr.ChatInterface(
|
164 |
fn=generate_response,
|
165 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
166 |
examples=examples_questions,
|
167 |
additional_inputs=additional_inputs,
|
|
|
168 |
cache_examples=False,
|
169 |
)
|
170 |
-
with gr.Column(
|
171 |
relevant_info = gr.Textbox(
|
172 |
label="Retrieved Information",
|
173 |
interactive=False,
|
|
|
120 |
retriever = vector_store.as_retriever(search_type="similarity", search_kwargs={"k": 16})
|
121 |
llm = ChatGroq(groq_api_key=os.environ.get("GROQ_API_KEY"), model=model)
|
122 |
custom_rag_prompt = PromptTemplate.from_template(template)
|
123 |
+
|
124 |
+
docs = retriever.invoke(query)
|
125 |
+
relevant_info = format_docs(docs)
|
126 |
+
|
127 |
rag_chain = (
|
128 |
{"context": retriever | format_docs, "question": RunnablePassthrough()}
|
129 |
| custom_rag_prompt
|
|
|
133 |
|
134 |
response = rag_chain.invoke(query)
|
135 |
|
136 |
+
return response, relevant_info
|
137 |
|
138 |
|
139 |
|
|
|
162 |
|
163 |
with gr.Tab("Chatbot"):
|
164 |
with gr.Row():
|
165 |
+
with gr.Column():
|
166 |
gr.ChatInterface(
|
167 |
fn=generate_response,
|
168 |
chatbot=gr.Chatbot(show_label=False, show_share_button=False, show_copy_button=True, likeable=True, layout="panel"),
|
169 |
examples=examples_questions,
|
170 |
additional_inputs=additional_inputs,
|
171 |
+
additional_outputs=[relevant_info],
|
172 |
cache_examples=False,
|
173 |
)
|
174 |
+
with gr.Column():
|
175 |
relevant_info = gr.Textbox(
|
176 |
label="Retrieved Information",
|
177 |
interactive=False,
|