mayooear / gpt4-pdf-chatbot-langchain

GPT4 & LangChain Chatbot for large PDF docs
https://www.youtube.com/watch?v=ih9PBGVVOO4
14.86k stars 3.01k forks source link

Ways to provide information to the chatbot. #421

Closed briannewtonpsyd closed 7 months ago

briannewtonpsyd commented 11 months ago

Hey all,

Fascinated by this project, and the potential here for large PDFs. I've successfully loaded in a few, and have had pretty good success querying or utilizing info from them. The particular application I'm using is not simply information retrieval, but using game sourcebooks to run me through a game.

The issue I'm running into, is that it simply will not accept input from me, it keeps acting like I'm trying to ask it to query the documents. For example, it will say, "What is your character's X skill?"

I will say, "My character's X is skill is 5" and it will reply, "I'm sorry, I don't have that information, what is your character's X skill?"

Is this something about the way the application is querying GPT4 or otherwise? GPT4 used directly seems to handle this quite easily and will integrate my answers and move forward with that information.

Thanks!

dosubot[bot] commented 11 months ago

🤖

Hello,

Thank you for your interest in the gpt4-pdf-chatbot-langchain project and for bringing this issue to our attention.

Based on your description, it seems like the chatbot is not maintaining the context of the conversation correctly. This could be due to how the chat history is being handled in the code.

In the gpt4-pdf-chatbot-langchain codebase, the chat history is maintained by storing the history of messages in the history array within the messageState object. This array is updated with each user question and corresponding AI response. When a user submits a question, the handleSubmit function updates the messages array with the user's question and sends a POST request to the '/api/chat' endpoint with the question and history as the request body. Once a response is received from the API, the messages array and history array are updated with the new AI response. The history array specifically is updated with a pair of the user's question and the AI's response.

Here is the relevant code:

setMessageState((state) => ({
  ...state,
  messages: [
    ...state.messages,
    {
      type: 'apiMessage',
      message: data.text,
      sourceDocs: data.sourceDocuments,
    },
  ],
  history: [...state.history, [question, data.text]],
}));

This updated history array is then passed in the next API call, allowing the chatbot to maintain context from the previous interactions.

If the chatbot is not maintaining the context correctly, it could be due to an issue with how the history array is being used in the '/api/chat' endpoint or how the AI response is being generated. It might be worth checking the server-side implementation of the chatbot to ensure it's properly using the chat history to maintain the context of the conversation.

If you could provide more information about the HumanMessage, AIMessage, and chain.call implementations, it would be easier to diagnose and fix the issue.

I hope this helps, and please let me know if you have any other questions or need further clarification.

Best, Dosu

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.

dosubot[bot] commented 8 months ago

Hi, @briannewtonpsyd

I'm helping the gpt4-pdf-chatbot-langchain team manage their backlog and am marking this issue as stale.

From what I understand, you raised an issue regarding the chatbot's inability to accept user input when providing information from large PDFs. In response, you received a detailed explanation from me about the chat history maintenance in the codebase and suggestions to check the server-side implementation of the chatbot. The issue has been resolved with the provided explanation and suggestions.

Could you please confirm if this issue is still relevant to the latest version of the gpt4-pdf-chatbot-langchain repository? If it is, please let the gpt4-pdf-chatbot-langchain team know by commenting on the issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you!