Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tests/cli/test_cli_predictions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from vlmrun.cli.cli import app


def test_list_predictions(runner, mock_client, config_file):
def test_list_predictions(runner, mock_client, config_file, monkeypatch):
"""Test list predictions command."""
monkeypatch.setenv("COLUMNS", "200")
result = runner.invoke(app, ["predictions", "list"])
assert result.exit_code == 0
assert "prediction1" in result.stdout
Expand Down Expand Up @@ -57,8 +58,9 @@ def test_get_prediction_usage_display(runner, mock_client, config_file):
assert "100" in result.stdout


def test_list_predictions_table_format(runner, mock_client, config_file):
def test_list_predictions_table_format(runner, mock_client, config_file, monkeypatch):
"""Test that list output is formatted correctly."""
monkeypatch.setenv("COLUMNS", "200")
result = runner.invoke(app, ["predictions", "list"])
assert result.exit_code == 0
assert "id" in result.stdout
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ def execute(self, name: str, **kwargs):
)
return prediction

def __init__(self, api_key=None, base_url=None):
def __init__(self, api_key=None, base_url=None, agent_base_url=None):
self.api_key = api_key or "test-key"
self.base_url = base_url or "https://api.vlm.run"
self.agent_base_url = agent_base_url or self.base_url
self.timeout = 120.0
self.max_retries = 1
self.dataset = self.Dataset(self)
Expand Down
4 changes: 2 additions & 2 deletions vlmrun/cli/_cli/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,9 @@ def chat(
help="Artifact output directory. [default: ~/.vlmrun/cache/artifacts/<id>]",
),
base_url: Optional[str] = typer.Option(
os.getenv("VLMRUN_BASE_URL", DEFAULT_BASE_URL),
os.getenv("VLMRUN_AGENT_BASE_URL", os.getenv("VLMRUN_BASE_URL", DEFAULT_BASE_URL)),
"--base-url",
help="VLM Run Agent API base URL.",
help="VLM Run Agent API base URL. Falls back to VLMRUN_AGENT_BASE_URL, then VLMRUN_BASE_URL.",
),
Comment on lines 490 to 494

Choose a reason for hiding this comment

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

medium

The base_url parameter defined here is currently unused within the chat function body. Since the VLMRun client is initialized in the parent command group (vlmrun/cli/cli.py) and passed via ctx.obj, this local option does not affect the client's configuration.

If the intention is to allow overriding the agent URL specifically for the chat command, you should apply this value to the client instance inside the function (e.g., client.agent_base_url = base_url). Additionally, consider renaming this option to --agent-base-url to maintain consistency with the client property and avoid confusion with the global --base-url option.

model: str = typer.Option(
DEFAULT_MODEL,
Expand Down
4 changes: 2 additions & 2 deletions vlmrun/client/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def completions(self):
error_type="missing_dependency",
)

base_url = f"{self._client.base_url}/openai"
base_url = f"{self._client.agent_base_url}/openai"
openai_client = OpenAI(
api_key=self._client.api_key,
base_url=base_url,
Expand Down Expand Up @@ -332,7 +332,7 @@ async def main():
error_type="missing_dependency",
)

base_url = f"{self._client.base_url}/openai"
base_url = f"{self._client.agent_base_url}/openai"
async_openai_client = AsyncOpenAI(
api_key=self._client.api_key,
base_url=base_url,
Expand Down
7 changes: 7 additions & 0 deletions vlmrun/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class VLMRun:
or VLMRUN_API_KEY environment variable.
base_url: Base URL for API. Defaults to None, which falls back to
VLMRUN_BASE_URL environment variable or https://api.vlm.run/v1.
agent_base_url: Base URL for the agent (OpenAI-compatible completions) endpoint.
Falls back to VLMRUN_AGENT_BASE_URL environment variable, then to base_url.
timeout: Request timeout in seconds. Defaults to 120.0.
max_retries: Maximum number of retry attempts for failed requests. Defaults to 5.
files: Files resource for managing files
Expand All @@ -50,6 +52,7 @@ class VLMRun:

api_key: Optional[str] = None
base_url: Optional[str] = None
agent_base_url: Optional[str] = None
timeout: float = 120.0
max_retries: int = 5

Expand Down Expand Up @@ -79,6 +82,10 @@ def __post_init__(self):
if self.base_url is None:
self.base_url = os.getenv("VLMRUN_BASE_URL", DEFAULT_BASE_URL)

# Handle agent base URL (for OpenAI-compatible completions endpoint)
if self.agent_base_url is None:
self.agent_base_url = os.getenv("VLMRUN_AGENT_BASE_URL", self.base_url)

# Initialize requestor for API key validation
requestor = APIRequestor(
self, timeout=self.timeout, max_retries=self.max_retries
Expand Down
1 change: 1 addition & 0 deletions vlmrun/types/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class VLMRunProtocol(Protocol):

api_key: Optional[str]
base_url: str
agent_base_url: str
timeout: float
files: Any
datasets: Any
Expand Down