Skip to content

Commit

Permalink
feat: add qwen2.5 no tool call prompt test
Browse files Browse the repository at this point in the history
  • Loading branch information
gaozixiang committed Nov 15, 2024
1 parent d6b76e2 commit 1c14724
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lmdeploy/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ def messages2prompt(self,
system=self.system)
ret = ''
tool_prompt = ''
if tools is not None:
if tools is not None and len(tools) > 0:
for tool in tools:
tool_prompt += self.separator
tool_prompt += f'{{"type": "function", "function": {json.dumps(tool, ensure_ascii=False)}}}'
Expand Down
22 changes: 22 additions & 0 deletions tests/test_lmdeploy/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,28 @@ def test_qwen2d5():
assert model.get_prompt(prompt, sequence_start=False) == prompt

model = MODELS.get('qwen2d5')(capability='chat')

# No tool call
messages = [
dict(role='user',
content='What\'s the temperature in San Francisco now?')
]
no_tool_prompt = ('<|im_start|>system\nYou are Qwen, created by Alibaba '
'Cloud. You are a helpful '
"assistant.<|im_end|>\n<|im_start|>user\nWhat's the "
'temperature in San Francisco '
'now?<|im_end|>\n<|im_start|>assistant\n')
assert model.messages2prompt(messages) == no_tool_prompt
assert model.messages2prompt(messages, tools=[]) == no_tool_prompt

messages.append({'role': 'assistant', 'content': 'I don\'t know.'})
no_tool_prompt = ('<|im_start|>system\nYou are Qwen, created by Alibaba '
'Cloud. You are a helpful '
"assistant.<|im_end|>\n<|im_start|>user\nWhat's the "
'temperature in San Francisco '
"now?<|im_end|>\n<|im_start|>assistant\nI don't "
'know.<|im_end|>\n<|im_start|>assistant\n')
assert model.messages2prompt(messages) == no_tool_prompt
# Single tool call
tools = [{
'name': 'get_current_temperature',
Expand Down

0 comments on commit 1c14724

Please sign in to comment.