Skip to content

Commit

Permalink
Revert "feat(chat): Add follow up questions functionality" (#2246)
Browse files Browse the repository at this point in the history
Reverts #2241
  • Loading branch information
StanGirard authored Feb 22, 2024
1 parent 44312dc commit 81072b3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 0 additions & 2 deletions backend/modules/brain/knowledge_brain_qa.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ def __init__(
brain_id=brain_id,
chat_id=chat_id,
streaming=streaming,
max_input=self.max_input,
max_tokens=self.max_tokens,
**kwargs,
)

Expand Down
30 changes: 15 additions & 15 deletions backend/modules/brain/rags/quivr_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,14 @@
from langchain.chains import ConversationalRetrievalChain
from langchain.embeddings.ollama import OllamaEmbeddings
from langchain.llms.base import BaseLLM
from langchain.memory import ConversationBufferMemory
from langchain.prompts import HumanMessagePromptTemplate
from langchain.schema import format_document
from langchain_community.chat_models import ChatLiteLLM
from langchain_core.messages import SystemMessage
from langchain_core.messages import SystemMessage, get_buffer_string
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import (
ChatPromptTemplate,
MessagesPlaceholder,
PromptTemplate,
)
from langchain_core.runnables import RunnablePassthrough
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
from langchain_core.runnables import RunnableLambda, RunnablePassthrough
from langchain_openai import OpenAIEmbeddings
from llm.utils.get_prompt_to_use import get_prompt_to_use
from logger import get_logger
Expand Down Expand Up @@ -56,7 +53,6 @@
"When answering use markdown or any other techniques to display the content in a nice and aerated way. Use the following pieces of context from files provided by the user to answer the users question in the same language as the user question. Your name is Quivr. You're a helpful assistant. If you don't know the answer with the context provided from the files, just say that you don't know, don't try to make up an answer."
)
),
MessagesPlaceholder(variable_name="chat_history", optional=False),
HumanMessagePromptTemplate.from_template(template_answer),
]
)
Expand Down Expand Up @@ -205,17 +201,23 @@ def get_retriever(self):

def get_chain(self):
retriever_doc = self.get_retriever()
memory = ConversationBufferMemory(
return_messages=True, output_key="answer", input_key="question"
)

loaded_memory = RunnablePassthrough.assign(
chat_history=RunnableLambda(memory.load_memory_variables)
| itemgetter("history"),
)

_inputs = RunnablePassthrough()
standalone_question = {
"standalone_question": {
"question": itemgetter("question"),
"chat_history": itemgetter("chat_history"),
"question": lambda x: x["question"],
"chat_history": lambda x: get_buffer_string(x["chat_history"]),
}
| CONDENSE_QUESTION_PROMPT
| ChatLiteLLM(temperature=0, model=self.model)
| StrOutputParser(),
"chat_history": itemgetter("chat_history"),
}

prompt_custom_user = self.prompt_to_use()
Expand All @@ -228,14 +230,12 @@ def get_chain(self):
"docs": itemgetter("standalone_question") | retriever_doc,
"question": lambda x: x["standalone_question"],
"custom_instructions": lambda x: prompt_to_use,
"chat_history": itemgetter("chat_history"),
}

final_inputs = {
"context": lambda x: self._combine_documents(x["docs"]),
"question": itemgetter("question"),
"custom_instructions": itemgetter("custom_instructions"),
"chat_history": itemgetter("chat_history"),
}

# And finally, we do the part that returns the answers
Expand All @@ -246,4 +246,4 @@ def get_chain(self):
"docs": itemgetter("docs"),
}

return _inputs | standalone_question | retrieved_documents | answer
return loaded_memory | standalone_question | retrieved_documents | answer
2 changes: 1 addition & 1 deletion backend/modules/chat/dto/chats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from modules.chat.dto.outputs import GetChatHistoryOutput
from modules.notification.entity.notification import Notification
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict


class ChatMessage(BaseModel):
Expand Down

0 comments on commit 81072b3

Please sign in to comment.