dify 文本生成器内部提示完成错误

ntjbwcob  于 2个月前  发布在  其他
关注(0)|答案(2)|浏览(33)

自我检查

  • 这仅用于报告错误,如果您想提问,请访问 Discussions
  • 我已在现有问题中搜索 search for existing issues ,包括已关闭的问题。
  • 我确认我使用英文提交此报告(我已阅读并同意 Language Policy )。
  • 请务必使用英文提交问题,否则会被关闭。谢谢!:)
  • 请不要修改此模板 :) 并填写所有必填字段。

Dify版本

0.6.13

云或自托管

自托管(Docker)

重现步骤

当大型模型类型是连续大型模型时,内置提示词组装中的错误导致大型模型异常返回。重现步骤:

  1. 将 codeqwen1.5 添加为代码连续大型模型。
  2. 添加一个文本生成应用程序,将 codeqwen1.5 选择为代码连续大型模型。
  3. 将提示词设置为:<fim_prefix>{{code_pre}}<fim_suffix>{{code_sur}}<fim_middle>
  4. 为 code_pre 和 code_sur 输入任何文本,点击生成,大型模型收到的提示词将变为:
    <fim_prefix>xxxxxx<fim_suffix>xxxxxxx<fim_middle>

{{#query#}}
原因:
在 core\prompt\simple_prompt_transform.py 文件中,get_prompt_template 方法在组装提示词时存在逻辑错误。当类型为 COMPLETION 或 WORKFLOW 时,没有查询变量,但仍然连接了
和 {{#query#}}。

✔️ 预期行为

正确的提示应该是:
<fim_prefix>xxxxxx<fim_suffix>xxxxxxx<fim_middle>

❌ 实际行为

大型模型收到的提示是:
<fim_prefix>xxxxxx<fim_suffix>xxxxxxx<fim_middle>
{{#query#}}

wwtsj6pe

wwtsj6pe1#

要解决Dify版本0.6.13中core\prompt\simple_prompt_transform.py方法在codeqwen1.5模型的提示中错误地将\n{{#query#}}附加到codeqwen1.5的问题,您需要修改get_prompt_template方法以专门处理codeqwen1.5模型。以下是更新后的代码:

def get_prompt_template(self, app_mode: AppMode,
provider: str,
model: str,
pre_prompt: str,
has_context: bool,
query_in_prompt: bool,
with_memory_prompt: bool = False) -> dict:
prompt_rules = self._get_prompt_rule(
app_mode=app_mode,
provider=provider,
model=model
)

    custom_variable_keys = []
    special_variable_keys = []

    prompt = ''
    for order in prompt_rules['system_prompt_orders']:
        if order == 'context_prompt' and has_context:
            prompt += prompt_rules['context_prompt']
            special_variable_keys.append('#context#')
        elif order == 'pre_prompt' and pre_prompt:
            prompt += pre_prompt + '\n'
            pre_prompt_template = PromptTemplateParser(template=pre_prompt)
            custom_variable_keys = pre_prompt_template.variable_keys
        elif order == 'histories_prompt' and with_memory_prompt:
            prompt += prompt_rules['histories_prompt']
            special_variable_keys.append('#histories#')

    if query_in_prompt:
        if model == 'codeqwen1.5':
            prompt += prompt_rules.get('query_prompt', '{{#query#}}').replace('\n{{#query#}}', '{{#query#}}')
        else:
            prompt += prompt_rules.get('query_prompt', '{{#query#}}')
        special_variable_keys.append('#query#')

    return {
        "prompt_template": PromptTemplateParser(template=prompt),
        "custom_variable_keys": custom_variable_keys,
        "special_variable_keys": special_variable_keys,
        "prompt_rules": prompt_rules
    }

此修改确保不会将`\n{{#query#}}`附加到`codeqwen1.5`模型的提示中,从而防止异常返回[[1]](https://github.com/langgenius/dify/blob/main/api/core/prompt/simple_prompt_transform.py)。

* 要继续与[Dosu](https://dosu.dev)交谈,请提及@dosu。*
8wigbo56

8wigbo562#

请随时提交一个pull request。:)

相关问题