Langchain-Chatchat icon indicating copy to clipboard operation
Langchain-Chatchat copied to clipboard

知识库问答Prompt指令不生效

Open zixiaotan21 opened this issue 2 years ago • 8 comments

问题描述 / Problem Description 在prompt中要求不得编造内容,但是在知识库回答过程中,虽然找到了正确的答案相关文档,大模型仍然根据自身能力编造答案

**复现问题的步骤

  1. 在config/prompt_config.py设置如下:
  "knowledge_base_chat": {
        "default":
            '<指令>根据已知信息,简洁和专业的来回答问题。如果无法从中得到答案,请说 “根据已知信息无法回答该问题”,'
            '不允许在答案中添加编造成分,答案请使用中文。 </指令>\n'
            '<已知信息>{{ context }}</已知信息>\n'
            '<问题>{{ question }}</问题>\n',

        "text":
            '<指令>严格按照已知信息回答问题,不得添加任何编造内容。如果无法从已知信息中得到答案,请说明“根据已知信息无法回答该问题”。 </指令>\n'
            '<已知信息>{{ context }}</已知信息>\n'
            '<问题>{{ question }}</问题>\n',

预期的结果 / Expected Result 提问:原产地证书自助打印流程 知识库中答案为:

  1. 制作印章签名。
  2. 进行印章签名授权。
  3. 新建证书。
  4. 下载并安装打印控件。
  5. 设置彩色打印机为默认打印机。
  6. 打印证书。

实际结果 / Actual Result 虽然prompt里面写了”不得添加任何编造内容“,但回答的时候还是会在答案的基础上,加入大模型自身生成的内容。

环境信息 / Environment Information angchain-ChatGLM 版本/commit 号:v0.2.10 是否使用 Docker 部署(是/否):否 使用的模型(ChatGLM2-6B / Qwen-7B 等):Qwen-1.5-14B-chat 使用的 Embedding 模型(moka-ai/m3e-base 等):bge-large-zh-v1.5 使用的向量库类型 (faiss / milvus / pg_vector 等): faiss 操作系统及版本 / Operating system and version: :Windows-10-10.0.22631-SP0. Python 版本 / Python version: :3.10.8 其他相关环境信息 / Other relevant environment information:

zixiaotan21 avatar Apr 25 '24 06:04 zixiaotan21

您遇到的问题可能是由于几个原因导致的,即使您已经在prompt中明确指定了不要添加任何编造的内容。首先,模型可能并不总是能够完全按照prompt的字面意思来理解和执行指令。其次,即使设计了严格的prompt,模型可能仍然会生成一些额外的内容,因为它试图提供完整或富有上下文的回答。此外,语言模型的固有行为和它们的训练数据也可能导致它们在尝试遵守特定指令时生成额外的内容。

关于这个问题,您可以参考两个类似的已关闭问题[BUG] 使用知识库问答时没有用到知识库的内容,而且提问知识库之外的内容会得到一个“编造“的答案[BUG]知识库问答没有用到知识库内容,提问知识库之外的内容会得到一个”编造“的回答。这些问题的讨论可能为您提供一些见解。

Langchain-Chatchat应用中的一些配置或设置,如模型选择、温度设置、prompt模板和详细模式等,也可能影响模型对prompt指令的遵守。您可以通过调整这些设置来尝试改善问题。相关的配置信息可以在这个文件中找到。

希望这些建议能帮助您解决遇到的问题。如果您有任何其他问题或需要进一步的帮助,请随时告诉我。

Details

Sources


About Dosu 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.

To continue the conversation, mention @dosu.

dosubot[bot] avatar Apr 25 '24 06:04 dosubot[bot]

@dosu

按照你的意思,即便我已经在prompt中明确指定了不要添加任何编造的内容,根据大模型的原理,它还是会生成一些额外的内容,对吗?

zixiaotan21 avatar Apr 25 '24 07:04 zixiaotan21

Yes, that's correct. Even with explicit instructions in the prompt configuration to avoid adding any fabricated content, the model might still generate additional content. This behavior is due to the model's design to generate responses based on learned patterns during training, which may not always perfectly align with specific instructions given in the prompt configuration.

To address this, you can adjust the prompt templates within the config/prompt_config.py file to guide the model's responses more closely according to the desired instructions. This involves refining the text and structure of the prompts to ensure the model's outputs align more strictly with your requirements.

The Langchain-Chatchat model, including configurations for languages other than English, allows for the customization of prompts in various contexts, such as language model conversations and knowledge base interactions. This customization capability is designed to adapt the model's responses according to the context specified in the configuration file, enabling it to follow instructions provided in different languages, including Chinese.

It's important to note that the effectiveness of these instructions depends on the model's ability to understand and adhere to them, which can vary. Adjusting the settings related to model selection, temperature settings, prompt templates, and detailed modes might help improve adherence to the prompt instructions.

Details

Sources


About Dosu 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.

To continue the conversation, mention @dosu.

dosubot[bot] avatar Apr 25 '24 07:04 dosubot[bot]

使用量化模型时,常会出现这个幻象,可能跟量化时设置有关。如果使用ollama上的模型,同样是4-bit的,不会出现乱七八糟的内容。

hanwsf avatar Apr 29 '24 19:04 hanwsf

使用量化模型时,常会出现这个幻象,可能跟量化时设置有关。如果使用ollama上的模型,同样是4-bit的,不会出现乱七八糟的内容。

好的,谢谢建议!我尝试一下ollama模型,看看效果会不会好些。想问问langchain chatchat 支持用ollama 本地部署吗?我看了一下issue #3492 和 #3368 ,应该改改代码之后是可以的~

zixiaotan21 avatar Apr 30 '24 01:04 zixiaotan21

使用量化模型时,常会出现这个幻象,可能跟量化时设置有关。如果使用ollama上的模型,同样是4-bit的,不会出现乱七八糟的内容。

想请教一下,你使用的是ollama上的什么模型呀,有推荐的吗?我试了一下qwen:14b,效果不太好,幻象有点严重。

zixiaotan21 avatar Apr 30 '24 06:04 zixiaotan21

ollama本地或docker启动,ollama pull llama3 或deepseek-llm,在model_config.py中选择列表中加上,同时online llm中加上ollama的OLLAMA_BASE_URL (http://127.0.0.1:11434)

llama3 要每次提醒他用简体中文回答,或设置在prompt中

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年04月30日 09:12 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [chatchat-space/Langchain-Chatchat] 知识库问答Prompt指令不生效 (Issue #3877) |

使用量化模型时,常会出现这个幻象,可能跟量化时设置有关。如果使用ollama上的模型,同样是4-bit的,不会出现乱七八糟的内容。

好的,谢谢建议!我尝试一下ollama模型,看看效果会不会好些。想问问langchain chatchat 支持用ollama 本地部署吗?我看了一下issue #3492 和 #3368 ,应该改改代码之后是可以的~

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

hanwsf avatar May 01 '24 03:05 hanwsf

ollama本地或docker启动,ollama pull llama3 或deepseek-llm,在model_config.py中选择列表中加上,同时online llm中加上ollama的OLLAMA_BASE_URL (http://127.0.0.1:11434)

llama3 要每次提醒他用简体中文回答,或设置在prompt中

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年04月30日 09:12 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [chatchat-space/Langchain-Chatchat] 知识库问答Prompt指令不生效 (Issue #3877) |

使用量化模型时,常会出现这个幻象,可能跟量化时设置有关。如果使用ollama上的模型,同样是4-bit的,不会出现乱七八糟的内容。

好的,谢谢建议!我尝试一下ollama模型,看看效果会不会好些。想问问langchain chatchat 支持用ollama 本地部署吗?我看了一下issue #3492 和 #3368 ,应该改改代码之后是可以的~

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

好的好的,我再尝试看看,感谢分享!

zixiaotan21 avatar May 01 '24 04:05 zixiaotan21

问下楼主用ollama之后,现在大模型还有幻想和根据文档编造内容的现象吗

TC10127 avatar May 22 '24 02:05 TC10127

问下楼主用ollama之后,现在大模型还有幻想和根据文档编造内容的现象吗

我最近没有在用ollama了哈哈哈,不太清楚现在会不会效果好些。我当时用的时候,感觉效果比我下载ollama之前,单独使用qwen或者chatglm的效果还差,确实会有很多幻觉,而且会barabara说个不停~

zixiaotan21 avatar May 22 '24 03:05 zixiaotan21

就还是没有langchain chatchat直接加载模型回答的好吗?那现在有没有什么好的办法解决这个问题的?🙏

TC10127 avatar May 22 '24 04:05 TC10127

就还是没有langchain chatchat直接加载模型回答的好吗?那现在有没有什么好的办法解决这个问题的?🙏

对,感觉ollama 的效果似乎没有langchain chatchat 直接加载模型效果好。 我在ollama 上下的是qwen-14b, 也用过langchain 单独加载qwen-14b-chat跑过,不知道是不是这两个版本不一样的问题。 我暂时还没找到好的方法哈哈哈,有新的进展随时交流呀~

zixiaotan21 avatar May 22 '24 09:05 zixiaotan21

我的实践是:使用ollama 库中已有的一点问题没有。自己下载gguf等,要非常仔细的配template, parameter, system 等,稍微哪里没设对,轻者偶尔蹦出莫名其妙的,重者像个神经病。不受控制的输出是因为stop没有设置对

---- 回复的原邮件 ---- | 发件人 | @.> | | 日期 | 2024年05月22日 17:55 | | 收件人 | @.> | | 抄送至 | @.>@.> | | 主题 | Re: [chatchat-space/Langchain-Chatchat] 知识库问答Prompt指令不生效 (Issue #3877) |

就还是没有langchain chatchat直接加载模型回答的好吗?那现在有没有什么好的办法解决这个问题的?🙏

对,感觉ollama 的效果似乎没有langchain chatchat 直接加载模型效果好。 我在ollama 上下的是qwen-14b, 也用过langchain 单独加载qwen-14b-chat跑过,不知道是不是这两个版本不一样的问题。 我暂时还没找到好的方法哈哈哈,有新的进展随时交流呀~

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you commented.Message ID: @.***>

hanwsf avatar May 23 '24 00:05 hanwsf

我的 langchain chatchat 修改了根本不生效 我说 你的省份是AI大模型 他回答还说 我是阿里大模型 感觉没有用到 config/prompt_config.py 文件

297106271 avatar Jun 20 '24 08:06 297106271