openai-sdk-helpers 0.0.8__py3-none-any.whl → 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openai_sdk_helpers/__init__.py +90 -2
- openai_sdk_helpers/agent/__init__.py +8 -4
- openai_sdk_helpers/agent/base.py +80 -45
- openai_sdk_helpers/agent/config.py +6 -4
- openai_sdk_helpers/agent/{project_manager.py → coordination.py} +29 -45
- openai_sdk_helpers/agent/prompt_utils.py +7 -1
- openai_sdk_helpers/agent/runner.py +67 -141
- openai_sdk_helpers/agent/search/__init__.py +33 -0
- openai_sdk_helpers/agent/search/base.py +297 -0
- openai_sdk_helpers/agent/{vector_search.py → search/vector.py} +89 -157
- openai_sdk_helpers/agent/{web_search.py → search/web.py} +77 -156
- openai_sdk_helpers/agent/summarizer.py +29 -8
- openai_sdk_helpers/agent/translator.py +40 -13
- openai_sdk_helpers/agent/validation.py +32 -8
- openai_sdk_helpers/async_utils.py +132 -0
- openai_sdk_helpers/config.py +101 -65
- openai_sdk_helpers/context_manager.py +241 -0
- openai_sdk_helpers/enums/__init__.py +9 -1
- openai_sdk_helpers/enums/base.py +67 -8
- openai_sdk_helpers/environment.py +33 -6
- openai_sdk_helpers/errors.py +133 -0
- openai_sdk_helpers/logging_config.py +105 -0
- openai_sdk_helpers/prompt/__init__.py +10 -71
- openai_sdk_helpers/prompt/base.py +222 -0
- openai_sdk_helpers/response/__init__.py +38 -3
- openai_sdk_helpers/response/base.py +363 -210
- openai_sdk_helpers/response/config.py +318 -0
- openai_sdk_helpers/response/messages.py +56 -40
- openai_sdk_helpers/response/runner.py +77 -33
- openai_sdk_helpers/response/tool_call.py +62 -27
- openai_sdk_helpers/response/vector_store.py +27 -14
- openai_sdk_helpers/retry.py +175 -0
- openai_sdk_helpers/streamlit_app/__init__.py +19 -2
- openai_sdk_helpers/streamlit_app/app.py +114 -39
- openai_sdk_helpers/streamlit_app/config.py +502 -0
- openai_sdk_helpers/streamlit_app/streamlit_web_search.py +5 -6
- openai_sdk_helpers/structure/__init__.py +72 -3
- openai_sdk_helpers/structure/agent_blueprint.py +82 -19
- openai_sdk_helpers/structure/base.py +208 -93
- openai_sdk_helpers/structure/plan/__init__.py +29 -1
- openai_sdk_helpers/structure/plan/enum.py +41 -5
- openai_sdk_helpers/structure/plan/helpers.py +172 -0
- openai_sdk_helpers/structure/plan/plan.py +109 -49
- openai_sdk_helpers/structure/plan/task.py +38 -6
- openai_sdk_helpers/structure/plan/types.py +15 -0
- openai_sdk_helpers/structure/prompt.py +21 -2
- openai_sdk_helpers/structure/responses.py +52 -11
- openai_sdk_helpers/structure/summary.py +55 -7
- openai_sdk_helpers/structure/validation.py +34 -6
- openai_sdk_helpers/structure/vector_search.py +132 -18
- openai_sdk_helpers/structure/web_search.py +125 -13
- openai_sdk_helpers/tools.py +193 -0
- openai_sdk_helpers/types.py +57 -0
- openai_sdk_helpers/utils/__init__.py +34 -1
- openai_sdk_helpers/utils/core.py +296 -34
- openai_sdk_helpers/validation.py +302 -0
- openai_sdk_helpers/vector_storage/__init__.py +21 -1
- openai_sdk_helpers/vector_storage/cleanup.py +25 -13
- openai_sdk_helpers/vector_storage/storage.py +123 -64
- openai_sdk_helpers/vector_storage/types.py +20 -19
- openai_sdk_helpers-0.1.0.dist-info/METADATA +550 -0
- openai_sdk_helpers-0.1.0.dist-info/RECORD +69 -0
- openai_sdk_helpers/streamlit_app/configuration.py +0 -324
- openai_sdk_helpers-0.0.8.dist-info/METADATA +0 -194
- openai_sdk_helpers-0.0.8.dist-info/RECORD +0 -55
- {openai_sdk_helpers-0.0.8.dist-info → openai_sdk_helpers-0.1.0.dist-info}/WHEEL +0 -0
- {openai_sdk_helpers-0.0.8.dist-info → openai_sdk_helpers-0.1.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
"""OpenAI response and tool helpers for structured outputs.
|
|
1
|
+
"""OpenAI response and tool helpers for structured outputs.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module provides helper functions for creating OpenAI API response formats
|
|
4
|
+
and tool definitions from BaseStructure classes. These helpers simplify the
|
|
5
|
+
process of configuring structured outputs for both Assistant and chat
|
|
6
|
+
completion APIs.
|
|
7
|
+
"""
|
|
4
8
|
|
|
5
|
-
from
|
|
9
|
+
from __future__ import annotations
|
|
6
10
|
|
|
7
11
|
from openai.types.responses.response_format_text_json_schema_config_param import (
|
|
8
12
|
ResponseFormatTextJSONSchemaConfigParam,
|
|
@@ -14,10 +18,13 @@ from ..utils import log
|
|
|
14
18
|
|
|
15
19
|
|
|
16
20
|
def assistant_tool_definition(
|
|
17
|
-
structure:
|
|
21
|
+
structure: type[BaseStructure], name: str, description: str
|
|
18
22
|
) -> dict:
|
|
19
23
|
"""Build a function tool definition for OpenAI Assistants.
|
|
20
24
|
|
|
25
|
+
Creates a tool definition compatible with the Assistant API that uses
|
|
26
|
+
the structure's schema as function parameters.
|
|
27
|
+
|
|
21
28
|
Parameters
|
|
22
29
|
----------
|
|
23
30
|
structure : type[BaseStructure]
|
|
@@ -30,7 +37,16 @@ def assistant_tool_definition(
|
|
|
30
37
|
Returns
|
|
31
38
|
-------
|
|
32
39
|
dict
|
|
33
|
-
Assistant tool definition payload.
|
|
40
|
+
Assistant tool definition payload in OpenAI format.
|
|
41
|
+
|
|
42
|
+
Examples
|
|
43
|
+
--------
|
|
44
|
+
>>> from openai_sdk_helpers.structure import BaseStructure
|
|
45
|
+
>>> tool = assistant_tool_definition(
|
|
46
|
+
... BaseStructure,
|
|
47
|
+
... "process_data",
|
|
48
|
+
... "Process input data"
|
|
49
|
+
... )
|
|
34
50
|
"""
|
|
35
51
|
log(f"{structure.__name__}::assistant_tool_definition")
|
|
36
52
|
return {
|
|
@@ -43,9 +59,12 @@ def assistant_tool_definition(
|
|
|
43
59
|
}
|
|
44
60
|
|
|
45
61
|
|
|
46
|
-
def assistant_format(structure:
|
|
62
|
+
def assistant_format(structure: type[BaseStructure]) -> dict:
|
|
47
63
|
"""Build a response format definition for OpenAI Assistants.
|
|
48
64
|
|
|
65
|
+
Creates a response format specification that instructs the Assistant API
|
|
66
|
+
to return structured output matching the provided schema.
|
|
67
|
+
|
|
49
68
|
Parameters
|
|
50
69
|
----------
|
|
51
70
|
structure : type[BaseStructure]
|
|
@@ -54,7 +73,11 @@ def assistant_format(structure: Type[BaseStructure]) -> dict:
|
|
|
54
73
|
Returns
|
|
55
74
|
-------
|
|
56
75
|
dict
|
|
57
|
-
Assistant response format definition.
|
|
76
|
+
Assistant response format definition in OpenAI format.
|
|
77
|
+
|
|
78
|
+
Examples
|
|
79
|
+
--------
|
|
80
|
+
>>> format_def = assistant_format(BaseStructure)
|
|
58
81
|
"""
|
|
59
82
|
log(f"{structure.__name__}::assistant_format")
|
|
60
83
|
return {
|
|
@@ -67,12 +90,15 @@ def assistant_format(structure: Type[BaseStructure]) -> dict:
|
|
|
67
90
|
|
|
68
91
|
|
|
69
92
|
def response_tool_definition(
|
|
70
|
-
structure:
|
|
93
|
+
structure: type[BaseStructure],
|
|
71
94
|
tool_name: str,
|
|
72
95
|
tool_description: str,
|
|
73
96
|
) -> dict:
|
|
74
97
|
"""Build a tool definition for OpenAI chat completions.
|
|
75
98
|
|
|
99
|
+
Creates a function tool definition compatible with the chat completions
|
|
100
|
+
API, using the structure's schema as parameters.
|
|
101
|
+
|
|
76
102
|
Parameters
|
|
77
103
|
----------
|
|
78
104
|
structure : type[BaseStructure]
|
|
@@ -85,7 +111,15 @@ def response_tool_definition(
|
|
|
85
111
|
Returns
|
|
86
112
|
-------
|
|
87
113
|
dict
|
|
88
|
-
Tool definition payload for chat completions.
|
|
114
|
+
Tool definition payload for chat completions API.
|
|
115
|
+
|
|
116
|
+
Examples
|
|
117
|
+
--------
|
|
118
|
+
>>> tool = response_tool_definition(
|
|
119
|
+
... BaseStructure,
|
|
120
|
+
... "analyze",
|
|
121
|
+
... "Analyze data"
|
|
122
|
+
... )
|
|
89
123
|
"""
|
|
90
124
|
log(f"{structure.__name__}::response_tool_definition")
|
|
91
125
|
return {
|
|
@@ -98,9 +132,12 @@ def response_tool_definition(
|
|
|
98
132
|
}
|
|
99
133
|
|
|
100
134
|
|
|
101
|
-
def response_format(structure:
|
|
135
|
+
def response_format(structure: type[BaseStructure]) -> ResponseTextConfigParam:
|
|
102
136
|
"""Build a response format for OpenAI chat completions.
|
|
103
137
|
|
|
138
|
+
Creates a response format specification that instructs the chat
|
|
139
|
+
completions API to return structured output matching the schema.
|
|
140
|
+
|
|
104
141
|
Parameters
|
|
105
142
|
----------
|
|
106
143
|
structure : type[BaseStructure]
|
|
@@ -109,7 +146,11 @@ def response_format(structure: Type[BaseStructure]) -> ResponseTextConfigParam:
|
|
|
109
146
|
Returns
|
|
110
147
|
-------
|
|
111
148
|
ResponseTextConfigParam
|
|
112
|
-
Response format definition.
|
|
149
|
+
Response format definition for chat completions API.
|
|
150
|
+
|
|
151
|
+
Examples
|
|
152
|
+
--------
|
|
153
|
+
>>> format_spec = response_format(BaseStructure)
|
|
113
154
|
"""
|
|
114
155
|
log(f"{structure.__name__}::response_format")
|
|
115
156
|
response_format_text_JSONSchema_config_param = (
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Structured output models for summaries.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module defines Pydantic models for representing summarization results,
|
|
4
|
+
including topic-level summaries with citations and consolidated text summaries.
|
|
5
|
+
"""
|
|
4
6
|
|
|
5
|
-
from
|
|
7
|
+
from __future__ import annotations
|
|
6
8
|
|
|
7
9
|
from .base import BaseStructure, spec_field
|
|
8
10
|
|
|
@@ -10,10 +12,30 @@ from .base import BaseStructure, spec_field
|
|
|
10
12
|
class SummaryTopic(BaseStructure):
|
|
11
13
|
"""Capture a topic-level summary with supporting citations.
|
|
12
14
|
|
|
15
|
+
Represents a single topic or micro-trend identified in source excerpts,
|
|
16
|
+
along with a summary and supporting citations.
|
|
17
|
+
|
|
18
|
+
Attributes
|
|
19
|
+
----------
|
|
20
|
+
topic : str
|
|
21
|
+
Topic or micro-trend identified in the provided excerpts.
|
|
22
|
+
summary : str
|
|
23
|
+
Concise explanation of what the excerpts convey about the topic.
|
|
24
|
+
citations : list[str]
|
|
25
|
+
Indices or short quotes that justify the topic summary.
|
|
26
|
+
|
|
13
27
|
Methods
|
|
14
28
|
-------
|
|
15
29
|
print()
|
|
16
30
|
Return a formatted string representation of the stored fields.
|
|
31
|
+
|
|
32
|
+
Examples
|
|
33
|
+
--------
|
|
34
|
+
>>> topic = SummaryTopic(
|
|
35
|
+
... topic="AI Trends",
|
|
36
|
+
... summary="Growing adoption of AI",
|
|
37
|
+
... citations=["Source 1", "Source 2"]
|
|
38
|
+
... )
|
|
17
39
|
"""
|
|
18
40
|
|
|
19
41
|
topic: str = spec_field(
|
|
@@ -26,7 +48,7 @@ class SummaryTopic(BaseStructure):
|
|
|
26
48
|
default=...,
|
|
27
49
|
description="Concise explanation of what the excerpts convey about the topic.",
|
|
28
50
|
)
|
|
29
|
-
citations:
|
|
51
|
+
citations: list[str] = spec_field(
|
|
30
52
|
"citations",
|
|
31
53
|
default_factory=list,
|
|
32
54
|
description="Indices or short quotes that justify the topic summary.",
|
|
@@ -34,12 +56,23 @@ class SummaryTopic(BaseStructure):
|
|
|
34
56
|
|
|
35
57
|
|
|
36
58
|
class SummaryStructure(BaseStructure):
|
|
37
|
-
"""
|
|
59
|
+
"""Consolidated summary returned by the summarizer agent.
|
|
60
|
+
|
|
61
|
+
Represents a synthesized summary text derived from multiple source excerpts.
|
|
62
|
+
|
|
63
|
+
Attributes
|
|
64
|
+
----------
|
|
65
|
+
text : str
|
|
66
|
+
Combined summary synthesized from the supplied excerpts.
|
|
38
67
|
|
|
39
68
|
Methods
|
|
40
69
|
-------
|
|
41
70
|
print()
|
|
42
71
|
Return a formatted string representation of the stored fields.
|
|
72
|
+
|
|
73
|
+
Examples
|
|
74
|
+
--------
|
|
75
|
+
>>> summary = SummaryStructure(text="This is a summary")
|
|
43
76
|
"""
|
|
44
77
|
|
|
45
78
|
text: str = spec_field(
|
|
@@ -50,15 +83,30 @@ class SummaryStructure(BaseStructure):
|
|
|
50
83
|
|
|
51
84
|
|
|
52
85
|
class ExtendedSummaryStructure(SummaryStructure):
|
|
53
|
-
"""
|
|
86
|
+
"""Extended summary with optional topic breakdown metadata.
|
|
87
|
+
|
|
88
|
+
Extends SummaryStructure to include topic-level summaries with citations,
|
|
89
|
+
providing more granular insight into the summarization.
|
|
90
|
+
|
|
91
|
+
Attributes
|
|
92
|
+
----------
|
|
93
|
+
metadata : list[SummaryTopic]
|
|
94
|
+
Optional topic-level summaries with supporting citations.
|
|
54
95
|
|
|
55
96
|
Methods
|
|
56
97
|
-------
|
|
57
98
|
print()
|
|
58
99
|
Return a formatted string representation of the stored fields.
|
|
100
|
+
|
|
101
|
+
Examples
|
|
102
|
+
--------
|
|
103
|
+
>>> extended = ExtendedSummaryStructure(
|
|
104
|
+
... text="Overall summary",
|
|
105
|
+
... metadata=[SummaryTopic(topic="T1", summary="S1", citations=[])]
|
|
106
|
+
... )
|
|
59
107
|
"""
|
|
60
108
|
|
|
61
|
-
metadata:
|
|
109
|
+
metadata: list[SummaryTopic] = spec_field(
|
|
62
110
|
"metadata",
|
|
63
111
|
default_factory=list,
|
|
64
112
|
description="Optional topic-level summaries with supporting citations.",
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
"""Structures describing guardrail validation results.
|
|
1
|
+
"""Structures describing guardrail validation results.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module defines Pydantic models for representing the results of guardrail
|
|
4
|
+
validation checks on user inputs and agent outputs.
|
|
5
|
+
"""
|
|
4
6
|
|
|
5
|
-
from
|
|
7
|
+
from __future__ import annotations
|
|
6
8
|
|
|
7
9
|
from .base import BaseStructure, spec_field
|
|
8
10
|
|
|
@@ -10,10 +12,36 @@ from .base import BaseStructure, spec_field
|
|
|
10
12
|
class ValidationResultStructure(BaseStructure):
|
|
11
13
|
"""Capture guardrail validation findings for user and agent messages.
|
|
12
14
|
|
|
15
|
+
Represents the results of safety and policy validation checks performed
|
|
16
|
+
on both user inputs and agent outputs, including detected violations
|
|
17
|
+
and recommended remediation actions.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
input_safe : bool
|
|
22
|
+
Whether the user-provided input is allowed within the guardrails.
|
|
23
|
+
output_safe : bool
|
|
24
|
+
Whether the agent output adheres to the safety guardrails.
|
|
25
|
+
violations : list[str]
|
|
26
|
+
Detected policy or safety issues that require mitigation.
|
|
27
|
+
recommended_actions : list[str]
|
|
28
|
+
Steps to remediate or respond to any detected violations.
|
|
29
|
+
sanitized_output : str or None
|
|
30
|
+
Optional redacted or rewritten text that fits the guardrails.
|
|
31
|
+
|
|
13
32
|
Methods
|
|
14
33
|
-------
|
|
15
34
|
print()
|
|
16
35
|
Return a formatted string representation of the stored fields.
|
|
36
|
+
|
|
37
|
+
Examples
|
|
38
|
+
--------
|
|
39
|
+
>>> result = ValidationResultStructure(
|
|
40
|
+
... input_safe=True,
|
|
41
|
+
... output_safe=True,
|
|
42
|
+
... violations=[],
|
|
43
|
+
... recommended_actions=[]
|
|
44
|
+
... )
|
|
17
45
|
"""
|
|
18
46
|
|
|
19
47
|
input_safe: bool = spec_field(
|
|
@@ -26,19 +54,19 @@ class ValidationResultStructure(BaseStructure):
|
|
|
26
54
|
allow_null=False,
|
|
27
55
|
description="Whether the agent output adheres to the safety guardrails.",
|
|
28
56
|
)
|
|
29
|
-
violations:
|
|
57
|
+
violations: list[str] = spec_field(
|
|
30
58
|
"violations",
|
|
31
59
|
allow_null=False,
|
|
32
60
|
default_factory=list,
|
|
33
61
|
description="Detected policy or safety issues that require mitigation.",
|
|
34
62
|
)
|
|
35
|
-
recommended_actions:
|
|
63
|
+
recommended_actions: list[str] = spec_field(
|
|
36
64
|
"recommended_actions",
|
|
37
65
|
allow_null=False,
|
|
38
66
|
default_factory=list,
|
|
39
67
|
description="Steps to remediate or respond to any detected violations.",
|
|
40
68
|
)
|
|
41
|
-
sanitized_output:
|
|
69
|
+
sanitized_output: str | None = spec_field(
|
|
42
70
|
"sanitized_output",
|
|
43
71
|
description="Optional redacted or rewritten text that fits the guardrails.",
|
|
44
72
|
)
|
|
@@ -1,47 +1,108 @@
|
|
|
1
|
-
"""
|
|
1
|
+
"""Structured output models for vector search workflows.
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
This module defines Pydantic models for representing vector search plans,
|
|
4
|
+
results, and reports. These structures support multi-query vector search
|
|
5
|
+
workflows with error tracking and result aggregation.
|
|
6
|
+
"""
|
|
4
7
|
|
|
5
|
-
from
|
|
8
|
+
from __future__ import annotations
|
|
6
9
|
|
|
7
10
|
from .base import BaseStructure, spec_field
|
|
8
11
|
|
|
9
12
|
|
|
10
13
|
class VectorSearchItemStructure(BaseStructure):
|
|
11
|
-
"""A single vector search to perform.
|
|
14
|
+
"""A single vector search to perform.
|
|
15
|
+
|
|
16
|
+
Represents one vector search query with rationale for its inclusion
|
|
17
|
+
in a multi-query search plan.
|
|
18
|
+
|
|
19
|
+
Attributes
|
|
20
|
+
----------
|
|
21
|
+
reason : str
|
|
22
|
+
Explanation for why this search is needed.
|
|
23
|
+
query : str
|
|
24
|
+
Vector search query text.
|
|
25
|
+
|
|
26
|
+
Examples
|
|
27
|
+
--------
|
|
28
|
+
>>> item = VectorSearchItemStructure(
|
|
29
|
+
... reason="Find related documents",
|
|
30
|
+
... query="machine learning trends"
|
|
31
|
+
... )
|
|
32
|
+
"""
|
|
12
33
|
|
|
13
34
|
reason: str = spec_field("reason")
|
|
14
35
|
query: str = spec_field("query")
|
|
15
36
|
|
|
16
37
|
|
|
17
38
|
class VectorSearchPlanStructure(BaseStructure):
|
|
18
|
-
"""Collection of vector searches required to satisfy the query.
|
|
39
|
+
"""Collection of vector searches required to satisfy the query.
|
|
19
40
|
|
|
20
|
-
|
|
41
|
+
Represents a plan containing multiple vector searches that together
|
|
42
|
+
provide comprehensive coverage for answering a user query.
|
|
43
|
+
|
|
44
|
+
Attributes
|
|
45
|
+
----------
|
|
46
|
+
searches : list[VectorSearchItemStructure]
|
|
47
|
+
List of vector search queries to execute.
|
|
48
|
+
|
|
49
|
+
Examples
|
|
50
|
+
--------
|
|
51
|
+
>>> plan = VectorSearchPlanStructure(
|
|
52
|
+
... searches=[VectorSearchItemStructure(reason="R", query="Q")]
|
|
53
|
+
... )
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
searches: list[VectorSearchItemStructure] = spec_field("searches")
|
|
21
57
|
|
|
22
58
|
|
|
23
59
|
class VectorSearchItemResultStructure(BaseStructure):
|
|
24
|
-
"""Result of a single vector search.
|
|
60
|
+
"""Result of a single vector search.
|
|
25
61
|
|
|
26
|
-
|
|
62
|
+
Contains the text results retrieved from executing one vector search query.
|
|
63
|
+
|
|
64
|
+
Attributes
|
|
65
|
+
----------
|
|
66
|
+
texts : list[str]
|
|
67
|
+
Retrieved text passages from the vector search.
|
|
68
|
+
|
|
69
|
+
Examples
|
|
70
|
+
--------
|
|
71
|
+
>>> result = VectorSearchItemResultStructure(texts=["Result 1", "Result 2"])
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
texts: list[str] = spec_field("texts")
|
|
27
75
|
|
|
28
76
|
|
|
29
77
|
class VectorSearchItemResultsStructure(BaseStructure):
|
|
30
|
-
"""Collection of search results
|
|
78
|
+
"""Collection of search results from multiple queries.
|
|
31
79
|
|
|
32
|
-
|
|
33
|
-
|
|
80
|
+
Aggregates results from multiple vector searches while tracking any
|
|
81
|
+
errors encountered. Failed searches are recorded in the errors list
|
|
82
|
+
to allow inspection of partial outcomes.
|
|
83
|
+
|
|
84
|
+
Attributes
|
|
85
|
+
----------
|
|
86
|
+
item_results : list[VectorSearchItemResultStructure]
|
|
87
|
+
List of successful search results.
|
|
88
|
+
errors : list[str]
|
|
89
|
+
List of error messages from failed searches.
|
|
34
90
|
|
|
35
91
|
Methods
|
|
36
92
|
-------
|
|
37
93
|
append(item)
|
|
38
94
|
Add a search result to the collection.
|
|
95
|
+
|
|
96
|
+
Examples
|
|
97
|
+
--------
|
|
98
|
+
>>> results = VectorSearchItemResultsStructure()
|
|
99
|
+
>>> results.append(VectorSearchItemResultStructure(texts=["Text"]))
|
|
39
100
|
"""
|
|
40
101
|
|
|
41
|
-
item_results:
|
|
102
|
+
item_results: list[VectorSearchItemResultStructure] = spec_field(
|
|
42
103
|
"item_results", default_factory=list
|
|
43
104
|
)
|
|
44
|
-
errors:
|
|
105
|
+
errors: list[str] = spec_field("errors", default_factory=list)
|
|
45
106
|
|
|
46
107
|
def append(self, item: VectorSearchItemResultStructure) -> None:
|
|
47
108
|
"""Add a search result to the collection.
|
|
@@ -59,16 +120,69 @@ class VectorSearchItemResultsStructure(BaseStructure):
|
|
|
59
120
|
|
|
60
121
|
|
|
61
122
|
class VectorSearchReportStructure(BaseStructure):
|
|
62
|
-
"""Structured output from the vector search writer agent.
|
|
123
|
+
"""Structured output from the vector search writer agent.
|
|
124
|
+
|
|
125
|
+
Contains the final synthesized report from vector search results,
|
|
126
|
+
including summary, markdown report, follow-up questions, and sources.
|
|
127
|
+
|
|
128
|
+
Attributes
|
|
129
|
+
----------
|
|
130
|
+
short_summary : str
|
|
131
|
+
Brief summary of the search findings.
|
|
132
|
+
markdown_report : str
|
|
133
|
+
Full markdown-formatted report.
|
|
134
|
+
follow_up_questions : list[str]
|
|
135
|
+
Suggested questions for further exploration.
|
|
136
|
+
sources : list[str]
|
|
137
|
+
Source references used in the report.
|
|
138
|
+
|
|
139
|
+
Examples
|
|
140
|
+
--------
|
|
141
|
+
>>> report = VectorSearchReportStructure(
|
|
142
|
+
... short_summary="Summary",
|
|
143
|
+
... markdown_report="# Report",
|
|
144
|
+
... follow_up_questions=["Q1?"],
|
|
145
|
+
... sources=["Source 1"]
|
|
146
|
+
... )
|
|
147
|
+
"""
|
|
63
148
|
|
|
64
149
|
short_summary: str = spec_field("short_summary")
|
|
65
150
|
markdown_report: str = spec_field("markdown_report")
|
|
66
|
-
follow_up_questions:
|
|
67
|
-
sources:
|
|
151
|
+
follow_up_questions: list[str] = spec_field("follow_up_questions")
|
|
152
|
+
sources: list[str] = spec_field("sources")
|
|
68
153
|
|
|
69
154
|
|
|
70
155
|
class VectorSearchStructure(BaseStructure):
|
|
71
|
-
"""Complete output of a vector search workflow.
|
|
156
|
+
"""Complete output of a vector search workflow.
|
|
157
|
+
|
|
158
|
+
Represents the full lifecycle of a vector search operation, from the
|
|
159
|
+
original query through plan generation, execution, and final report.
|
|
160
|
+
|
|
161
|
+
Attributes
|
|
162
|
+
----------
|
|
163
|
+
query : str
|
|
164
|
+
Original user query.
|
|
165
|
+
plan : VectorSearchPlanStructure
|
|
166
|
+
Generated search plan.
|
|
167
|
+
results : VectorSearchItemResultsStructure
|
|
168
|
+
Aggregated search results.
|
|
169
|
+
report : VectorSearchReportStructure
|
|
170
|
+
Final synthesized report.
|
|
171
|
+
|
|
172
|
+
Examples
|
|
173
|
+
--------
|
|
174
|
+
>>> workflow = VectorSearchStructure(
|
|
175
|
+
... query="Test query",
|
|
176
|
+
... plan=VectorSearchPlanStructure(searches=[]),
|
|
177
|
+
... results=VectorSearchItemResultsStructure(),
|
|
178
|
+
... report=VectorSearchReportStructure(
|
|
179
|
+
... short_summary="S",
|
|
180
|
+
... markdown_report="R",
|
|
181
|
+
... follow_up_questions=[],
|
|
182
|
+
... sources=[]
|
|
183
|
+
... )
|
|
184
|
+
... )
|
|
185
|
+
"""
|
|
72
186
|
|
|
73
187
|
query: str = spec_field("query")
|
|
74
188
|
plan: VectorSearchPlanStructure = spec_field("plan")
|
|
@@ -79,8 +193,8 @@ class VectorSearchStructure(BaseStructure):
|
|
|
79
193
|
__all__ = [
|
|
80
194
|
"VectorSearchReportStructure",
|
|
81
195
|
"VectorSearchItemStructure",
|
|
196
|
+
"VectorSearchPlanStructure",
|
|
82
197
|
"VectorSearchItemResultStructure",
|
|
83
198
|
"VectorSearchItemResultsStructure",
|
|
84
|
-
"VectorSearchPlanStructure",
|
|
85
199
|
"VectorSearchStructure",
|
|
86
200
|
]
|