Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用llamafactory-cli api启动llama3.1-70b-Instruct模型,在dify中应用,模型失去function call能力 #6056

Open
1 task done
limusen75 opened this issue Nov 17, 2024 · 1 comment
Labels
pending This problem is yet to be addressed

Comments

@limusen75
Copy link

Reminder

  • I have read the README and searched the existing issues.

System Info

启动环境不存在问题,模型可以正常启动推理

Reproduction

将模型注册到dify中,llama3.1-70b-Instruct是支持function call的,在dify中选择模型支持function call,在dify中应用的时候模型不会调用工具;在dify中选择模型不支持function call,在dify中应用的时候模型会react的形式调用工具。

Expected behavior

请问llamafactory-cli api启动的模型是不支持function call吗?还是我参数没写对?llamafactory支持与dify集成吗?

Others

No response

@github-actions github-actions bot added the pending This problem is yet to be addressed label Nov 17, 2024
@Melancholy495
Copy link

Melancholy495 commented Nov 25, 2024

llama3.1是支持Function call的,如果模型调用了工具,最后stop的Special token应该是<|eom_id|>,对应id为128008,而普通的stop的Special token是<|eot_id|>,对应的是128009。可以通过最后一个token来判断是否为tool_call,如果是tool_call,最后的response应该直接是一个json字符串,可以直接解析。
如下图:

image

示例(包含prompt和Special tokens)(这里的prompt都是tokenizer.apply_chat_template()拿到的):

<|begin_of_text|><|start_header_id|>system<|end_header_id|>

Environment: ipython
Cutting Knowledge Date: December 2023
Today Date: 26 Jul 2024

You are a bot that responds to weather queries.<|eot_id|><|start_header_id|>user<|end_header_id|>

Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.

Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}.Do not use variables.

{{Functions}}

Hey, what's the temperature in Paris right now?<|eot_id|><|start_header_id|>assistant<|end_header_id|>

{"name": "get_current_temperature", "parameters": {"unit": "celsius", "location": "Paris, France"}}<|eom_id|>

但是,llamafactory是通过加入prompt让模型生成相应格式的字符,再进行解析。
而且llamafactory的template和通过tokenizer.apply_chat_template()得到的文本不同

DEFAULT_TOOL_PROMPT = ( "You have access to the following tools:\n{tool_text}" "Use the following format if using a tool:\n" "```\n" "Action: tool name (one of [{tool_names}])\n" "Action Input: the input to the tool, in a JSON format representing the kwargs " """(e.g. ```{{"input": "hello world", "num_beams": 5}}```)\n""" "```\n" )

这种方式可能就解析不到可能的tool_call,因为llama3.1的tool_call返回的本来就应该是一个json格式的以<|eom_id|>结束的字符串,而不是“action: action input”形式。

但是我现在也不知道怎么把这个改进llamafactory里边(或许可以把default tool prompt改成tokenizer.apply_chat_template()里边的prompt,直接让它输出json字符,然后直接解析,能解析成功就是tool_call,但是改代码好痛苦)。

希望能帮到你

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pending This problem is yet to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants