-
Notifications
You must be signed in to change notification settings - Fork 19
【BugFix】Fix the support issue for IPv6 #186
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ | |
| import warnings | ||
| import asyncio | ||
| import os.path as osp | ||
| import ipaddress | ||
| from abc import abstractmethod | ||
| from copy import deepcopy | ||
| from typing import Dict, List, Optional, Tuple, Union | ||
|
|
@@ -113,7 +114,17 @@ def _get_base_url(self) -> str: | |
| if self.url.startswith("http://") or self.url.startswith("https://"): | ||
| return self.url | ||
| return f"{protocol}://{self.url}" | ||
| base_url = f"{protocol}://{self.host_ip}:{self.host_port}/" | ||
|
|
||
| # 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 | ||
|
Comment on lines
+118
to
+126
|
||
| base_url = f"{protocol}://{host}:{self.host_port}/" | ||
| return base_url | ||
|
|
||
| def _get_service_model_path(self) -> str: | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -77,7 +77,7 @@ The description of configurable parameters for the service-oriented inference ba | |||||
| | `traffic_cfg` | Dict | Parameters for controlling fluctuations in the request sending rate (for detailed usage instructions, refer to 🔗 [Description of Request Rate (RPS) Distribution Control and Visualization](../../advanced_tutorials/rps_distribution.md)). If this item is not filled in, the function is disabled by default | | ||||||
| | `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/` | | ||||||
|
||||||
| | `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/` | |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -72,7 +72,7 @@ models = [ | |||||
| | `traffic_cfg` | Dict | 请求发送速率波动控制参数(具体使用说明请参考 🔗 [请求速率(RPS)分布控制及可视化说明](../../advanced_tutorials/rps_distribution.md)),不填写此项默认不启用该功能。 | | ||||||
| | `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/` | | ||||||
|
||||||
| | `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/` | |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -61,6 +61,8 @@ async def parse_stream_response(self, data, output): | |
| "host_ip": "127.0.0.1", | ||
| "host_port": 8000 | ||
| } | ||
| self.ipv6_kwargs = self.default_kwargs.copy() | ||
| self.ipv6_kwargs["host_ip"] = "::1" | ||
|
|
||
| def test_init(self): | ||
| model = self.model_class(**self.default_kwargs) | ||
|
|
@@ -70,6 +72,10 @@ def test_init(self): | |
| self.assertEqual(model.retry, 1) | ||
| self.assertEqual(model.base_url, "http://127.0.0.1:8000/") | ||
|
|
||
| def test_init_with_ipv6_host_ip(self): | ||
| model = self.model_class(**self.ipv6_kwargs) | ||
| self.assertEqual(model.base_url, "http://[::1]:8000/") | ||
|
|
||
| def test_init_with_url(self): | ||
| kwargs = self.default_kwargs.copy() | ||
| kwargs["url"] = "https://test-api.com/v1" | ||
|
|
@@ -86,6 +92,16 @@ def test_get_base_url(self): | |
| model = self.model_class(**self.default_kwargs) | ||
| self.assertEqual(model._get_base_url(), "http://127.0.0.1:8000/") | ||
|
|
||
| def test_get_base_url_with_ipv6_host_ip(self): | ||
| model = self.model_class(**self.ipv6_kwargs) | ||
| self.assertEqual(model._get_base_url(), "http://[::1]:8000/") | ||
|
|
||
| def test_get_base_url_with_hostname(self): | ||
| kwargs = self.default_kwargs.copy() | ||
| kwargs["host_ip"] = "localhost" | ||
| model = self.model_class(**kwargs) | ||
| self.assertEqual(model._get_base_url(), "http://localhost:8000/") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new tests cover 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/") |
||
|
|
||
| @mock.patch('requests.get') | ||
| def test_get_service_model_path_success(self, mock_get): | ||
| mock_response = MockResponse(200, json_data={"data": [{"id": "test-model-123"}]}) | ||
|
|
||
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.
[review] we should add warning to user
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.
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.