Skip to content

Commit 5ebd5a2

Browse files
authored
Merge pull request #15 from workflowai/guillaume/add-test
Add deserialization test
2 parents 0d1fea5 + 3e1c45b commit 5ebd5a2

5 files changed

Lines changed: 221 additions & 6 deletions

File tree

poetry.lock

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"id": "e3683ced-efd2-4b15-9ab4-aefdf17c4c19",
3+
"task_id": "generate-changelog-from-properties",
4+
"task_schema_id": 1,
5+
"task_input": {
6+
"temperature": 1
7+
},
8+
"task_input_hash": "6faebdc55135f380b00e7ada53f5cccc",
9+
"task_input_preview": "old_task_group: {properties: {temperature: 1, instructions: \"Add 5 to the n",
10+
"task_output": {
11+
"changes": [
12+
"Temperature decreased from Creative to 0.73"
13+
]
14+
},
15+
"task_output_hash": "d057c1f26fd8447c11cda7300e0f3717",
16+
"task_output_preview": "changes: [\"Temperature decreased from Creative to 0.73\"]",
17+
"group": {
18+
"id": "68eead780d01791ff2e09d39055ae6e8",
19+
"iteration": 36,
20+
"properties": {
21+
"model": "gemini-1.5-flash-002",
22+
"provider": "google",
23+
"temperature": 0,
24+
"instructions": "",
25+
"max_tokens": null,
26+
"runner_name": "WorkflowAI",
27+
"runner_version": "v0.1.0",
28+
"few_shot": null,
29+
"template_name": "v1",
30+
"task_variant_id": "fa546275ed8f6c801d6c6f174828d615"
31+
},
32+
"tags": [
33+
"model=gemini-1.5-flash-002",
34+
"provider=google",
35+
"temperature=0"
36+
],
37+
"aliases": null,
38+
"is_external": null,
39+
"is_favorite": null,
40+
"notes": null,
41+
"similarity_hash": "",
42+
"benchmark_for_datasets": null
43+
},
44+
"status": "success",
45+
"error": null,
46+
"start_time": "2024-10-01T17:55:06.241000Z",
47+
"end_time": "2024-10-01T17:55:07.879000Z",
48+
"duration_seconds": 1.638103,
49+
"cost_usd": 0.00004651875,
50+
"created_at": "2024-10-01T17:55:07.879000Z",
51+
"updated_at": "2024-10-01T17:55:07.879000Z",
52+
"example_id": null,
53+
"corrections": null,
54+
"parent_task_ids": null,
55+
"scores": null,
56+
"labels": null,
57+
"metadata": {
58+
"used_alias": "environment=production"
59+
},
60+
"llm_completions": [
61+
{
62+
"messages": [
63+
{
64+
"role": "system",
65+
"content": ""
66+
},
67+
{
68+
"role": "user",
69+
"content": ""
70+
}
71+
],
72+
"response": "{\"changes\": [\"Temperature decreased from Creative to 0.73\"]}",
73+
"usage": {
74+
"completion_token_count": 13.5,
75+
"completion_cost_usd": 0.00000405,
76+
"prompt_token_count": 566.25,
77+
"prompt_cost_usd": 0.00004246875
78+
}
79+
}
80+
],
81+
"config_id": null,
82+
"dataset_benchmark_ids": null,
83+
"is_free": null,
84+
"author_tenant": null
85+
}

