Using agent chain and gpt turbo model is returning multiple follow up question and answer

I am struggling to find out why this is happening. I followed the example in the attached link

# https://python.langchain.com/en/latest/modules/memory/examples/adding_memory_chain_multiple_inputs.html
template = """
- You are a chatbot named Botty having a conversation with a human.
- Your name is Botty.
- You have to be friendly.
- You are talking to a human.
- You NEVER answer that your are an AI language model.
- If you don't know the answer truthfully say you don't have an answer. Don't try to make up an answer.
- Always reply in the same language you are being asked.

Given the following extracted parts of a long document and a question, create a final answer.

{context}

{chat_history}
Human: {question}
Chatbot:"""

prompt = PromptTemplate(
    input_variables=["chat_history", "question", "context"], 
    template=template
)
session_id = 'UNIQUE FOR CLIENT SESSION OR SIMPLY CLIENT'
message_history = RedisChatMessageHistory(url=redisUrl, ttl=600, session_id=session_id)
memory = ConversationBufferMemory(memory_key="chat_history", chat_memory=message_history, input_key="question")
agent_chain = load_qa_chain(llm, chain_type="stuff", memory=memory, prompt=prompt)
search_index = FAISS.load_local(local_folder, OpenAIEmbeddings())
response = agent_chain(
    {
        "input_documents": search_index.similarity_search(query, k=1),
        "question": query,
    },
    return_only_outputs=True,
)

When I run this, I get the answer but along with it multiple Human: Chatbot: messages rephrasing the question. It looks like gpt turbo is not only answering the question, it is also sending additional human and chatbot conversation which I need only when I ask follow up questions. How do I stop gpt giving follow up questions ?

You can enter Human: as a stop sequence.

You can also prompt “end your answer with stopsign emoji” and then add that emoji as a stop sequence.
https://help.openai.com/en/articles/5072263-how-do-i-use-stop-sequences

1 Like

Thanks a lot. Let me try it and will share my findings