Variables for rag_context and fallback algorithms added to Tenant and parts of the implementation.

This commit is contained in:
Josako
2024-06-13 15:23:35 +02:00
parent cbddaee810
commit b77e1ab321
6 changed files with 63 additions and 17 deletions

View File

@@ -21,7 +21,7 @@ from common.models.user import Tenant
from common.models.interaction import ChatSession, Interaction, InteractionEmbedding
from common.extensions import db
from common.utils.celery_utils import current_celery
from common.utils.model_utils import select_model_variables, create_language_template
from common.utils.model_utils import select_model_variables, create_language_template, replace_variable_in_template
from common.langchain.EveAIRetriever import EveAIRetriever
from common.langchain.EveAIHistoryRetriever import EveAIHistoryRetriever
@@ -31,7 +31,8 @@ def detail_question(question, language, model_variables, session_id):
llm = model_variables['llm']
template = model_variables['history_template']
language_template = create_language_template(template, language)
history_prompt = ChatPromptTemplate.from_template(language_template)
full_template = replace_variable_in_template(language_template, "{tenant_context}", model_variables['rag_context'])
history_prompt = ChatPromptTemplate.from_template(full_template)
setup_and_retrieval = RunnableParallel({"history": retriever,"question": RunnablePassthrough()})
output_parser = StrOutputParser()
@@ -103,7 +104,8 @@ def ask_question(tenant_id, question, language, session_id):
llm = model_variables['llm']
template = model_variables['rag_template']
language_template = create_language_template(template, language)
rag_prompt = ChatPromptTemplate.from_template(language_template)
full_template = replace_variable_in_template(language_template, "{tenant_context}", model_variables['rag_context'])
rag_prompt = ChatPromptTemplate.from_template(full_template)
setup_and_retrieval = RunnableParallel({"context": retriever, "question": RunnablePassthrough()})
new_interaction_embeddings = []