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

Add tools to api_server for InternLM2 model #1763

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

AllentDan
Copy link
Collaborator

No description provided.

@lvhan028
Copy link
Collaborator

Pls fix the UT test error and the PR test error

@lvhan028 lvhan028 added the enhancement New feature or request label Jun 13, 2024
@lvhan028 lvhan028 requested review from irexyc and lvhan028 June 20, 2024 20:42
}
]
messages = [{"role": "user", "content": "What's the weather like in Boston today?"}]
tool_choice={"type": "function", "function": {"name": "get_current_weather"}}
Copy link
Collaborator

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?

Copy link
Collaborator Author

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':
Copy link
Collaborator

@lvhan028 lvhan028 Jun 25, 2024

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?

Copy link
Collaborator Author

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.

@lvhan028
Copy link
Collaborator

Do we support "finish_reason": "tool_calls"?

@AllentDan
Copy link
Collaborator Author

Do we support "finish_reason": "tool_calls"?

No, we did not yet.

@AllentDan
Copy link
Collaborator Author

@Harold-lkk May help review this PR。

@lvhan028 lvhan028 requested a review from Harold-lkk June 25, 2024 06:16
@AllentDan
Copy link
Collaborator Author

I got this prompt string if I used the code snippet in our doc.

<|im_start|>system\nYou are an AI assistant whose name is InternLM (书生·浦语).\n- InternLM (书生·浦语) is a conversational language model that is developed by Shanghai AI Laboratory (上海人工智能实验室). It is designed to be helpful, honest, and harmless.\n- InternLM (书生·浦语) can understand and communicate fluently in the language chosen by the user such as English and 中文.\n<|im_end|>\n<|im_start|>system name=<|plugin|>\n[{"description": "Get the current weather in a given location", "name": "get_current_weather", "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"]}}]<|im_end|>\n<|im_start|>user\nWhat\'s the weather like in Boston today?<|im_end|>\n<|im_start|>assistant\n

And only internlm2-chat1_8b return the desired output:

ChatCompletion(id='1', choices=[Choice(finish_reason='tool_calls', index=0, logprobs=None, message=ChatCompletionMessage(content='', role='assistant', function_call=None, tool_calls=[ChatCompletionMessageToolCall(id='1', function=Function(arguments={'location': 'Boston'}, name='get_current_weather'), type='function')]))], created=1719306194, model='/nvme/shared_data/InternLM/internlm2-chat-1_8b', object='chat.completion', system_fingerprint=None, usage=CompletionUsage(completion_tokens=23, prompt_tokens=209, total_tokens=232))

@AllentDan
Copy link
Collaborator Author

It turns out that we have to pass skip_special_tokens=False in the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants