From 4e13f22cbf85e5ad43c81287729adc2aec925f6c Mon Sep 17 00:00:00 2001 From: luxuncang <2635886314@qq.com> Date: Tue, 23 Apr 2024 05:43:09 +0800 Subject: [PATCH] Make the port number optional in JupyterConnectionInfo() (#2473) * fix: JupyterConnectionInfo port type * fix: jupyter_client base_url * fix: JupyterConnectionInfo --- autogen/coding/jupyter/base.py | 6 +++--- autogen/coding/jupyter/jupyter_client.py | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/autogen/coding/jupyter/base.py b/autogen/coding/jupyter/base.py index d896b6ac3cc5..0e7acaf1e87b 100644 --- a/autogen/coding/jupyter/base.py +++ b/autogen/coding/jupyter/base.py @@ -10,9 +10,9 @@ class JupyterConnectionInfo: """`str` - Host of the Jupyter gateway server""" use_https: bool """`bool` - Whether to use HTTPS""" - port: int - """`int` - Port of the Jupyter gateway server""" - token: Optional[str] + port: Optional[int] = None + """`Optional[int]` - Port of the Jupyter gateway server. If None, the default port is used""" + token: Optional[str] = None """`Optional[str]` - Token for authentication. If None, no token is used""" diff --git a/autogen/coding/jupyter/jupyter_client.py b/autogen/coding/jupyter/jupyter_client.py index 44aafd8f5b09..b3de374fce9b 100644 --- a/autogen/coding/jupyter/jupyter_client.py +++ b/autogen/coding/jupyter/jupyter_client.py @@ -41,10 +41,12 @@ def _get_headers(self) -> Dict[str, str]: def _get_api_base_url(self) -> str: protocol = "https" if self._connection_info.use_https else "http" - return f"{protocol}://{self._connection_info.host}:{self._connection_info.port}" + port = f":{self._connection_info.port}" if self._connection_info.port else "" + return f"{protocol}://{self._connection_info.host}{port}" def _get_ws_base_url(self) -> str: - return f"ws://{self._connection_info.host}:{self._connection_info.port}" + port = f":{self._connection_info.port}" if self._connection_info.port else "" + return f"ws://{self._connection_info.host}{port}" def list_kernel_specs(self) -> Dict[str, Dict[str, str]]: response = self._session.get(f"{self._get_api_base_url()}/api/kernelspecs", headers=self._get_headers())