【BugFix】Fix the support issue for IPv6#186
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a bug where Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly adds support for IPv6 addresses in host_ip and updates the documentation accordingly. However, the implementation has a critical bug where it fails to handle hostnames other than localhost, which will cause a ValueError. I've provided a code suggestion to fix this by using a try-except block to gracefully handle hostnames. I've also recommended adding a unit test for generic hostnames to improve test coverage and prevent future regressions.
| kwargs = self.default_kwargs.copy() | ||
| kwargs["host_ip"] = "localhost" | ||
| model = self.model_class(**kwargs) | ||
| self.assertEqual(model._get_base_url(), "http://localhost:8000/") |
There was a problem hiding this comment.
The new tests cover localhost, but they don't cover other hostnames (e.g., example.com). The current implementation in base_api.py would fail for such hostnames. It's good practice to add a test case for this scenario to prevent future regressions.
I recommend adding another test case for a generic hostname:
def test_get_base_url_with_generic_hostname(self):
kwargs = self.default_kwargs.copy()
kwargs["host_ip"] = "my-service.local"
model = self.model_class(**kwargs)
self.assertEqual(model._get_base_url(), "http://my-service.local:8000/")Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
| if isinstance(ip, ipaddress.IPv6Address): | ||
| host = f"[{ip}]" | ||
| except ValueError: | ||
| # Not an IP address, so it's a hostname. Use it as is. |
There was a problem hiding this comment.
[review] we should add warning to user
There was a problem hiding this comment.
The IP address format issue is verified and a message is displayed during model building. The value error here is caused only by the "localhost" address, and no additional log message is required.
There was a problem hiding this comment.
Pull request overview
This PR fixes URL construction for service-based API model backends so host_ip works correctly with IPv6 literals (bracketed in URLs), and updates docs/tests accordingly.
Changes:
- Update
BaseAPIModel._get_base_url()to detect IPv6 literals viaipaddress.ip_address()and wrap them in[]when buildingbase_url. - Add unit tests covering IPv6 (
::1) and hostname (localhost)host_ipbehaviors. - Update EN/ZH docs to clarify IPv6
host_ipsupport and bracketed URL generation.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| ais_bench/benchmark/models/api_models/base_api.py | Make base URL building IPv6-aware by bracket-wrapping IPv6 literals. |
| tests/UT/models/api_models/test_base_api.py | Add tests for IPv6 base URL construction and hostname compatibility. |
| docs/source_zh_cn/base_tutorials/all_params/models.md | Document IPv6 host_ip support and bracket behavior (ZH). |
| docs/source_en/base_tutorials/all_params/models.md | Document IPv6 host_ip support and bracket behavior (EN). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| | `retry` | Int | Maximum number of retries after failing to connect to the server. Valid range: [0, 1000] | | ||
| | `api_key` | String | Custom API key, default is an empty string. Only supports the `VLLMCustomAPI` and `VLLMCustomAPIChat` model type. | | ||
| | `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1` | | ||
| | `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` | |
There was a problem hiding this comment.
This parameter description now says “Server IP address” and only mentions IPv4/IPv6 literals, but the tool also supports hostname values (at least localhost, and the implementation falls back to treating any non-IP string as a hostname). Consider updating the wording to “host/IP” and explicitly stating which hostname forms are supported, so users don’t assume hostnames are invalid.
| | `host_ip` | String | Server IP address, supporting valid IPv4 or IPv6, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` | | |
| | `host_ip` | String | Server host/IP address. Supports hostnames such as `localhost` and other DNS-resolvable hostnames, as well as valid IPv4 or IPv6 literals, e.g., `127.0.0.1`, `::1`. When using an IPv6 literal, the tool automatically wraps it in brackets when building URLs, for example: `http://[::1]:8080/` | |
| | `retry` | Int | 连接服务端失败后的最大重试次数。合法范围:[0, 1000] | | ||
| | `api_key` | String | 自定义API key,默认是空字符串。仅支持 `VLLMCustomAPI` 和 `VLLMCustomAPIChat` 模型类型。 | | ||
| | `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 或 IPv6,例如:`127.0.0.1` | | ||
| | `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 或 IPv6,例如:`127.0.0.1`、`::1`。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` | |
There was a problem hiding this comment.
这里将 host_ip 描述为“IP 地址”且仅强调 IPv4/IPv6 字面量,但实际使用中也支持主机名(至少 localhost,实现也会把非 IP 字符串按 hostname 处理)。建议将描述改为“主机名或 IP”,并明确哪些 hostname 形式被支持,避免用户误解。
| | `host_ip` | String | 服务端 IP 地址,支持合法 IPv4 或 IPv6,例如:`127.0.0.1`、`::1`。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` | | |
| | `host_ip` | String | 服务端主机名或 IP 地址,支持主机名(如 `localhost`)以及合法 IPv4 / IPv6 字面量,例如:`127.0.0.1`、`::1`。非 IP 字符串将按主机名解析。当使用 IPv6 字面量时,访问 URL 中会自动转换为带方括号的形式,例如:`http://[::1]:8080/` | |
| # For IPv6 literals, wrap in brackets when constructing the URL. | ||
| host = self.host_ip | ||
| try: | ||
| ip = ipaddress.ip_address(host) | ||
| if isinstance(ip, ipaddress.IPv6Address): | ||
| host = f"[{ip}]" | ||
| except ValueError: | ||
| # Not an IP address, so it's a hostname. Use it as is. | ||
| pass |
There was a problem hiding this comment.
The new hostname fallback (treating non-IP host_ip as a hostname) doesn’t fully deliver the PR’s stated goal of supporting arbitrary hostnames in configs: _validate_model_cfg currently only allows host_ip == "localhost" or a valid IP literal, and rejects other hostnames/domains. Either widen config validation to accept hostnames (and document it), or tighten this logic/doc/PR description to only support localhost + IP literals so behavior is consistent end-to-end.
Thanks for your contribution; we appreciate it a lot. The following instructions will make your pull request healthier and help you get feedback more easily. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.
感谢您的贡献,我们非常重视。以下说明将使您的拉取请求更健康,更易于获得反馈。如果您不理解某些项目,请不要担心,只需提交拉取请求并从维护人员那里寻求帮助即可。
PR Type / PR类型
Related Issue | 关联 Issue
Fixes #(issue ID / issue 编号) / Relates to #(issue ID / issue 编号)
🔍 Motivation / 变更动机
This PR aims to make service-based model backends work reliably with IPv4, IPv6 literals and hostnames when configuring
host_ip. Previously,BaseAPIModelonly handled IPv4 literals correctly and could generate invalid URLs or even raise exceptions when using IPv6 literals orlocalhost. With this change, users can configure IPv4/IPv6/hostnames in a more intuitive and consistent way, with proper URL construction and clearer documentation.本 PR 旨在让服务化模型后端在配置
host_ip时能够稳定支持 IPv4、IPv6 字面量以及主机名。此前BaseAPIModel只在 IPv4 字面量场景下工作正常,使用 IPv6 字面量或localhost时可能会生成非法 URL,甚至抛出异常。本次修改希望通过修正 URL 构造逻辑并补充文档说明,使用户在配置 IPv4/IPv6/主机名时行为更加直观、一致。📝 Modification / 修改内容
Code changes / 代码修改
[ais_bench/benchmark/models/api_models/base_api.py]to buildbase_urlbased onhost_ipin a protocol-agnostic and IP-version-aware way:ipaddress.ip_address(self.host_ip)to detect whetherhost_ipis a valid IPv4 or IPv6 literal.http://[::1]:8080/), while keeping IPv4 literals unchanged.localhostor custom domains), keep the original string without modification to remain compatible with existing deployments.文档与测试 / Docs & Tests
[docs/source_zh_cn/base_tutorials/all_params/models.md]and[docs/source_en/base_tutorials/all_params/models.md], clarify thathost_ipsupports both IPv4 and IPv6 literals, add examples like::1, and explicitly document that IPv6 literals will be automatically wrapped in brackets in the generated URLs.[tests/UT/models/api_models/test_base_api.py], add unit tests to cover:_get_base_urlbehavior with an IPv6 literalhost_ip(e.g.::1);_get_base_urlbehavior with a hostnamehost_ip(e.g.localhost) to ensure backward compatibility.smoke test:
📐 Associated Test Results / 关联测试结果
Local unit tests have been added/updated and executed for the affected modules, focusing on IPv6 and hostname handling in
BaseAPIModel:tests/UT/models/api_models/test_base_api.py相关模块的本地单元测试已补充/更新并执行,重点覆盖
BaseAPIModel中 IPv6 与主机名场景的行为:tests/UT/models/api_models/test_base_api.py测试结果:
This change is not expected to be BC-breaking. It keeps the behavior for IPv4 literals and hostnames unchanged at the configuration level, while making URL construction for IPv6 literals more correct (adding brackets automatically). Existing configurations using
127.0.0.1orlocalhostshould continue to work as before.本次修改预期不会引入向后不兼容变更:对 IPv4 字面量和主机名的配置行为保持不变,仅在内部对 IPv6 字面量的 URL 构造进行了更规范的处理(自动添加方括号)。已使用
127.0.0.1或localhost的现有配置应能继续按原有方式工作。If the modification introduces performance degradation, please describe the impact of the performance degradation and the expected performance improvement.
如果引入了性能下降,请描述性能下降的影响和预期的性能改进。
🌟 Use cases (Optional) / 使用案例(可选)
If this PR introduces a new feature, it is better to list some use cases here and update the documentation.
如果此拉取请求引入了新功能,最好在此处列出一些用例并更新文档。
✅ Checklist / 检查列表
Before PR:
After PR:
👥 Collaboration Info / 协作信息
🌟 Useful CI Command / 实用的CI命令
/gemini review/gemini summary/gemini help/readthedocs build