Skip to content

Commit 4b38cbb

Browse files
committed
fix: run vs non run endpoint
1 parent 8099d67 commit 4b38cbb

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

tests/e2e/no_schema_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class SummarizeTaskOutput(BaseModel):
1313
summary_points: Optional[list[str]] = None
1414

1515

16-
@workflowai.agent(id="summarize")
16+
@workflowai.agent(id="summarize", model="gemini-1.5-flash-latest")
1717
async def summarize(task_input: SummarizeTaskInput) -> SummarizeTaskOutput: ...
1818

1919

tests/integration/run_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class CityToCapitalTaskOutput(BaseModel):
1717
capital: str
1818

1919

20-
workflowai.init(api_key="test", url="http://localhost:8000")
20+
workflowai.init(api_key="test", url="https://run.workflowai.dev")
2121

22-
_REGISTER_URL = "http://localhost:8000/v1/_/agents"
22+
_REGISTER_URL = "https://api.workflowai.dev/v1/_/agents"
2323

2424

2525
def _mock_register(httpx_mock: HTTPXMock, schema_id: int = 1, task_id: str = "city-to-capital", variant_id: str = "1"):
@@ -33,14 +33,14 @@ def _mock_register(httpx_mock: HTTPXMock, schema_id: int = 1, task_id: str = "ci
3333
def _mock_response(httpx_mock: HTTPXMock, task_id: str = "city-to-capital", capital: str = "Tokyo"):
3434
httpx_mock.add_response(
3535
method="POST",
36-
url=f"http://localhost:8000/v1/_/agents/{task_id}/schemas/1/run",
36+
url=f"https://run.workflowai.dev/v1/_/agents/{task_id}/schemas/1/run",
3737
json={"id": "123", "task_output": {"capital": capital}},
3838
)
3939

4040

4141
def _mock_stream(httpx_mock: HTTPXMock, task_id: str = "city-to-capital"):
4242
httpx_mock.add_response(
43-
url=f"http://localhost:8000/v1/_/agents/{task_id}/schemas/1/run",
43+
url=f"https://run.workflowai.dev/v1/_/agents/{task_id}/schemas/1/run",
4444
stream=IteratorStream(
4545
[
4646
b'data: {"id":"1","task_output":{"capital":""}}\n\n',
@@ -53,7 +53,7 @@ def _mock_stream(httpx_mock: HTTPXMock, task_id: str = "city-to-capital"):
5353

5454
def _check_request(request: Optional[Request], version: Any = "production", task_id: str = "city-to-capital"):
5555
assert request is not None
56-
assert request.url == f"http://localhost:8000/v1/_/agents/{task_id}/schemas/1/run"
56+
assert request.url == f"https://run.workflowai.dev/v1/_/agents/{task_id}/schemas/1/run"
5757
body = json.loads(request.content)
5858
assert body == {
5959
"task_input": {"city": "Hello"},

workflowai/core/client/_api.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,16 @@ def __init__(self, endpoint: str, api_key: str, source_headers: Optional[dict[st
2020
self.api_key = api_key
2121
self.source_headers = source_headers or {}
2222

23+
def _get_endpoint(self, run: bool = False):
24+
if run:
25+
return self.endpoint
26+
return self.endpoint.replace("https://run.", "https://api.")
27+
2328
@asynccontextmanager
24-
async def _client(self):
29+
async def _client(self, run: bool = False):
2530
source_headers = self.source_headers or {}
2631
async with httpx.AsyncClient(
27-
base_url=self.endpoint,
32+
base_url=self._get_endpoint(run),
2833
headers={
2934
"Authorization": f"Bearer {self.api_key}",
3035
**source_headers,
@@ -48,18 +53,19 @@ async def get(self, path: str, returns: type[_R], query: Union[dict[str, Any], N
4853
return TypeAdapter(returns).validate_python(response.json())
4954

5055
@overload
51-
async def post(self, path: str, data: BaseModel, returns: type[_R]) -> _R: ...
56+
async def post(self, path: str, data: BaseModel, returns: type[_R], run: bool = False) -> _R: ...
5257

5358
@overload
54-
async def post(self, path: str, data: BaseModel) -> None: ...
59+
async def post(self, path: str, data: BaseModel, returns: None = None, run: bool = False) -> None: ...
5560

5661
async def post(
5762
self,
5863
path: str,
5964
data: BaseModel,
6065
returns: Optional[type[_R]] = None,
66+
run: bool = False,
6167
) -> Optional[_R]:
62-
async with self._client() as client:
68+
async with self._client(run) as client:
6369
response = await client.post(
6470
path,
6571
content=data.model_dump_json(exclude_none=True),
@@ -155,8 +161,9 @@ async def stream(
155161
path: str,
156162
data: BaseModel,
157163
returns: type[_M],
164+
run: bool = False,
158165
) -> AsyncIterator[_M]:
159-
async with self._client() as client, client.stream(
166+
async with self._client(run=run) as client, client.stream(
160167
method,
161168
path,
162169
content=data.model_dump_json(exclude_none=True),

workflowai/core/client/agent.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ async def run(
127127
last_error = None
128128
while prepared_run.should_retry():
129129
try:
130-
res = await self.api.post(prepared_run.route, prepared_run.request, returns=RunResponse)
130+
res = await self.api.post(prepared_run.route, prepared_run.request, returns=RunResponse, run=True)
131131
return res.to_domain(self.agent_id, prepared_run.schema_id, validator)
132132
except WorkflowAIError as e: # noqa: PERF203
133133
last_error = e
@@ -174,6 +174,7 @@ async def stream(
174174
path=prepared_run.route,
175175
data=prepared_run.request,
176176
returns=RunResponse,
177+
run=True,
177178
):
178179
yield chunk.to_domain(self.agent_id, prepared_run.schema_id, validator)
179180
return

0 commit comments

Comments
 (0)