workflowai/core/client/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def __init__(self, endpoint: str, api_key: str, source_headers: Optional[dict[st
2222
raise ValueError("Missing API URL or key")
2323

2424
def _client(self) -> httpx.AsyncClient:
25+
source_headers = self.source_headers or {}
2526
client = httpx.AsyncClient(
2627
base_url=self.endpoint,
2728
headers={
2829
"Authorization": f"Bearer {self.api_key}",
29-
**(self.source_headers or {}),
30+
**source_headers,
3031
},
3132
timeout=120.0,
3233
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import pytest
2+
3+
from tests.utils import fixture_text
4+
from workflowai.core.client.models import TaskRunResponse
5+
6+
7+
@pytest.mark.parametrize(
8+
"fixture",
9+
[
10+
"task_run.json",
11+
"task_run_float_usage.json",
12+
],
13+
)
14+
def test_task_run_response(fixture: str):
15+
txt = fixture_text(fixture)
16+
task_run = TaskRunResponse.model_validate_json(txt)
17+
assert task_run
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
from typing import Optional
2+
3+
from pydantic import BaseModel
4+
5+
from workflowai.core.client.models import TaskRunResponse
6+
from workflowai.core.domain.task import Task
7+
8+
9+
class GenerateChangelogFromPropertiesTaskInput(BaseModel):
10+
temperature: Optional[float] = None
11+
12+
13+
class GenerateChangelogFromPropertiesTaskOutput(BaseModel):
14+
changes: Optional[list[str]] = None
15+
16+
17+
def test_task_run_model_validate():
18+
json_str = """{
19+
"id": "e3683ced-efd2-4b15-9ab4-aefdf17c4c19",
20+
"task_id": "generate-changelog-from-properties",
21+
"task_schema_id": 1,
22+
"task_input": {
23+
"temperature": 1
24+
},
25+
"task_input_hash": "6faebdc55135f380b00e7ada53f5cccc",
26+
"task_input_preview": "old_task_group: {properties: {temperature: 1, instructions: \\"Add 5 to the n",
27+
"task_output": {
28+
"changes": [
29+
"Temperature decreased from Creative to 0.73"
30+
]
31+
},
32+
"task_output_hash": "d057c1f26fd8447c11cda7300e0f3717",
33+
"task_output_preview": "changes: [\\"Temperature decreased from Creative to 0.73\\"]",
34+
"group": {
35+
"id": "68eead780d01791ff2e09d39055ae6e8",
36+
"iteration": 36,
37+
"properties": {
38+
"model": "gemini-1.5-flash-002",
39+
"provider": "google",
40+
"temperature": 0,
41+
"instructions": "",
42+
"max_tokens": null,
43+
"runner_name": "WorkflowAI",
44+
"runner_version": "v0.1.0",
45+
"few_shot": null,
46+
"template_name": "v1",
47+
"task_variant_id": "fa546275ed8f6c801d6c6f174828d615"
48+
},
49+
"tags": [
50+
"model=gemini-1.5-flash-002",
51+
"provider=google",
52+
"temperature=0"
53+
],
54+
"aliases": null,
55+
"is_external": null,
56+
"is_favorite": null,
57+
"notes": null,
58+
"similarity_hash": "",
59+
"benchmark_for_datasets": null
60+
},
61+
"status": "success",
62+
"error": null,
63+
"start_time": "2024-10-01T17:55:06.241000Z",
64+
"end_time": "2024-10-01T17:55:07.879000Z",
65+
"duration_seconds": 1.638103,
66+
"cost_usd": 0.00004651875,
67+
"created_at": "2024-10-01T17:55:07.879000Z",
68+
"updated_at": "2024-10-01T17:55:07.879000Z",
69+
"example_id": null,
70+
"corrections": null,
71+
"parent_task_ids": null,
72+
"scores": null,
73+
"labels": null,
74+
"metadata": {
75+
"used_alias": "environment=production"
76+
},
77+
"llm_completions": [
78+
{
79+
"messages": [
80+
{
81+
"role": "system",
82+
"content": ""
83+
},
84+
{
85+
"role": "user",
86+
"content": ""
87+
}
88+
],
89+
"response": "{\\"changes\\": [\\"Temperature decreased from Creative to 0.73\\"]}",
90+
"usage": {
91+
"completion_token_count": 13.5,
92+
"completion_cost_usd": 0.00000405,
93+
"prompt_token_count": 566.25,
94+
"prompt_cost_usd": 0.00004246875
95+
}
96+
}
97+
],
98+
"config_id": null,
99+
"dataset_benchmark_ids": null,
100+
"is_free": null,
101+
"author_tenant": null
102+
}"""
103+
104+
task_run = TaskRunResponse.model_validate_json(json_str).to_domain(
105+
Task(
106+
input_class=GenerateChangelogFromPropertiesTaskInput,
107+
output_class=GenerateChangelogFromPropertiesTaskOutput,
108+
),
109+
)
110+
assert task_run.id == "e3683ced-efd2-4b15-9ab4-aefdf17c4c19"

0 commit comments

Comments
 (0)