Combining simple chat agent with ConversationalRetrievalChain #9158
Replies: 1 comment 3 replies
-
🤖 Hello, Yes, it is indeed possible to combine a simple chat agent that answers user questions with a document retrieval chain for specific inquiries from your documents in the LangChain framework. Based on the similar issues and solutions found in the LangChain repository, you can achieve this by using the # Get the answer from the documents
embeddings = OpenAIEmbeddings()
vectordb = Chroma(embedding_function=embeddings, persist_directory=directory)
qa_chain = ConversationalRetrievalChain.from_llm(ChatOpenAI(model_name="gpt-3.5-turbo", temperature=0.3), vectordb.as_retriever(), memory=memory)
answer = (qa_chain({"question": query}))
# Modify the tone using OpenAI's ChatCompletion
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful and friendly chatbot who converts text to a very friendly tone."},
{"role": "user", "content": f"{answer}"}
]
) In this example, you first retrieve the answer from the documents using For creating a simple chat agent, you can use the from langchain.agents.agent_toolkits import create_pbi_chat_agent, create_conversational_retrieval_agent
# Create a chat agent
chat_agent = create_pbi_chat_agent()
# Create a document retrieval agent
retrieval_agent = create_conversational_retrieval_agent()
# Combine the two agents
def combined_agent(user_input):
# First, try to answer the question using the chat agent
chat_response = chat_agent.get_response(user_input)
if chat_response is not None:
return chat_response
# If the chat agent can't answer, try the retrieval agent
retrieval_response = retrieval_agent.get_response(user_input)
if retrieval_response is not None:
return retrieval_response
# If neither agent can answer, return a default response
return "I'm sorry, I don't know the answer to that." In this example, the I hope this helps! If you have any further questions or need more clarification, feel free to ask. Best, Sources
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant. If you want to continue the conversation, start your reply with @dosu-bot. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hey guys i want to try combining a simple agent that just chats with user and answers question with a document retrieval chain, This chain is for when i ask about something specific from my documents. Is this possible ?
Beta Was this translation helpful? Give feedback.
All reactions