Skip to content

Conversation

blancsw
Copy link

@blancsw blancsw commented Oct 6, 2025

Hello the Team !

Purpose

Add Apertus tool parser class

Fix Apertus jinja template to accept both tool call format (chat/completion and responses)

# Chat Completions API
{
  "type": "function",
  "function": {
    "name": "get_weather",
    "description": "Determine weather in my location",
    "strict": true,
    "parameters": {
      "type": "object",
      "properties": {
        "location": {
          "type": "string",
        },
      },
      "additionalProperties": false,
      "required": [
        "location",
        "unit"
      ]
    }
  }
}

# Responses API
{
  "type": "function",
  "name": "get_weather",
  "description": "Determine weather in my location",
  "parameters": {
    "type": "object",
    "properties": {
      "location": {
        "type": "string",
      },
    },
    "additionalProperties": false,
    "required": [
      "location",
      "unit"
    ]
  }
}

Test Plan

Test on swiss-ai/Apertus-70B-Instruct-2509 with 4xL40s with the base image docker.io/vllm/vllm-openai:v0.10.2
With and without streaming

Testing code:

@pytest.fixture()
def sample_tool_schema():
    return {
        "type": "function",
        "function": {
            "name": "calculate_sum",
            "description": "Calculate the sum of two numbers",
            "parameters": {
                "type": "object",
                "properties": {
                    "a": {"type": "number", "description": "First number"},
                    "b": {"type": "number", "description": "Second number"},
                },
                "required": ["a", "b"],
            },
        },
    }
    
@pytest.mark.order(3)
def test_tool_calling(get_client, sample_tool_schema):
    """Test tool calling functionality"""
    client, model, config = get_client
    if config["tool_calling"]:
        response = client.chat.completions.create(
            model=model,
            messages=[{"role": "user", "content": "Calculate the sum of 15 and 27"}],
            tools=[sample_tool_schema],
            max_tokens=300,
        )

        assert response is not None
        assert hasattr(response, "choices")
        assert len(response.choices) > 0
        choice = response.choices[0]

        # Check if tool was called
        assert choice.message.tool_calls
        tool_call = choice.message.tool_calls[0]
        assert tool_call.function.name == "calculate_sum"
        assert tool_call.function.arguments is not None
        args = json.loads(tool_call.function.arguments)
        assert "a" in args
        assert "b" in args
    else:
        pytest.skip(f"Model {model} does not support tool_calling functionality")

Test Result

Return the proper tool


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link

github-actions bot commented Oct 6, 2025

👋 Hi! Thank you for contributing to the vLLM project.

💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels.

Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors.

You ask your reviewers to trigger select CI tests on top of fastcheck CI.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can either: Add ready label to the PR or enable auto-merge.

If you have any questions, please reach out to us on Slack at https://slack.vllm.ai.

🚀

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ApertusToolParser for handling tool calls with Apertus models. The implementation covers both non-streaming and streaming responses. While the overall structure is good, I've found a critical bug in the streaming logic. The state of previously parsed tool calls is not consistently updated, which leads to dropping the initial parts of streamed tool arguments. I've provided a code suggestion to fix this issue. Once addressed, this will be a solid addition.

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@mergify mergify bot added the documentation Improvements or additions to documentation label Oct 7, 2025
Signed-off-by: swan.blanc <[email protected]>
Signed-off-by: swan.blanc <[email protected]>
Signed-off-by: swan.blanc <[email protected]>
Signed-off-by: swan.blanc <[email protected]>
@blancsw blancsw force-pushed the feat_add_apertus_tool_parser branch from 866c589 to 4ac6419 Compare October 7, 2025 13:57
@blancsw
Copy link
Author

blancsw commented Oct 7, 2025

Hi 🤗 @aarnphm / @chaunceyjiang my PR is ready, thanks in advance for your help !
Good AI day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation frontend tool-calling
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant