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

apply_chat_template api usage consult #1575

Open
FanZhang91 opened this issue Jul 22, 2024 · 0 comments
Open

apply_chat_template api usage consult #1575

FanZhang91 opened this issue Jul 22, 2024 · 0 comments

Comments

@FanZhang91
Copy link

FanZhang91 commented Jul 22, 2024

       ` environment: transformers=4.42.4, tokenizers=0.19.1`
        I want to use apply_chat_template interface to implement tools calling。 Using the tools parameter to pass in function information, but the return result of the `apply_chat_template `interface does not add input tools info to the generated prompt.
        how to fix this problem? Here is the code I used。
from transformers import AutoTokenizer

get_current_weather = {
  "type": "function",
  "function": {
    "name": "get_current_weather",
    "description": "Get the current weather in a given location.",
    "parameters": {
        "type": "object",
        "properties": {
          "location": {
            "type": "string",
            "description": "The city and state, e.g. San Francisco, CA",
          },
          "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
        },
        "required": ["location"],
      },
  }
}

messages = [
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "help me query currnet weather in San Francisco."},
    ]

tokenizer = AutoTokenizer.from_pretrained("xxxx/Qwen2-1.5B-Instruct")

prompt = tokenizer.apply_chat_template(
    messages,
    tools=[get_current_weather,],
    tokenize=False,
    add_generation_prompt=True,
)

print("prompt: ", prompt)
prompt:  <|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
help me query currnet weather in San Francisco.<|im_end|>
<|im_start|>assistant
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant