Correcting the retrieval of relevant documents
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from datetime import datetime as dt, timezone as tz
|
||||
from flask import current_app
|
||||
from flask import current_app, session
|
||||
from langchain_core.output_parsers import StrOutputParser
|
||||
from langchain_core.runnables import RunnableParallel, RunnablePassthrough
|
||||
from langchain.globals import set_debug
|
||||
@@ -46,9 +46,9 @@ def ask_question(tenant_id, question, language, session_id):
|
||||
# Ensure we are working in the correct database schema
|
||||
Database(tenant_id).switch_schema()
|
||||
|
||||
# Ensure we have a session to story history
|
||||
chat_session = ChatSession.query.filter_by(session_id=session_id).first()
|
||||
if not chat_session:
|
||||
# Initialize a chat_session on the database
|
||||
try:
|
||||
chat_session = ChatSession()
|
||||
chat_session.session_id = session_id
|
||||
@@ -66,22 +66,14 @@ def ask_question(tenant_id, question, language, session_id):
|
||||
new_interaction.question_at = dt.now(tz.utc)
|
||||
new_interaction.algorithm_used = current_app.config['INTERACTION_ALGORITHMS']['RAG_TENANT']['name']
|
||||
|
||||
# try:
|
||||
# db.session.add(new_interaction)
|
||||
# db.session.commit()
|
||||
# except SQLAlchemyError as e:
|
||||
# current_app.logger.error(f'ask_question: Error saving interaction to database: {e}')
|
||||
# raise
|
||||
|
||||
current_app.logger.debug(f'ask_question: new_interaction: {new_interaction}')
|
||||
|
||||
# Select variables to work with depending on tenant model
|
||||
model_variables = select_model_variables(tenant)
|
||||
tenant_info = tenant.to_dict()
|
||||
|
||||
current_app.logger.debug(f'ask_question: model_variables: {model_variables}')
|
||||
# Langchain debugging if required
|
||||
# set_debug(True)
|
||||
|
||||
set_debug(True)
|
||||
retriever = EveAIRetriever(model_variables)
|
||||
retriever = EveAIRetriever(model_variables, tenant_info)
|
||||
llm = model_variables['llm']
|
||||
template = model_variables['rag_template']
|
||||
language_template = create_language_template(template, language)
|
||||
@@ -141,7 +133,8 @@ def ask_question(tenant_id, question, language, session_id):
|
||||
current_app.logger.error(f'ask_question: Error saving interaction to database: {e}')
|
||||
raise
|
||||
|
||||
set_debug(False)
|
||||
# Disable langchain debugging if set above.
|
||||
# set_debug(False)
|
||||
|
||||
result['algorithm'] = current_app.config['INTERACTION_ALGORITHMS']['RAG_TENANT']['name']
|
||||
result['interaction_id'] = new_interaction.id
|
||||
|
||||
Reference in New Issue
Block a user