-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathno_schema_test.py
More file actions
59 lines (41 loc) · 1.63 KB
/
no_schema_test.py
File metadata and controls
59 lines (41 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from typing import Optional
from pydantic import BaseModel, Field
import workflowai
from workflowai.core.client.agent import Agent
class SummarizeTaskInput(BaseModel):
text: Optional[str] = None
class SummarizeTaskOutput(BaseModel):
summary_points: Optional[list[str]] = None
@workflowai.agent(id="summarize", model="gemini-1.5-flash-latest")
async def summarize(_: SummarizeTaskInput) -> SummarizeTaskOutput: ...
async def test_summarize():
summarized = await summarize(
SummarizeTaskInput(
text="""The first computer programmer was Ada Lovelace. She wrote the first algorithm
intended to be processed by a machine in the 1840s. Her work was on Charles Babbage's
proposed mechanical computer, the Analytical Engine. She is celebrated annually on Ada
Lovelace Day, which promotes women in science and technology.""",
),
use_cache="never",
)
assert summarized.summary_points
async def test_same_schema():
class InputWithNullableList(BaseModel):
opt_list: Optional[list[str]] = None
class InputWithNonNullableList(BaseModel):
opt_list: list[str] = Field(default_factory=list)
agent1 = Agent(
agent_id="summarize",
input_cls=InputWithNullableList,
output_cls=SummarizeTaskOutput,
api=lambda: workflowai.shared_client.api,
)
schema_id1 = await agent1.register()
agent2 = Agent(
agent_id="summarize",
input_cls=InputWithNonNullableList,
output_cls=SummarizeTaskOutput,
api=lambda: workflowai.shared_client.api,
)
schema_id2 = await agent2.register()
assert schema_id1 == schema_id2