yvann-ba / Robby-chatbot

AI chatbot 🤖 for chat with CSV, PDF, TXT files 📄 and YTB videos 🎥 | using Langchain🦜 | OpenAI | Streamlit ⚡
MIT License
766 stars 287 forks source link

standalone question often translated into English, even the user using other language. how to aviod it? #31

Closed chinesewebman closed 1 year ago

chinesewebman commented 1 year ago

I modified _template and qa_template in chatbot.py, ask it to use specific language, but it still goes back to English after several conversations... how to avoid it? please let me know, thanks!

yvann-ba commented 1 year ago

Hi! I think one of the possible solutions would be to use FewShot PromptTemplate from Langchain. It allows you to give examples of conversations in the prompt to show the chatbot how to do it, maybe try putting examples where it answers in the same language as the user. Or else put a button to choose the language or the clicked language is added at the end of the user's prompt in "answer in french" . Or we could initialize the chat_history with bits of conversations where the chatbot answers in the same language as the user, it will serve as an example. I hope that these tracks can help you, do not hesitate to keep me informed

chinesewebman commented 1 year ago

many thanks!

jdwngdev commented 1 year ago

Does this method work? I am trying to make language dynamic too but with no success.

chinesewebman commented 1 year ago

in the new version or Robby it seems one template is missing, so I modified like this; ` cq_template = """"给定以下聊天历史和后续问题,如果后续问题是完整的句子,就原样将后续问题复制为独立问题,如果后续问题不是一个完整句子或完整问题,就参考聊天历史将其补全为独立问题。 聊天历史: {chat_history} 后续问题: {question} 独立问题:"""

CONDENSE_QUESTION_PROMPT = PromptTemplate.from_template(cq_template)

chain = ConversationalRetrievalChain.from_llm(llm=llm, retriever=retriever, condense_question_prompt=self.CONDENSE_QUESTION_PROMPT, verbose=True, return_source_documents=True, max_tokens_limit=4097, combine_docs_chain_kwargs={'prompt': self.QA_PROMPT}) chain_input = {"question": query, "chat_history": st.session_state["history"]} ` my code was heavy modified and it's in Chinese, so... sorry for can't request a PR for this.

chinesewebman commented 1 year ago

hi,

thank you for your creation, the Robby chatbot, I forked your project and modified it as my own needs... it's not perfect but maybe you will have the interests in part of it: Based on Robby chatbot, more features added: multiple files supports, you can choose which file you want to ask about (but I failed to switch the file name displyed in chatbox, so i removed the name in chatbox :) word files (.docx) supports local dictionary supports, if user query like "what is X", a local dict will be used in the first place to answer directly, this can avoid the hallucination of AI (the orignal dict file should be a .txt file, each phrase begin with a name following by a : and ended in ###) a custom moderation supports, it will analyze the altitude and topic, helps to maintain the converstaion in the way you specified ( the main reason is: I don't want the chatbot to commit it's wrong when user blames :) some details tune: token exceeds limitation bug fix, random spin text displaying during waiting the response from chatgpt, custom chunk_size, chunk seprator, and top_k, custom prompt with or without keywords, chunk score display and so on...

it's here: chinesewebman/doc-chatbot: A chatgpt bot �� with doc + dict + memory + custom moderator | chatgpt 聊天机器人,有内置词典、文档上下文、记忆、定制的内容审查 (github.com) almost all my modifications are in Chinese so I can't send a PR, sorry.

the chat history part messed up by me, I need to fix it later. the poor coding skill is an other reason that can't send a PR.

thank you again!

@.***

From: Yvann Date: 2023-05-08 15:55 To: yvann-hub/Robby-chatbot CC: chinesewebman; Author Subject: Re: [yvann-hub/Robby-chatbot] standalone question often translated into English, even the user using other language. how to aviod it? (Issue #31) Hi! I think one of the possible solutions would be to use FewShot PromptTemplate from Langchain. It allows you to give examples of conversations in the prompt to show the chatbot how to do it, maybe try putting examples where it answers in the same language as the user. Or else put a button to choose the language or the clicked language is added at the end of the user's prompt in "answer in french" . Or we could initialize the chat_history with bits of conversations where the chatbot answers in the same language as the user, it will serve as an example. I hope that these tracks can help you, do not hesitate to keep me informed Translated with www.DeepL.com/Translator (free version) — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>