-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Diwank Tomer <[email protected]>
- Loading branch information
Diwank Tomer
committed
Aug 20, 2024
1 parent
d92b054
commit 9962356
Showing
8 changed files
with
164 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import re | ||
|
||
import yaml | ||
from fastapi import Request | ||
|
||
|
||
class YamlMiddleware: | ||
def __init__(self, path_regex: str = r".*"): | ||
self.path_regex = re.compile(path_regex) | ||
|
||
async def __call__(self, request: Request, call_next): | ||
content_type = request.headers.get("content-type", "").strip().lower() | ||
|
||
# Filter out requests that are not for YAML and not for the specified path | ||
if not self.path_regex.match(request.url.path) or content_type not in [ | ||
"application/x-yaml", | ||
"application/yaml", | ||
"text/yaml", | ||
"text/x-yaml", | ||
]: | ||
return await call_next(request) | ||
|
||
# Parse the YAML body into a Python object | ||
body = yaml.load(await request.body(), yaml.CSafeLoader) | ||
request._json = body | ||
|
||
# Switch headers to JSON | ||
headers = request.headers.mutablecopy() | ||
headers["content-type"] = "application/json" | ||
|
||
request._headers = headers | ||
|
||
# Continue processing the request | ||
response = await call_next(request) | ||
return response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
# Tests for task queries | ||
|
||
from uuid import uuid4 | ||
|
||
from ward import test | ||
|
||
from .fixtures import cozo_client, test_agent, test_developer_id | ||
from .utils import patch_http_client_with_temporal | ||
|
||
|
||
@test("workflow route: evaluate step single") | ||
async def _( | ||
cozo_client=cozo_client, | ||
developer_id=test_developer_id, | ||
agent=test_agent, | ||
): | ||
agent_id = str(agent.id) | ||
task_id = str(uuid4()) | ||
|
||
async with patch_http_client_with_temporal( | ||
cozo_client=cozo_client, developer_id=developer_id | ||
) as ( | ||
make_request, | ||
client, | ||
): | ||
task_data = { | ||
"name": "test task", | ||
"description": "test task about", | ||
"input_schema": {"type": "object", "additionalProperties": True}, | ||
"main": [{"evaluate": {"hello": '"world"'}}], | ||
} | ||
|
||
make_request( | ||
method="POST", | ||
url=f"/agents/{agent_id}/tasks/{task_id}", | ||
json=task_data, | ||
) | ||
|
||
execution_data = dict(input={"test": "input"}) | ||
|
||
make_request( | ||
method="POST", | ||
url=f"/tasks/{task_id}/executions", | ||
json=execution_data, | ||
) | ||
|
||
|
||
@test("workflow route: evaluate step single with yaml") | ||
async def _( | ||
cozo_client=cozo_client, | ||
developer_id=test_developer_id, | ||
agent=test_agent, | ||
): | ||
agent_id = str(agent.id) | ||
task_id = str(uuid4()) | ||
|
||
async with patch_http_client_with_temporal( | ||
cozo_client=cozo_client, developer_id=developer_id | ||
) as ( | ||
make_request, | ||
client, | ||
): | ||
task_data = """ | ||
name: test task | ||
description: test task about | ||
input_schema: | ||
type: object | ||
additionalProperties: true | ||
main: | ||
- evaluate: | ||
hello: '"world"' | ||
""" | ||
|
||
make_request( | ||
method="POST", | ||
url=f"/agents/{agent_id}/tasks/{task_id}", | ||
content=task_data, | ||
headers={"Content-Type": "text/yaml"}, | ||
) | ||
|
||
execution_data = dict(input={"test": "input"}) | ||
|
||
make_request( | ||
method="POST", | ||
url=f"/tasks/{task_id}/executions", | ||
json=execution_data, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters