openai-sdk-helpers 0.4.3__py3-none-any.whl → 0.5.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 +41 -7
- openai_sdk_helpers/agent/__init__.py +1 -2
- openai_sdk_helpers/agent/base.py +89 -173
- openai_sdk_helpers/agent/configuration.py +12 -20
- openai_sdk_helpers/agent/coordinator.py +14 -17
- openai_sdk_helpers/agent/runner.py +3 -45
- openai_sdk_helpers/agent/search/base.py +49 -71
- openai_sdk_helpers/agent/search/vector.py +82 -110
- openai_sdk_helpers/agent/search/web.py +103 -81
- openai_sdk_helpers/agent/summarizer.py +20 -28
- openai_sdk_helpers/agent/translator.py +17 -23
- openai_sdk_helpers/agent/validator.py +17 -23
- openai_sdk_helpers/errors.py +9 -0
- openai_sdk_helpers/extract/__init__.py +23 -0
- openai_sdk_helpers/extract/extractor.py +157 -0
- openai_sdk_helpers/extract/generator.py +476 -0
- openai_sdk_helpers/prompt/extractor_config_agent_instructions.jinja +6 -0
- openai_sdk_helpers/prompt/extractor_config_generator.jinja +37 -0
- openai_sdk_helpers/prompt/extractor_config_generator_instructions.jinja +9 -0
- openai_sdk_helpers/prompt/extractor_prompt_optimizer_agent_instructions.jinja +4 -0
- openai_sdk_helpers/prompt/extractor_prompt_optimizer_request.jinja +11 -0
- openai_sdk_helpers/response/__init__.py +2 -6
- openai_sdk_helpers/response/base.py +85 -94
- openai_sdk_helpers/response/configuration.py +39 -14
- openai_sdk_helpers/response/files.py +2 -0
- openai_sdk_helpers/response/runner.py +1 -48
- openai_sdk_helpers/response/tool_call.py +0 -141
- openai_sdk_helpers/response/vector_store.py +8 -5
- openai_sdk_helpers/streamlit_app/app.py +1 -1
- openai_sdk_helpers/structure/__init__.py +16 -0
- openai_sdk_helpers/structure/base.py +239 -278
- openai_sdk_helpers/structure/extraction.py +1228 -0
- openai_sdk_helpers/structure/plan/plan.py +0 -20
- openai_sdk_helpers/structure/plan/task.py +0 -33
- openai_sdk_helpers/structure/prompt.py +16 -0
- openai_sdk_helpers/structure/responses.py +2 -2
- openai_sdk_helpers/structure/web_search.py +0 -10
- openai_sdk_helpers/tools.py +346 -99
- openai_sdk_helpers/utils/__init__.py +7 -0
- openai_sdk_helpers/utils/json/base_model.py +315 -32
- openai_sdk_helpers/utils/langextract.py +194 -0
- {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.0.dist-info}/METADATA +18 -4
- {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.0.dist-info}/RECORD +46 -37
- openai_sdk_helpers/streamlit_app/streamlit_web_search.py +0 -75
- {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.0.dist-info}/WHEEL +0 -0
- {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.0.dist-info}/entry_points.txt +0 -0
- {openai_sdk_helpers-0.4.3.dist-info → openai_sdk_helpers-0.5.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Any,
|
|
6
|
+
from typing import Any, Dict, Optional, Union
|
|
7
7
|
|
|
8
8
|
from agents import custom_span, gen_trace_id, trace
|
|
9
9
|
from agents.model_settings import ModelSettings
|
|
10
10
|
from agents.tool import WebSearchTool
|
|
11
11
|
|
|
12
12
|
from ...structure.prompt import PromptStructure
|
|
13
|
+
from ..base import AgentBase
|
|
13
14
|
from ...structure.web_search import (
|
|
14
15
|
WebSearchItemStructure,
|
|
15
16
|
WebSearchItemResultStructure,
|
|
@@ -17,10 +18,10 @@ from ...structure.web_search import (
|
|
|
17
18
|
WebSearchPlanStructure,
|
|
18
19
|
WebSearchReportStructure,
|
|
19
20
|
)
|
|
20
|
-
from ...tools import tool_handler_factory
|
|
21
21
|
from ..configuration import AgentConfiguration
|
|
22
22
|
from ..utils import run_coroutine_agent_sync
|
|
23
23
|
from .base import SearchPlanner, SearchToolAgent, SearchWriter
|
|
24
|
+
from ...tools import ToolSpec, ToolHandlerRegistration
|
|
24
25
|
|
|
25
26
|
MAX_CONCURRENT_SEARCHES = 10
|
|
26
27
|
|
|
@@ -30,10 +31,10 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
|
|
|
30
31
|
|
|
31
32
|
Parameters
|
|
32
33
|
----------
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
template_path : Path | str | None, default=None
|
|
35
|
+
Template file path for prompt rendering.
|
|
36
|
+
model : str | None, default=None
|
|
37
|
+
Model identifier to use when not defined in configuration.
|
|
37
38
|
|
|
38
39
|
Methods
|
|
39
40
|
-------
|
|
@@ -43,20 +44,19 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
|
|
|
43
44
|
Raises
|
|
44
45
|
------
|
|
45
46
|
ValueError
|
|
46
|
-
If the
|
|
47
|
+
If the configuration omits a model identifier.
|
|
47
48
|
|
|
48
49
|
Examples
|
|
49
50
|
--------
|
|
50
|
-
>>> planner = WebAgentPlanner(
|
|
51
|
+
>>> planner = WebAgentPlanner(model="gpt-4o-mini")
|
|
51
52
|
"""
|
|
52
53
|
|
|
53
|
-
def
|
|
54
|
-
self,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def _configure_agent(self) -> AgentConfiguration:
|
|
54
|
+
def _configure_agent(
|
|
55
|
+
self,
|
|
56
|
+
template_path: Path | str | None = None,
|
|
57
|
+
model: str | None = None,
|
|
58
|
+
**kwargs: Any,
|
|
59
|
+
) -> AgentConfiguration:
|
|
60
60
|
"""Return configuration for the web planner agent.
|
|
61
61
|
|
|
62
62
|
Returns
|
|
@@ -68,6 +68,8 @@ class WebAgentPlanner(SearchPlanner[WebSearchPlanStructure]):
|
|
|
68
68
|
name="web_planner",
|
|
69
69
|
instructions="Agent instructions",
|
|
70
70
|
description="Agent that plans web searches based on a user query.",
|
|
71
|
+
template_path=template_path,
|
|
72
|
+
model=model,
|
|
71
73
|
output_structure=WebSearchPlanStructure,
|
|
72
74
|
)
|
|
73
75
|
|
|
@@ -81,10 +83,10 @@ class WebSearchToolAgent(
|
|
|
81
83
|
|
|
82
84
|
Parameters
|
|
83
85
|
----------
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
86
|
+
template_path : Path | str | None, default=None
|
|
87
|
+
Template file path for prompt rendering.
|
|
88
|
+
model : str or None, default=None
|
|
89
|
+
Model identifier to use when not defined in configuration.
|
|
88
90
|
|
|
89
91
|
Methods
|
|
90
92
|
-------
|
|
@@ -96,24 +98,20 @@ class WebSearchToolAgent(
|
|
|
96
98
|
Raises
|
|
97
99
|
------
|
|
98
100
|
ValueError
|
|
99
|
-
If the
|
|
101
|
+
If the model is not provided.
|
|
100
102
|
|
|
101
103
|
Examples
|
|
102
104
|
--------
|
|
103
|
-
>>> tool = WebSearchToolAgent(
|
|
105
|
+
>>> tool = WebSearchToolAgent(model="gpt-4o-mini")
|
|
104
106
|
"""
|
|
105
107
|
|
|
106
|
-
def
|
|
107
|
-
self,
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
max_concurrent_searches=MAX_CONCURRENT_SEARCHES,
|
|
114
|
-
)
|
|
115
|
-
|
|
116
|
-
def _configure_agent(self) -> AgentConfiguration:
|
|
108
|
+
def _configure_agent(
|
|
109
|
+
self,
|
|
110
|
+
*,
|
|
111
|
+
template_path: Path | str | None = None,
|
|
112
|
+
model: str | None = None,
|
|
113
|
+
**kwargs: Any,
|
|
114
|
+
) -> AgentConfiguration:
|
|
117
115
|
"""Return configuration for the web search tool agent.
|
|
118
116
|
|
|
119
117
|
Returns
|
|
@@ -125,6 +123,8 @@ class WebSearchToolAgent(
|
|
|
125
123
|
name="web_search",
|
|
126
124
|
instructions="Agent instructions",
|
|
127
125
|
description="Agent that performs web searches and summarizes results.",
|
|
126
|
+
template_path=template_path,
|
|
127
|
+
model=model,
|
|
128
128
|
input_structure=WebSearchPlanStructure,
|
|
129
129
|
tools=[WebSearchTool()],
|
|
130
130
|
model_settings=ModelSettings(tool_choice="required"),
|
|
@@ -186,10 +186,10 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
|
|
|
186
186
|
|
|
187
187
|
Parameters
|
|
188
188
|
----------
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
189
|
+
template_path : Path | str | None, default=None
|
|
190
|
+
Template file path for prompt rendering.
|
|
191
|
+
model : str | None, default=None
|
|
192
|
+
Model identifier to use when not defined in configuration.
|
|
193
193
|
|
|
194
194
|
Methods
|
|
195
195
|
-------
|
|
@@ -199,20 +199,31 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
|
|
|
199
199
|
Raises
|
|
200
200
|
------
|
|
201
201
|
ValueError
|
|
202
|
-
If the
|
|
202
|
+
If the configuration omits a model identifier.
|
|
203
203
|
|
|
204
204
|
Examples
|
|
205
205
|
--------
|
|
206
|
-
>>> writer = WebAgentWriter(
|
|
206
|
+
>>> writer = WebAgentWriter(model="gpt-4o-mini")
|
|
207
207
|
"""
|
|
208
208
|
|
|
209
209
|
def __init__(
|
|
210
|
-
self,
|
|
210
|
+
self,
|
|
211
|
+
template_path: Path | str | None = None,
|
|
212
|
+
model: str | None = None,
|
|
213
|
+
**kwargs: Any,
|
|
211
214
|
) -> None:
|
|
212
215
|
"""Initialize the writer agent."""
|
|
213
|
-
|
|
216
|
+
configuration = self._configure_agent(
|
|
217
|
+
template_path=template_path, model=model, **kwargs
|
|
218
|
+
)
|
|
219
|
+
super().__init__(configuration=configuration)
|
|
214
220
|
|
|
215
|
-
def _configure_agent(
|
|
221
|
+
def _configure_agent(
|
|
222
|
+
self,
|
|
223
|
+
template_path: Path | str | None = None,
|
|
224
|
+
model: str | None = None,
|
|
225
|
+
**kwargs: Any,
|
|
226
|
+
) -> AgentConfiguration:
|
|
216
227
|
"""Return configuration for the web writer agent.
|
|
217
228
|
|
|
218
229
|
Returns
|
|
@@ -224,19 +235,21 @@ class WebAgentWriter(SearchWriter[WebSearchReportStructure]):
|
|
|
224
235
|
name="web_writer",
|
|
225
236
|
instructions="Agent instructions",
|
|
226
237
|
description="Agent that writes a report based on web search results.",
|
|
238
|
+
template_path=template_path,
|
|
239
|
+
model=model,
|
|
227
240
|
output_structure=WebSearchReportStructure,
|
|
228
241
|
)
|
|
229
242
|
|
|
230
243
|
|
|
231
|
-
class WebAgentSearch:
|
|
244
|
+
class WebAgentSearch(AgentBase):
|
|
232
245
|
"""Manage the complete web search workflow.
|
|
233
246
|
|
|
234
247
|
Parameters
|
|
235
248
|
----------
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
249
|
+
template_path : Path | str | None, default=None
|
|
250
|
+
Template file path for prompt rendering.
|
|
251
|
+
model : str | None, default=None
|
|
252
|
+
Model identifier to use when not defined in configuration.
|
|
240
253
|
|
|
241
254
|
Methods
|
|
242
255
|
-------
|
|
@@ -254,21 +267,36 @@ class WebAgentSearch:
|
|
|
254
267
|
Raises
|
|
255
268
|
------
|
|
256
269
|
ValueError
|
|
257
|
-
If the
|
|
270
|
+
If the model identifier is not provided.
|
|
258
271
|
|
|
259
272
|
Examples
|
|
260
273
|
--------
|
|
261
|
-
>>> search = WebAgentSearch(
|
|
274
|
+
>>> search = WebAgentSearch(model="gpt-4o-mini")
|
|
262
275
|
"""
|
|
263
276
|
|
|
264
277
|
def __init__(
|
|
265
278
|
self,
|
|
266
|
-
|
|
267
|
-
|
|
279
|
+
*,
|
|
280
|
+
template_path: Path | str | None = None,
|
|
281
|
+
model: str | None = None,
|
|
268
282
|
) -> None:
|
|
269
|
-
"""
|
|
270
|
-
|
|
271
|
-
|
|
283
|
+
"""Initialize the web search orchestration agent.
|
|
284
|
+
|
|
285
|
+
Parameters
|
|
286
|
+
----------
|
|
287
|
+
template_path : Path | str | None, default=None
|
|
288
|
+
Optional template file path for prompt rendering.
|
|
289
|
+
model : str | None, default=None
|
|
290
|
+
Model identifier to use when not defined in configuration.
|
|
291
|
+
"""
|
|
292
|
+
configuration = AgentConfiguration(
|
|
293
|
+
name="web_agent_search",
|
|
294
|
+
instructions="Agent instructions",
|
|
295
|
+
description="Run a multi-step web search workflow.",
|
|
296
|
+
template_path=template_path,
|
|
297
|
+
model=model,
|
|
298
|
+
)
|
|
299
|
+
super().__init__(configuration=configuration)
|
|
272
300
|
|
|
273
301
|
async def run_agent_async(self, search_query: str) -> WebSearchStructure:
|
|
274
302
|
"""Execute the entire research workflow for ``search_query``.
|
|
@@ -286,14 +314,12 @@ class WebAgentSearch:
|
|
|
286
314
|
trace_id = gen_trace_id()
|
|
287
315
|
with trace("WebAgentSearch trace", trace_id=trace_id):
|
|
288
316
|
planner = WebAgentPlanner(
|
|
289
|
-
|
|
317
|
+
template_path=self._template_path, model=self.model
|
|
290
318
|
)
|
|
291
319
|
tool = WebSearchToolAgent(
|
|
292
|
-
|
|
293
|
-
)
|
|
294
|
-
writer = WebAgentWriter(
|
|
295
|
-
prompt_dir=self._prompt_dir, default_model=self._default_model
|
|
320
|
+
template_path=self._template_path, model=self.model
|
|
296
321
|
)
|
|
322
|
+
writer = WebAgentWriter(template_path=self._template_path, model=self.model)
|
|
297
323
|
search_plan = await planner.run_agent(query=search_query)
|
|
298
324
|
search_results = await tool.run_agent(search_plan=search_plan)
|
|
299
325
|
search_report = await writer.run_agent(search_query, search_results)
|
|
@@ -320,37 +346,33 @@ class WebAgentSearch:
|
|
|
320
346
|
"""
|
|
321
347
|
return run_coroutine_agent_sync(self.run_agent_async(search_query))
|
|
322
348
|
|
|
323
|
-
def
|
|
324
|
-
self,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
tool_description: str = "Run the web search workflow.",
|
|
328
|
-
) -> tuple[dict[str, Callable[..., Any]], dict[str, Any]]:
|
|
329
|
-
"""Return a Responses API tool handler and definition.
|
|
349
|
+
def as_tool_registration(
|
|
350
|
+
self, tool_name: str, tool_description: str
|
|
351
|
+
) -> ToolHandlerRegistration:
|
|
352
|
+
"""Build a Responses API tool definition and handler for the web search agent.
|
|
330
353
|
|
|
331
354
|
Parameters
|
|
332
355
|
----------
|
|
333
|
-
tool_name : str
|
|
334
|
-
Name
|
|
335
|
-
tool_description : str
|
|
336
|
-
Description
|
|
356
|
+
tool_name : str
|
|
357
|
+
Name of the tool.
|
|
358
|
+
tool_description : str
|
|
359
|
+
Description of the tool.
|
|
337
360
|
|
|
338
361
|
Returns
|
|
339
362
|
-------
|
|
340
|
-
|
|
341
|
-
Tool
|
|
363
|
+
ToolHandlerRegistration
|
|
364
|
+
Tool definition and handler for the Responses API.
|
|
342
365
|
"""
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
366
|
+
tool_spec = ToolSpec(
|
|
367
|
+
input_structure=PromptStructure,
|
|
368
|
+
tool_name=tool_name,
|
|
369
|
+
tool_description=tool_description,
|
|
370
|
+
output_structure=WebSearchStructure,
|
|
371
|
+
)
|
|
372
|
+
return ToolHandlerRegistration(
|
|
373
|
+
handler=self.run_agent_sync,
|
|
374
|
+
tool_spec=tool_spec,
|
|
352
375
|
)
|
|
353
|
-
return tool_handler, tool_definition
|
|
354
376
|
|
|
355
377
|
|
|
356
378
|
__all__ = [
|
|
@@ -3,13 +3,12 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
from pathlib import Path
|
|
6
|
-
from typing import Any, Dict, Optional
|
|
6
|
+
from typing import Any, Dict, Optional
|
|
7
7
|
|
|
8
8
|
from ..structure import SummaryStructure
|
|
9
9
|
from ..structure.base import StructureBase
|
|
10
10
|
from .base import AgentBase
|
|
11
11
|
from .configuration import AgentConfiguration
|
|
12
|
-
from ..environment import DEFAULT_PROMPT_DIR
|
|
13
12
|
|
|
14
13
|
|
|
15
14
|
class SummarizerAgent(AgentBase):
|
|
@@ -21,11 +20,10 @@ class SummarizerAgent(AgentBase):
|
|
|
21
20
|
|
|
22
21
|
Parameters
|
|
23
22
|
----------
|
|
24
|
-
|
|
25
|
-
Optional
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
Fallback model identifier when not specified elsewhere.
|
|
23
|
+
template_path : Path | str | None, default=None
|
|
24
|
+
Optional template file path for prompt rendering.
|
|
25
|
+
model : str | None, default=None
|
|
26
|
+
Model identifier to use for summarization.
|
|
29
27
|
output_structure : type[StructureBase], default=SummaryStructure
|
|
30
28
|
Type describing the expected summary output.
|
|
31
29
|
|
|
@@ -34,7 +32,7 @@ class SummarizerAgent(AgentBase):
|
|
|
34
32
|
Basic usage with default settings:
|
|
35
33
|
|
|
36
34
|
>>> from openai_sdk_helpers.agent import SummarizerAgent
|
|
37
|
-
>>> summarizer = SummarizerAgent(
|
|
35
|
+
>>> summarizer = SummarizerAgent(model="gpt-4o-mini")
|
|
38
36
|
>>> summary = summarizer.run_sync("Long text to summarize...")
|
|
39
37
|
>>> print(summary.text)
|
|
40
38
|
|
|
@@ -42,7 +40,7 @@ class SummarizerAgent(AgentBase):
|
|
|
42
40
|
|
|
43
41
|
>>> import asyncio
|
|
44
42
|
>>> async def main():
|
|
45
|
-
... summarizer = SummarizerAgent(
|
|
43
|
+
... summarizer = SummarizerAgent(model="gpt-4o-mini")
|
|
46
44
|
... result = await summarizer.run_agent(
|
|
47
45
|
... text="Article content...",
|
|
48
46
|
... metadata={"source": "news.txt", "date": "2025-01-01"}
|
|
@@ -59,44 +57,38 @@ class SummarizerAgent(AgentBase):
|
|
|
59
57
|
def __init__(
|
|
60
58
|
self,
|
|
61
59
|
*,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
output_structure: Type[StructureBase] = SummaryStructure,
|
|
60
|
+
template_path: Path | str | None = None,
|
|
61
|
+
model: str | None = None,
|
|
65
62
|
) -> None:
|
|
66
63
|
"""Initialize the summarizer agent configuration.
|
|
67
64
|
|
|
68
65
|
Parameters
|
|
69
66
|
----------
|
|
70
|
-
|
|
71
|
-
Optional
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
Fallback model identifier when not specified elsewhere.
|
|
75
|
-
output_structure : type[StructureBase], default=SummaryStructure
|
|
76
|
-
Type describing the expected summary output.
|
|
67
|
+
template_path : Path | str | None, default=None
|
|
68
|
+
Optional template file path for prompt rendering.
|
|
69
|
+
model : str | None, default=None
|
|
70
|
+
Model identifier to use for summarization.
|
|
77
71
|
|
|
78
72
|
Raises
|
|
79
73
|
------
|
|
80
74
|
ValueError
|
|
81
|
-
If the
|
|
75
|
+
If the model is not provided.
|
|
82
76
|
|
|
83
77
|
Examples
|
|
84
78
|
--------
|
|
85
|
-
>>> summarizer = SummarizerAgent(
|
|
79
|
+
>>> summarizer = SummarizerAgent(model="gpt-4o-mini")
|
|
86
80
|
"""
|
|
87
81
|
configuration = AgentConfiguration(
|
|
88
82
|
name="summarizer",
|
|
89
83
|
instructions="Agent instructions",
|
|
90
84
|
description="Summarize passages into concise findings.",
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
super().__init__(
|
|
95
|
-
configuration=configuration,
|
|
96
|
-
prompt_dir=prompt_directory,
|
|
97
|
-
default_model=default_model,
|
|
85
|
+
template_path=template_path,
|
|
86
|
+
output_structure=SummaryStructure,
|
|
87
|
+
model=model,
|
|
98
88
|
)
|
|
99
89
|
|
|
90
|
+
super().__init__(configuration=configuration)
|
|
91
|
+
|
|
100
92
|
async def run_agent(
|
|
101
93
|
self, text: str, metadata: Optional[Dict[str, Any]] = None
|
|
102
94
|
) -> Any:
|
|
@@ -8,7 +8,6 @@ from typing import Any, Dict, Optional
|
|
|
8
8
|
|
|
9
9
|
from ..structure import TranslationStructure
|
|
10
10
|
from ..structure.base import StructureBase
|
|
11
|
-
from ..environment import DEFAULT_PROMPT_DIR
|
|
12
11
|
|
|
13
12
|
from .base import AgentBase
|
|
14
13
|
from .configuration import AgentConfiguration
|
|
@@ -22,18 +21,17 @@ class TranslatorAgent(AgentBase):
|
|
|
22
21
|
|
|
23
22
|
Parameters
|
|
24
23
|
----------
|
|
25
|
-
|
|
26
|
-
Optional
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
Fallback model identifier when not specified elsewhere.
|
|
24
|
+
template_path : Path | str | None, default=None
|
|
25
|
+
Optional template file path for prompt rendering.
|
|
26
|
+
model : str | None, default=None
|
|
27
|
+
Model identifier to use for translation.
|
|
30
28
|
|
|
31
29
|
Examples
|
|
32
30
|
--------
|
|
33
31
|
Basic translation:
|
|
34
32
|
|
|
35
33
|
>>> from openai_sdk_helpers.agent import TranslatorAgent
|
|
36
|
-
>>> translator = TranslatorAgent(
|
|
34
|
+
>>> translator = TranslatorAgent(model="gpt-4o-mini")
|
|
37
35
|
>>> result = translator.run_sync("Hello world", target_language="Spanish")
|
|
38
36
|
>>> print(result.text)
|
|
39
37
|
'Hola mundo'
|
|
@@ -42,7 +40,7 @@ class TranslatorAgent(AgentBase):
|
|
|
42
40
|
|
|
43
41
|
>>> import asyncio
|
|
44
42
|
>>> async def main():
|
|
45
|
-
... translator = TranslatorAgent(
|
|
43
|
+
... translator = TranslatorAgent(model="gpt-4o-mini")
|
|
46
44
|
... result = await translator.run_agent(
|
|
47
45
|
... text="Good morning",
|
|
48
46
|
... target_language="French",
|
|
@@ -62,40 +60,36 @@ class TranslatorAgent(AgentBase):
|
|
|
62
60
|
def __init__(
|
|
63
61
|
self,
|
|
64
62
|
*,
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
template_path: Path | str | None = None,
|
|
64
|
+
model: str | None = None,
|
|
67
65
|
) -> None:
|
|
68
66
|
"""Initialize the translation agent configuration.
|
|
69
67
|
|
|
70
68
|
Parameters
|
|
71
69
|
----------
|
|
72
|
-
|
|
73
|
-
Optional
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
Fallback model identifier when not specified elsewhere.
|
|
70
|
+
template_path : Path | str | None, default=None
|
|
71
|
+
Optional template file path for prompt rendering.
|
|
72
|
+
model : str | None, default=None
|
|
73
|
+
Model identifier to use for translation.
|
|
77
74
|
|
|
78
75
|
Raises
|
|
79
76
|
------
|
|
80
77
|
ValueError
|
|
81
|
-
If the
|
|
78
|
+
If the model is not provided.
|
|
82
79
|
|
|
83
80
|
Examples
|
|
84
81
|
--------
|
|
85
|
-
>>> translator = TranslatorAgent(
|
|
82
|
+
>>> translator = TranslatorAgent(model="gpt-4o-mini")
|
|
86
83
|
"""
|
|
87
84
|
configuration = AgentConfiguration(
|
|
88
85
|
name="translator",
|
|
89
86
|
instructions="Agent instructions",
|
|
90
87
|
description="Translate text into the requested language.",
|
|
88
|
+
template_path=template_path,
|
|
91
89
|
output_structure=TranslationStructure,
|
|
90
|
+
model=model,
|
|
92
91
|
)
|
|
93
|
-
|
|
94
|
-
super().__init__(
|
|
95
|
-
configuration=configuration,
|
|
96
|
-
prompt_dir=prompt_directory,
|
|
97
|
-
default_model=default_model,
|
|
98
|
-
)
|
|
92
|
+
super().__init__(configuration=configuration)
|
|
99
93
|
|
|
100
94
|
async def run_agent(
|
|
101
95
|
self,
|
|
@@ -5,7 +5,6 @@ from __future__ import annotations
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any, Dict, Optional
|
|
7
7
|
|
|
8
|
-
from ..environment import DEFAULT_PROMPT_DIR
|
|
9
8
|
from ..structure.validation import ValidationResultStructure
|
|
10
9
|
from .base import AgentBase
|
|
11
10
|
from .configuration import AgentConfiguration
|
|
@@ -20,18 +19,17 @@ class ValidatorAgent(AgentBase):
|
|
|
20
19
|
|
|
21
20
|
Parameters
|
|
22
21
|
----------
|
|
23
|
-
|
|
24
|
-
Optional
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Fallback model identifier when not specified elsewhere.
|
|
22
|
+
template_path : Path | str | None, default=None
|
|
23
|
+
Optional template file path for prompt rendering.
|
|
24
|
+
model : str | None, default=None
|
|
25
|
+
Model identifier to use for validation.
|
|
28
26
|
|
|
29
27
|
Examples
|
|
30
28
|
--------
|
|
31
29
|
Validate user input:
|
|
32
30
|
|
|
33
31
|
>>> from openai_sdk_helpers.agent import ValidatorAgent
|
|
34
|
-
>>> validator = ValidatorAgent(
|
|
32
|
+
>>> validator = ValidatorAgent(model="gpt-4o-mini")
|
|
35
33
|
>>> result = validator.run_sync("Tell me about Python programming")
|
|
36
34
|
>>> print(result.input_safe) # True
|
|
37
35
|
>>> print(result.violations) # []
|
|
@@ -40,7 +38,7 @@ class ValidatorAgent(AgentBase):
|
|
|
40
38
|
|
|
41
39
|
>>> import asyncio
|
|
42
40
|
>>> async def main():
|
|
43
|
-
... validator = ValidatorAgent(
|
|
41
|
+
... validator = ValidatorAgent(model="gpt-4o-mini")
|
|
44
42
|
... result = await validator.run_agent(
|
|
45
43
|
... user_input="Summarize this document",
|
|
46
44
|
... agent_output="Summary containing PII...",
|
|
@@ -59,40 +57,36 @@ class ValidatorAgent(AgentBase):
|
|
|
59
57
|
def __init__(
|
|
60
58
|
self,
|
|
61
59
|
*,
|
|
62
|
-
|
|
63
|
-
|
|
60
|
+
template_path: Path | str | None = None,
|
|
61
|
+
model: str | None = None,
|
|
64
62
|
) -> None:
|
|
65
63
|
"""Initialize the validator agent configuration.
|
|
66
64
|
|
|
67
65
|
Parameters
|
|
68
66
|
----------
|
|
69
|
-
|
|
70
|
-
Optional
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
Fallback model identifier when not specified elsewhere.
|
|
67
|
+
template_path : Path | str | None, default=None
|
|
68
|
+
Optional template file path for prompt rendering.
|
|
69
|
+
model : str | None, default=None
|
|
70
|
+
Model identifier to use for validation.
|
|
74
71
|
|
|
75
72
|
Raises
|
|
76
73
|
------
|
|
77
74
|
ValueError
|
|
78
|
-
If the
|
|
75
|
+
If the model is not provided.
|
|
79
76
|
|
|
80
77
|
Examples
|
|
81
78
|
--------
|
|
82
|
-
>>> validator = ValidatorAgent(
|
|
79
|
+
>>> validator = ValidatorAgent(model="gpt-4o-mini")
|
|
83
80
|
"""
|
|
84
81
|
configuration = AgentConfiguration(
|
|
85
82
|
name="validator",
|
|
86
83
|
instructions="Agent instructions",
|
|
87
84
|
description="Validate user input and agent output against guardrails.",
|
|
85
|
+
template_path=template_path,
|
|
88
86
|
output_structure=ValidationResultStructure,
|
|
87
|
+
model=model,
|
|
89
88
|
)
|
|
90
|
-
|
|
91
|
-
super().__init__(
|
|
92
|
-
configuration=configuration,
|
|
93
|
-
prompt_dir=prompt_directory,
|
|
94
|
-
default_model=default_model,
|
|
95
|
-
)
|
|
89
|
+
super().__init__(configuration=configuration)
|
|
96
90
|
|
|
97
91
|
async def run_agent(
|
|
98
92
|
self,
|
openai_sdk_helpers/errors.py
CHANGED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""LangExtract-powered document extraction helpers."""
|
|
2
|
+
|
|
3
|
+
from .extractor import DocumentExtractor
|
|
4
|
+
from .generator import (
|
|
5
|
+
EXTRACTOR_CONFIG_GENERATOR,
|
|
6
|
+
EXTRACTOR_CONFIG_AGENT_INSTRUCTIONS,
|
|
7
|
+
PROMPT_OPTIMIZER_AGENT_INSTRUCTIONS,
|
|
8
|
+
generate_document_extractor_config,
|
|
9
|
+
generate_document_extractor_config_with_agent,
|
|
10
|
+
optimize_extractor_prompt,
|
|
11
|
+
optimize_extractor_prompt_with_agent,
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"DocumentExtractor",
|
|
16
|
+
"EXTRACTOR_CONFIG_GENERATOR",
|
|
17
|
+
"EXTRACTOR_CONFIG_AGENT_INSTRUCTIONS",
|
|
18
|
+
"PROMPT_OPTIMIZER_AGENT_INSTRUCTIONS",
|
|
19
|
+
"generate_document_extractor_config",
|
|
20
|
+
"generate_document_extractor_config_with_agent",
|
|
21
|
+
"optimize_extractor_prompt",
|
|
22
|
+
"optimize_extractor_prompt_with_agent",
|
|
23
|
+
]
|