Skip to content

improve(autotest): replace APIClient with OpenAI SDK and strict param checks - #4887

Open
littlegy wants to merge 7 commits into
InternLM:mainfrom
littlegy:rm_apiclient
Open

improve(autotest): replace APIClient with OpenAI SDK and strict param checks#4887
littlegy wants to merge 7 commits into
InternLM:mainfrom
littlegy:rm_apiclient

Conversation

@littlegy

Copy link
Copy Markdown
Contributor

… checks

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

Please describe the motivation of this PR and the goal you want to achieve through this PR.

Modification

Please briefly describe what modification is made in this PR.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repositories?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@littlegy
littlegy marked this pull request as ready for review August 28, 2026 02:39
@lvhan028
lvhan028 requested a lite review from Copilot September 3, 2026 05:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

A few introduced helper behaviors can produce incorrect test outcomes or mask failures (notably completion-token capping and health-check success criteria).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR modernizes the RESTful autotest harness by migrating off the internal APIClient in favor of the OpenAI Python SDK (and newer Anthropic SDK patterns), while tightening request-parameter validation tests and making “large payload”/max_tokens tests more session-length aware.

Changes:

  • Replace lmdeploy.serve.openai.api_client.APIClient usage in multiple RESTful tests/utilities with OpenAI SDK calls and a shared get_client_and_model() helper.
  • Add stricter negative tests/assertions for invalid request parameters (HTTP 400 + OpenAI error envelope checks).
  • Introduce session-length-aware helpers for sizing prompts/payloads and capping max_tokens to avoid context overflows in follow-up tests.
File summaries
File Description
requirements/test.txt Bump Anthropic SDK minimum version to >=1.0.0 for updated SDK behavior.
autotest/utils/toolkit.py Extend encode_text() to support add_special_tokens control for token counting/ID generation.
autotest/utils/tool_reasoning_definitions.py Centralize client/model discovery by importing get_client_and_model().
autotest/utils/run_restful_chat.py Replace APIClient calls with OpenAI SDK and shared client/model helper; add helper for required server availability.
autotest/utils/restful_return_check.py Add OpenAI error-envelope assertion helper and session-length-aware payload/max_tokens sizing utilities.
autotest/utils/anthropic_messages.py Add anthropic_extra_body() helper and use shared model discovery for Anthropic SDK setup.
autotest/interface/restful/tool_parser/test_tool_call_anthropic_sdk.py Replace APIClient model lookup with cached deployed model name via shared helper; adapt SDK calls using extra_body.
autotest/interface/restful/tool_parser/test_tool_call_advanced.py Use session-length-aware max_tokens capping for routed-experts follow-up regression test.
autotest/interface/restful/test_restful_generate.py Tighten expected status codes and use session-length-aware max_tokens capping; replace server-side encoding dependency for stop token IDs.
autotest/interface/restful/test_restful_completions_v1.py Migrate to OpenAI SDK, add raw HTTP negative tests for invalid params with OpenAI error-envelope assertions.
autotest/interface/restful/test_restful_chat_completions_v1.py Large refactor: migrate to OpenAI SDK, add strict invalid-param negative tests, and session-length-aware oversize payload generation.
autotest/interface/restful/test_restful_anthropic_v1.py Use shared session-sized payload builder for “large payload” regression guard and shared model discovery.
autotest/interface/restful/test_restful_anthropic_sdk_messages.py Update Anthropic SDK calls to pass unsupported fields via extra_body.
Review details
  • Files reviewed: 13/13 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +303 to +307
session_len = resolve_effective_session_len(config, model_id)
model_path = get_model_path_from_config(config, model_id)
prompt_tokens = len(encode_text(model_path, prompt_text, add_special_tokens=False))
available = session_len - prompt_tokens - reserve
return min(default_cap, max(min_cap, available))
messages=[{'role': 'user', 'content': '你好'}],
extra_body={'top_k': 1},
)
return model_name == model_name_current and response.choices is not None
Comment on lines +252 to +256
try:
client, model_name = get_client_and_model(url)
except Exception:
assert False, 'server not start correctly'
return client, model_name, model_name.split('/')[-1]
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

Successfully merging this pull request may close these issues.

2 participants