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

[Feature] add tool role in BaseChatTemplate as tool response in messages #2973

Closed
Huarong opened this issue Dec 30, 2024 · 0 comments
Closed
Assignees

Comments

@Huarong
Copy link

Huarong commented Dec 30, 2024

lmdeploy/lmdeploy/model.py

Lines 224 to 237 in 9c16443

box_map = dict(user=self.user,
assistant=self.assistant,
system=self.system)
eox_map = dict(user=self.eoh,
assistant=self.eoa + self.separator,
system=self.eosys)
ret = ''
if self.meta_instruction is not None and sequence_start:
if len(messages) and messages[0]['role'] != 'system':
ret += f'{self.system}{self.meta_instruction}{self.eosys}'
for message in messages:
role = message['role']
content = get_text(message['content'])
ret += f'{box_map[role]}{content}{eox_map[role]}'

request payload to /chat/completions endpoint

{
    "model": "xxxx",
    "messages": [
        {
            "role": "system",
            "content": "....”"
        },
        {
            "role": "user",
            "content": "吃了阿司匹林有什么副作用?"
        },
        {
            "role": "assistant",
            "content": "....."
        },
        {
            "role": "tool",
            "content": "..."
        }
    ],
    "max_tokens": 512,
    "stream": false,
    "temperature": 0.2,
    "top_p": 0.9,
    "user": "user-1234"
}

current error:

  File "/opt/lmdeploy/lmdeploy/serve/openai/api_server.py", line 483, in chat_completions_v1
    async for res in result_generator:
  File "/opt/lmdeploy/lmdeploy/serve/async_engine.py", line 524, in generate
    prompt_input = await self._get_prompt_input(prompt,
  File "/opt/lmdeploy/lmdeploy/serve/async_engine.py", line 455, in _get_prompt_input
    prompt = chat_template.messages2prompt(prompt,
  File "/opt/lmdeploy/lmdeploy/model.py", line 237, in messages2prompt
    ret += f'{box_map[role]}{content}{eox_map[role]}'
KeyError: 'tool'

The toolrole is in the OpenAI API document.

@Huarong Huarong changed the title feature: add tool role in BaseChatTemplate as tool response in messages [Feature] add tool role in BaseChatTemplate as tool response in messages Dec 30, 2024
@lvhan028 lvhan028 closed this as completed Jan 2, 2025
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

3 participants