-
Notifications
You must be signed in to change notification settings - Fork 488
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
Add tools to api_server for InternLM2 model #1763
Conversation
Conflicts: lmdeploy/serve/openai/api_server.py
Pls fix the UT test error and the PR test error |
docs/en/serving/api_server.md
Outdated
} | ||
] | ||
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}] | ||
tool_choice={"type": "function", "function": {"name": "get_current_weather"}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we support tool_choice
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only supports none
or specifying a particular tool in json format.
@@ -434,10 +451,21 @@ async def chat_completions_v1(request: ChatCompletionRequest, | |||
stop_words=request.stop, | |||
skip_special_tokens=request.skip_special_tokens) | |||
|
|||
tools = None | |||
if request.tools and request.tool_choice != 'none': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we make error response to the client when request.tool_choice is not None?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made it in the check_request
function.
Do we support |
No, we did not yet. |
@Harold-lkk May help review this PR。 |
I got this prompt string if I used the code snippet in our doc.
And only internlm2-chat1_8b return the desired output:
|
It turns out that we have to pass |
@zhulinJulia24 we should add test cases for internlm2 function_call |
|
||
class ToolCall(BaseModel): | ||
"""Tool call response.""" | ||
id: str |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the openai spec, id
refers to "The ID of the tool call".
In my test, it increases by 1 automatically.
I view the id
as the index of the invoked tool in the tool list. But I am not sure about it.
@Harold-lkk, can you clarify it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT supports multi-function calls at the same time, so the id is used to identify which function call of the response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GPT supports multi-function calls at the same time, so the id is used to identify which function call of the response
Does that mean we have to return 0 for all requests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, we have to find out the index of the returned function in tools list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if two functions share the same name? Can it happen or do we have to consider this possibility? @Harold-lkk
The |
docs/en/serving/api_server_tools.md
Outdated
top_p=0.8, | ||
stream=False, | ||
tools=tools, | ||
extra_body={'skip_special_tokens': False}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we hide the extra_body
in the implementation instead of the API?
I don't find it in the openai API spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra_body is common when calling openai api. There are documentations in vllm too. https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html#extra-parameters
if request.tools and request.tool_choice != 'none': | ||
if request.stream is True: | ||
logger.warning('Set stream to False for tools') | ||
request.stream = False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why change it to False
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose it only supports stream=False. In streaming mode, how can client call the function? And it would be hard to extract content inside too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the client call the function when the finish_reason is tool_calls
?
There is warning for each request
I tried the |
@@ -173,6 +173,10 @@ for message in messages: | |||
print(item) | |||
``` | |||
|
|||
### Tools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to add the md file to index.rst
since pr #1880 is merged. May need to sync with main branch.
Conflicts: examples/vl/qwen_model.py examples/vl/xcomposer_model.py
@zhulinJulia24 may add TC |
Conflicts: lmdeploy/model.py
No description provided.