Skip to content

Commit d3a2ea0

Browse files
author
Pierre
authored
Merge branch 'main' into pierre-readme
2 parents 845410a + 386c244 commit d3a2ea0

File tree

6 files changed

+59
-6
lines changed

6 files changed

+59
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "workflowai"
3-
version = "0.6.0.dev11"
3+
version = "0.6.0.dev12"
44
description = ""
55
authors = ["Guillaume Aquilina <guillaume@workflowai.com>"]
66
readme = "README.md"

workflowai/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import os
21
from collections.abc import Callable, Iterable
32
from typing import Any, Optional
43

54
from typing_extensions import deprecated
65

6+
from workflowai import env
77
from workflowai.core.client._types import AgentDecorator
88
from workflowai.core.client.client import WorkflowAI as WorkflowAI
99
from workflowai.core.domain import model
@@ -23,8 +23,8 @@ def _build_client(
2323
default_version: Optional[VersionReference] = None,
2424
):
2525
return WorkflowAI(
26-
endpoint=endpoint or os.getenv("WORKFLOWAI_API_URL"),
27-
api_key=api_key or os.getenv("WORKFLOWAI_API_KEY", ""),
26+
endpoint=endpoint or env.WORKFLOWAI_API_URL,
27+
api_key=api_key or env.WORKFLOWAI_API_KEY,
2828
default_version=default_version,
2929
)
3030

@@ -33,7 +33,7 @@ def _build_client(
3333
shared_client: WorkflowAI = _build_client()
3434

3535
# The default model to use when running agents without a deployment
36-
DEFAULT_MODEL: "model.ModelOrStr" = os.getenv("WORKFLOWAI_DEFAULT_MODEL", "gemini-1.5-pro-latest")
36+
DEFAULT_MODEL: "model.ModelOrStr" = env.WORKFLOWAI_DEFAULT_MODEL
3737

3838

3939
def init(api_key: Optional[str] = None, url: Optional[str] = None, default_version: Optional[VersionReference] = None):

workflowai/core/domain/run.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from pydantic import BaseModel, Field # pyright: ignore [reportUnknownVariableType]
55
from typing_extensions import Unpack
66

7+
from workflowai import env
78
from workflowai.core import _common_types
89
from workflowai.core.client import _types
910
from workflowai.core.domain.errors import BaseError
@@ -120,6 +121,10 @@ def __str__(self) -> str:
120121
"""Return a string representation of the run."""
121122
return self.format_output()
122123

124+
@property
125+
def run_url(self):
126+
return f"{env.WORKFLOWAI_APP_URL}/agents/{self.agent_id}/runs/{self.id}"
127+
123128

124129
class _AgentBase(Protocol, Generic[AgentOutput]):
125130
async def reply(

workflowai/core/domain/run_test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from unittest.mock import Mock
1+
from unittest.mock import Mock, patch
22

33
import pytest
44
from pydantic import BaseModel
@@ -114,3 +114,9 @@ def test_format_output_no_cost_latency() -> None:
114114
=================================================="""
115115

116116
assert run.format_output() == expected
117+
118+
119+
class TestRunURL:
120+
@patch("workflowai.env.WORKFLOWAI_APP_URL", "https://workflowai.hello")
121+
def test_run_url(self, run1: Run[_TestOutput]):
122+
assert run1.run_url == "https://workflowai.hello/agents/agent-1/runs/test-id"

workflowai/env.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
"""A file to describe all environment variables"""
2+
3+
import os
4+
5+
WORKFLOWAI_DEFAULT_MODEL = os.getenv("WORKFLOWAI_DEFAULT_MODEL", "gemini-1.5-pro-latest")
6+
7+
WORKFLOWAI_API_URL = os.getenv("WORKFLOWAI_API_URL")
8+
9+
10+
def _default_api_url():
11+
if not WORKFLOWAI_API_URL:
12+
return "https://workflowai.com"
13+
if WORKFLOWAI_API_URL.startswith("https://run."):
14+
return "https://" + WORKFLOWAI_API_URL.removeprefix("https://run.")
15+
if WORKFLOWAI_API_URL.startswith("https://api."):
16+
return "https://" + WORKFLOWAI_API_URL.removeprefix("https://api.")
17+
return "https://workflowai.com"
18+
19+
20+
WORKFLOWAI_APP_URL = os.getenv("WORKFLOWAI_APP_URL", _default_api_url)
21+
22+
WORKFLOWAI_API_KEY = os.getenv("WORKFLOWAI_API_KEY", "")

workflowai/env_test.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from typing import Optional
2+
from unittest.mock import patch
3+
4+
import pytest
5+
6+
from .env import _default_api_url # pyright: ignore[reportPrivateUsage]
7+
8+
9+
@pytest.mark.parametrize(
10+
("api_url", "expected"),
11+
[
12+
("https://run.workflowai.com", "https://workflowai.com"),
13+
("https://api.workflowai.com", "https://workflowai.com"),
14+
("https://workflowai.com", "https://workflowai.com"),
15+
(None, "https://workflowai.com"),
16+
],
17+
)
18+
def test_default_api_url(api_url: Optional[str], expected: str):
19+
with patch("workflowai.env.WORKFLOWAI_API_URL", api_url):
20+
assert _default_api_url() == expected

0 commit comments

Comments
 (0)