openai-sdk-helpers 0.0.8__tar.gz → 0.1.0__tar.gz
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-0.1.0/PKG-INFO +550 -0
- openai_sdk_helpers-0.1.0/README.md +525 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/pyproject.toml +3 -4
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/__init__.py +161 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/__init__.py +8 -4
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/base.py +80 -45
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/config.py +6 -4
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/agent/project_manager.py → openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/coordination.py +29 -45
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/prompt_utils.py +15 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/runner.py +141 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/search/__init__.py +33 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/search/base.py +297 -0
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/agent/vector_search.py → openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/search/vector.py +89 -157
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/agent/web_search.py → openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/agent/search/web.py +77 -156
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/summarizer.py +29 -8
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/translator.py +40 -13
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/validation.py +32 -8
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/async_utils.py +132 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/config.py +235 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/context_manager.py +241 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/enums/__init__.py +15 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/enums/base.py +88 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/environment.py +54 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/errors.py +133 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/logging_config.py +105 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/prompt/__init__.py +16 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/prompt/base.py +222 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/response/__init__.py +55 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/response/base.py +743 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/response/config.py +318 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/response/messages.py +56 -40
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/response/runner.py +148 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/response/tool_call.py +144 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/response/vector_store.py +27 -14
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/retry.py +175 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/streamlit_app/__init__.py +30 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/streamlit_app/app.py +114 -39
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/streamlit_app/config.py +502 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/streamlit_app/streamlit_web_search.py +5 -6
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/__init__.py +112 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/agent_blueprint.py +82 -19
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/base.py +208 -93
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/plan/__init__.py +41 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/plan/enum.py +41 -5
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/plan/helpers.py +172 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/plan/plan.py +109 -49
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/plan/task.py +38 -6
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/plan/types.py +15 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/prompt.py +43 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/structure/responses.py +52 -11
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/summary.py +113 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/validation.py +75 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/vector_search.py +200 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/structure/web_search.py +162 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/tools.py +193 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/types.py +57 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/utils/__init__.py +60 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/utils/core.py +596 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/validation.py +302 -0
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/vector_storage/__init__.py +35 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/vector_storage/cleanup.py +25 -13
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/vector_storage/storage.py +123 -64
- openai_sdk_helpers-0.1.0/src/openai_sdk_helpers/vector_storage/types.py +59 -0
- openai_sdk_helpers-0.0.8/PKG-INFO +0 -194
- openai_sdk_helpers-0.0.8/README.md +0 -177
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/__init__.py +0 -73
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/agent/prompt_utils.py +0 -9
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/agent/runner.py +0 -215
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/config.py +0 -199
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/enums/__init__.py +0 -7
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/enums/base.py +0 -29
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/environment.py +0 -27
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/prompt/__init__.py +0 -77
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/response/__init__.py +0 -20
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/response/base.py +0 -590
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/response/runner.py +0 -104
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/response/tool_call.py +0 -109
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/streamlit_app/__init__.py +0 -13
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/streamlit_app/configuration.py +0 -324
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/__init__.py +0 -43
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/plan/__init__.py +0 -13
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/prompt.py +0 -24
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/summary.py +0 -65
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/validation.py +0 -47
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/vector_search.py +0 -86
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/structure/web_search.py +0 -50
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/utils/__init__.py +0 -27
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/utils/core.py +0 -334
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/vector_storage/__init__.py +0 -15
- openai_sdk_helpers-0.0.8/src/openai_sdk_helpers/vector_storage/types.py +0 -58
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/.gitignore +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/LICENSE +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/agent/utils.py +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/prompt/summarizer.jinja +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/prompt/translator.jinja +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/prompt/validator.jinja +0 -0
- {openai_sdk_helpers-0.0.8 → openai_sdk_helpers-0.1.0}/src/openai_sdk_helpers/py.typed +0 -0
|
@@ -0,0 +1,550 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: openai-sdk-helpers
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Composable helpers for OpenAI SDK agents, prompts, and storage
|
|
5
|
+
Author: openai-sdk-helpers maintainers
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.10
|
|
9
|
+
Requires-Dist: jinja2
|
|
10
|
+
Requires-Dist: openai
|
|
11
|
+
Requires-Dist: openai-agents
|
|
12
|
+
Requires-Dist: pydantic<3,>=2.7
|
|
13
|
+
Requires-Dist: python-dotenv
|
|
14
|
+
Requires-Dist: streamlit
|
|
15
|
+
Requires-Dist: typing-extensions<5,>=4.15.0
|
|
16
|
+
Provides-Extra: dev
|
|
17
|
+
Requires-Dist: black; extra == 'dev'
|
|
18
|
+
Requires-Dist: black[jupyter]; extra == 'dev'
|
|
19
|
+
Requires-Dist: pydocstyle; extra == 'dev'
|
|
20
|
+
Requires-Dist: pyright; extra == 'dev'
|
|
21
|
+
Requires-Dist: pytest; extra == 'dev'
|
|
22
|
+
Requires-Dist: pytest-asyncio; extra == 'dev'
|
|
23
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
<div align="center">
|
|
27
|
+
|
|
28
|
+
# openai-sdk-helpers
|
|
29
|
+
|
|
30
|
+
[](https://pypi.org/project/openai-sdk-helpers/)
|
|
31
|
+
[](https://pypi.org/project/openai-sdk-helpers/)
|
|
32
|
+
[](https://opensource.org/licenses/MIT)
|
|
33
|
+
|
|
34
|
+
Shared primitives for composing OpenAI workflows: high-level agent abstractions
|
|
35
|
+
(via `openai-agents` SDK) and low-level response handling (via `openai` SDK),
|
|
36
|
+
plus structures, prompt rendering, and reusable utilities.
|
|
37
|
+
|
|
38
|
+
[Installation](#installation) •
|
|
39
|
+
[Quickstart](#quickstart) •
|
|
40
|
+
[Features](#features) •
|
|
41
|
+
[Documentation](#key-modules) •
|
|
42
|
+
[Contributing](#contributing)
|
|
43
|
+
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
## Table of Contents
|
|
47
|
+
|
|
48
|
+
- [Overview](#overview)
|
|
49
|
+
- [Features](#features)
|
|
50
|
+
- [Requirements](#requirements)
|
|
51
|
+
- [Installation](#installation)
|
|
52
|
+
- [Quickstart](#quickstart)
|
|
53
|
+
- [Text utilities](#text-utilities)
|
|
54
|
+
- [Centralized OpenAI configuration](#centralized-openai-configuration)
|
|
55
|
+
- [Advanced Usage](#advanced-usage)
|
|
56
|
+
- [Development](#development)
|
|
57
|
+
- [Project Structure](#project-structure)
|
|
58
|
+
- [Key modules](#key-modules)
|
|
59
|
+
- [Contributing](#contributing)
|
|
60
|
+
- [License](#license)
|
|
61
|
+
- [Troubleshooting](#troubleshooting)
|
|
62
|
+
|
|
63
|
+
## Overview
|
|
64
|
+
|
|
65
|
+
`openai-sdk-helpers` packages the common building blocks required to assemble agent-driven
|
|
66
|
+
applications. The library intentionally focuses on reusable primitives—data
|
|
67
|
+
structures, configuration helpers, and orchestration utilities—while leaving
|
|
68
|
+
application-specific prompts and tools to the consuming project.
|
|
69
|
+
|
|
70
|
+
**Important**: This library integrates with **two distinct OpenAI SDKs**:
|
|
71
|
+
- **`openai-agents`** - Used by the `agent` module for high-level agent workflows with automatic tool handling and streaming
|
|
72
|
+
- **`openai`** - Used by the `response` module for direct API interactions with fine-grained control over responses
|
|
73
|
+
|
|
74
|
+
The `agent` module provides a higher-level abstraction for building agents, while the `response` module offers lower-level control for custom response handling workflows.
|
|
75
|
+
|
|
76
|
+
### Key Features
|
|
77
|
+
|
|
78
|
+
#### Agent Module (Built on `openai-agents` SDK)
|
|
79
|
+
- **Agent wrappers** with synchronous and asynchronous entry points
|
|
80
|
+
- **Prompt rendering** powered by Jinja2 for dynamic agent instructions
|
|
81
|
+
- **Vector and web search flows** that coordinate planning, execution, and
|
|
82
|
+
reporting with built-in concurrency control
|
|
83
|
+
- **Reusable text agents** for common tasks:
|
|
84
|
+
- **SummarizerAgent**: Generate concise summaries from provided text
|
|
85
|
+
- **TranslatorAgent**: Translate text into target languages
|
|
86
|
+
- **ValidatorAgent**: Check inputs and outputs against safety guardrails
|
|
87
|
+
|
|
88
|
+
#### Response Module (Built on `openai` SDK)
|
|
89
|
+
- **Response handling utilities** for direct API control with fine-grained message management
|
|
90
|
+
- **Tool execution framework** with custom handlers and structured outputs
|
|
91
|
+
- **Session persistence** for saving and restoring conversation history
|
|
92
|
+
|
|
93
|
+
#### Shared Components
|
|
94
|
+
- **Typed structures** using Pydantic for prompts, responses, and search workflows
|
|
95
|
+
to ensure predictable inputs and outputs
|
|
96
|
+
- **OpenAI configuration management** with environment variable and `.env` file support
|
|
97
|
+
- **Vector storage abstraction** for seamless integration with OpenAI vector stores
|
|
98
|
+
- **Type-safe interfaces** with full type hints and `py.typed` marker for external projects
|
|
99
|
+
|
|
100
|
+
## Requirements
|
|
101
|
+
|
|
102
|
+
- Python 3.10 or higher
|
|
103
|
+
- OpenAI API key (set via `OPENAI_API_KEY` environment variable)
|
|
104
|
+
|
|
105
|
+
**Note**: This package depends on both:
|
|
106
|
+
- `openai` - The standard OpenAI Python SDK
|
|
107
|
+
- `openai-agents` - The OpenAI Agents SDK for high-level agent workflows
|
|
108
|
+
|
|
109
|
+
Both are automatically installed when you install `openai-sdk-helpers`.
|
|
110
|
+
|
|
111
|
+
## Installation
|
|
112
|
+
|
|
113
|
+
Install the package directly from PyPI:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
pip install openai-sdk-helpers
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
The package ships with type information via `py.typed`, enabling full type checking
|
|
120
|
+
support in your IDE and with tools like mypy and pyright.
|
|
121
|
+
|
|
122
|
+
### Development Installation
|
|
123
|
+
|
|
124
|
+
For local development with editable sources and optional dev dependencies:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Clone the repository
|
|
128
|
+
git clone https://github.com/fatmambot33/openai-sdk-helpers.git
|
|
129
|
+
cd openai-sdk-helpers
|
|
130
|
+
|
|
131
|
+
# Install in editable mode with dev dependencies
|
|
132
|
+
pip install -e .[dev]
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
The dev dependencies include:
|
|
136
|
+
- `pydocstyle` - Docstring style checking
|
|
137
|
+
- `pyright` - Static type checking
|
|
138
|
+
- `black` - Code formatting
|
|
139
|
+
- `pytest` and `pytest-cov` - Testing and coverage
|
|
140
|
+
|
|
141
|
+
## Quickstart
|
|
142
|
+
|
|
143
|
+
### Basic Vector Search
|
|
144
|
+
|
|
145
|
+
Create a vector search workflow by wiring your own prompt templates and
|
|
146
|
+
preferred model configuration. This example uses the `agent` module built on `openai-agents` SDK:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
from pathlib import Path
|
|
150
|
+
from openai_sdk_helpers.agent.search.vector import VectorSearch
|
|
151
|
+
|
|
152
|
+
# Point to your custom prompt directory
|
|
153
|
+
prompts = Path("./prompts")
|
|
154
|
+
|
|
155
|
+
# Create and configure the vector search agent
|
|
156
|
+
vector_search = VectorSearch(
|
|
157
|
+
prompt_dir=prompts,
|
|
158
|
+
default_model="gpt-4o-mini"
|
|
159
|
+
)
|
|
160
|
+
|
|
161
|
+
# Run a synchronous search query
|
|
162
|
+
report = vector_search.run_agent_sync("Explain quantum entanglement for beginners")
|
|
163
|
+
print(report.report)
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
**Note**: The vector search workflow requires prompt templates for each agent
|
|
167
|
+
(`vector_planner.jinja`, `vector_search.jinja`, and `vector_writer.jinja`).
|
|
168
|
+
If your `prompt_dir` doesn't contain these files, agent construction will fail
|
|
169
|
+
with a `FileNotFoundError`.
|
|
170
|
+
|
|
171
|
+
### Text utilities
|
|
172
|
+
|
|
173
|
+
The built-in text helpers provide lightweight single-step agents for common tasks.
|
|
174
|
+
These use the `agent` module built on `openai-agents` SDK:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from openai_sdk_helpers.agent import (
|
|
178
|
+
SummarizerAgent,
|
|
179
|
+
TranslatorAgent,
|
|
180
|
+
ValidatorAgent,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
# Initialize agents with a default model
|
|
184
|
+
summarizer = SummarizerAgent(default_model="gpt-4o-mini")
|
|
185
|
+
translator = TranslatorAgent(default_model="gpt-4o-mini")
|
|
186
|
+
validator = ValidatorAgent(default_model="gpt-4o-mini")
|
|
187
|
+
|
|
188
|
+
# Generate a summary
|
|
189
|
+
summary = summarizer.run_sync("Long-form content to condense...")
|
|
190
|
+
print(summary.text)
|
|
191
|
+
|
|
192
|
+
# Translate text
|
|
193
|
+
translation = translator.run_sync("Bonjour", target_language="English")
|
|
194
|
+
print(translation)
|
|
195
|
+
|
|
196
|
+
# Validate against guardrails
|
|
197
|
+
validation = validator.run_sync(
|
|
198
|
+
"Share meeting notes with names removed",
|
|
199
|
+
agent_output=summary.text
|
|
200
|
+
)
|
|
201
|
+
print(validation.is_safe)
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Important**: These text helpers ship with default prompt templates under
|
|
205
|
+
`src/openai_sdk_helpers/prompt`, so you do **not** need to create placeholder
|
|
206
|
+
files when installing from PyPI. Only pass a `prompt_dir` when you have custom
|
|
207
|
+
templates you want to use instead.
|
|
208
|
+
|
|
209
|
+
### Centralized OpenAI configuration
|
|
210
|
+
|
|
211
|
+
`OpenAISettings` provides a centralized way to manage OpenAI SDK configuration
|
|
212
|
+
across your application:
|
|
213
|
+
|
|
214
|
+
```python
|
|
215
|
+
from openai_sdk_helpers import OpenAISettings
|
|
216
|
+
|
|
217
|
+
# Load from environment variables or a local .env file
|
|
218
|
+
settings = OpenAISettings.from_env()
|
|
219
|
+
|
|
220
|
+
# Create an OpenAI client with loaded settings
|
|
221
|
+
client = settings.create_client()
|
|
222
|
+
|
|
223
|
+
# Reuse the default model across agents
|
|
224
|
+
from openai_sdk_helpers.agent.search.vector import VectorSearch
|
|
225
|
+
|
|
226
|
+
vector_search = VectorSearch(
|
|
227
|
+
prompt_dir=prompts,
|
|
228
|
+
default_model=settings.default_model or "gpt-4o-mini"
|
|
229
|
+
)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
**Supported Environment Variables:**
|
|
233
|
+
- `OPENAI_API_KEY` (required) - Your OpenAI API key
|
|
234
|
+
- `OPENAI_ORG_ID` - Organization identifier
|
|
235
|
+
- `OPENAI_PROJECT_ID` - Project identifier for billing
|
|
236
|
+
- `OPENAI_BASE_URL` - Custom base URL for self-hosted deployments
|
|
237
|
+
- `OPENAI_MODEL` - Default model name
|
|
238
|
+
- `OPENAI_TIMEOUT` - Request timeout in seconds
|
|
239
|
+
- `OPENAI_MAX_RETRIES` - Maximum retry attempts
|
|
240
|
+
|
|
241
|
+
Pass uncommon OpenAI client keyword arguments (such as `default_headers`,
|
|
242
|
+
`http_client`, or custom `base_url` proxies) through `extra_client_kwargs`
|
|
243
|
+
when instantiating `OpenAISettings`.
|
|
244
|
+
|
|
245
|
+
### Direct Response Control (Response Module)
|
|
246
|
+
|
|
247
|
+
For more fine-grained control over API interactions, use the `response` module built on the standard `openai` SDK. This gives you direct access to message history, tool handlers, and custom response parsing:
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
from openai_sdk_helpers.response import BaseResponse
|
|
251
|
+
from openai_sdk_helpers import OpenAISettings
|
|
252
|
+
|
|
253
|
+
# Configure OpenAI settings
|
|
254
|
+
settings = OpenAISettings.from_env()
|
|
255
|
+
|
|
256
|
+
# Create a response handler with custom instructions
|
|
257
|
+
response = BaseResponse(
|
|
258
|
+
instructions="You are a helpful code review assistant.",
|
|
259
|
+
tools=None, # Or provide custom tool definitions
|
|
260
|
+
output_structure=None, # Or a Pydantic model for structured output
|
|
261
|
+
tool_handlers={}, # Map tool names to handler functions
|
|
262
|
+
openai_settings=settings
|
|
263
|
+
)
|
|
264
|
+
|
|
265
|
+
# Execute and get a response
|
|
266
|
+
result = response.run_sync("Review this Python code for best practices...")
|
|
267
|
+
print(result)
|
|
268
|
+
|
|
269
|
+
# Clean up
|
|
270
|
+
response.close()
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
**Key Differences:**
|
|
274
|
+
- **Agent Module**: Higher-level abstraction with built-in streaming, automatic tool handling, and agent-specific workflows
|
|
275
|
+
- **Response Module**: Lower-level control with manual message management, custom tool handlers, and direct API access
|
|
276
|
+
|
|
277
|
+
## Advanced Usage
|
|
278
|
+
|
|
279
|
+
### Custom Prompt Templates
|
|
280
|
+
|
|
281
|
+
Create custom Jinja2 templates for specialized agent behaviors:
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
from pathlib import Path
|
|
285
|
+
from openai_sdk_helpers.agent import SummarizerAgent
|
|
286
|
+
|
|
287
|
+
# Use custom prompt templates
|
|
288
|
+
custom_prompts = Path("./my_prompts")
|
|
289
|
+
summarizer = SummarizerAgent(
|
|
290
|
+
prompt_dir=custom_prompts,
|
|
291
|
+
default_model="gpt-4o"
|
|
292
|
+
)
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Asynchronous Execution
|
|
296
|
+
|
|
297
|
+
All agents support both synchronous and asynchronous execution:
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
import asyncio
|
|
301
|
+
from openai_sdk_helpers.agent import SummarizerAgent
|
|
302
|
+
|
|
303
|
+
async def main():
|
|
304
|
+
summarizer = SummarizerAgent(default_model="gpt-4o-mini")
|
|
305
|
+
|
|
306
|
+
# Run asynchronously
|
|
307
|
+
result = await summarizer.run_agent(
|
|
308
|
+
text="Long document to summarize...",
|
|
309
|
+
metadata={"source": "example.pdf"}
|
|
310
|
+
)
|
|
311
|
+
print(result.text)
|
|
312
|
+
|
|
313
|
+
asyncio.run(main())
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### Vector Storage Integration
|
|
317
|
+
|
|
318
|
+
Integrate with OpenAI vector stores for document search:
|
|
319
|
+
|
|
320
|
+
```python
|
|
321
|
+
from openai_sdk_helpers.vector_storage import VectorStorage
|
|
322
|
+
from openai_sdk_helpers.agent.search.vector import VectorSearch
|
|
323
|
+
|
|
324
|
+
# Create or connect to a vector store
|
|
325
|
+
storage = VectorStorage(store_name="my_documents")
|
|
326
|
+
|
|
327
|
+
# Use it with vector search
|
|
328
|
+
vector_search = VectorSearch(
|
|
329
|
+
default_model="gpt-4o-mini",
|
|
330
|
+
vector_storage=storage
|
|
331
|
+
)
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
## Development
|
|
335
|
+
|
|
336
|
+
The repository follows standard Python development practices with comprehensive
|
|
337
|
+
quality checks.
|
|
338
|
+
|
|
339
|
+
### Setting Up Your Development Environment
|
|
340
|
+
|
|
341
|
+
```bash
|
|
342
|
+
# Clone and install with dev dependencies
|
|
343
|
+
git clone https://github.com/fatmambot33/openai-sdk-helpers.git
|
|
344
|
+
cd openai-sdk-helpers
|
|
345
|
+
pip install -e .[dev]
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Running Quality Checks
|
|
349
|
+
|
|
350
|
+
Before opening a pull request, ensure all quality checks pass locally:
|
|
351
|
+
|
|
352
|
+
```bash
|
|
353
|
+
# Style and docstring checks
|
|
354
|
+
pydocstyle src
|
|
355
|
+
|
|
356
|
+
# Code formatting check
|
|
357
|
+
black --check .
|
|
358
|
+
|
|
359
|
+
# Apply formatting (if needed)
|
|
360
|
+
black .
|
|
361
|
+
|
|
362
|
+
# Static type checking
|
|
363
|
+
pyright src
|
|
364
|
+
|
|
365
|
+
# Unit tests with coverage (minimum 70% required)
|
|
366
|
+
pytest -q --cov=src --cov-report=term-missing --cov-fail-under=70
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
All checks must pass for changes to be merged.
|
|
370
|
+
|
|
371
|
+
## Project Structure
|
|
372
|
+
|
|
373
|
+
```
|
|
374
|
+
src/openai_sdk_helpers/
|
|
375
|
+
├── agent/ # Agent factories, orchestration, and search workflows
|
|
376
|
+
│ ├── base.py # Base agent class with sync/async execution
|
|
377
|
+
│ ├── summarizer.py # Text summarization agent
|
|
378
|
+
│ ├── translator.py # Translation agent
|
|
379
|
+
│ ├── validation.py # Input/output validation agent
|
|
380
|
+
│ ├── vector_search.py # Multi-agent vector search workflow
|
|
381
|
+
│ └── coordinator_agent.py # Coordinated multi-step workflows
|
|
382
|
+
├── prompt/ # Jinja2 template rendering utilities
|
|
383
|
+
├── response/ # Response parsing and transformation helpers
|
|
384
|
+
├── structure/ # Pydantic-based typed data structures
|
|
385
|
+
│ ├── base.py # Base structure with schema generation
|
|
386
|
+
│ ├── plan/ # Task and plan structures
|
|
387
|
+
│ ├── summary.py # Summary output structures
|
|
388
|
+
│ └── validation.py # Validation result structures
|
|
389
|
+
├── vector_storage/ # Vector store abstraction layer
|
|
390
|
+
├── config.py # OpenAI settings and configuration
|
|
391
|
+
└── utils/ # JSON serialization, logging, and helpers
|
|
392
|
+
|
|
393
|
+
tests/ # Comprehensive unit test suite
|
|
394
|
+
```
|
|
395
|
+
|
|
396
|
+
## Key Modules
|
|
397
|
+
|
|
398
|
+
The package is organized around cohesive, reusable building blocks:
|
|
399
|
+
|
|
400
|
+
### Agent Modules (Built on `openai-agents` SDK)
|
|
401
|
+
|
|
402
|
+
These modules use the `openai-agents` SDK for high-level agent workflows with automatic streaming, tool handling, and conversation management.
|
|
403
|
+
|
|
404
|
+
- **`openai_sdk_helpers.agent.base.AgentBase`**
|
|
405
|
+
Base class for all agents with synchronous and asynchronous execution support.
|
|
406
|
+
Handles prompt rendering, model configuration, and tool integration.
|
|
407
|
+
|
|
408
|
+
- **`openai_sdk_helpers.agent.search.vector.VectorSearch`**
|
|
409
|
+
Complete vector search workflow that coordinates planning, searching, and
|
|
410
|
+
reporting. Bundles `VectorSearchPlanner`, `VectorSearchTool`, and
|
|
411
|
+
`VectorSearchWriter` into a single entry point.
|
|
412
|
+
|
|
413
|
+
- **`openai_sdk_helpers.agent.coordinator_agent.ProjectManager`**
|
|
414
|
+
Orchestrates multi-step workflows with prompt creation, plan building, task
|
|
415
|
+
execution, and summarization. Persists intermediate artifacts to disk.
|
|
416
|
+
|
|
417
|
+
- **`openai_sdk_helpers.agent.summarizer.SummarizerAgent`**
|
|
418
|
+
Generates concise summaries from provided text using structured output.
|
|
419
|
+
|
|
420
|
+
- **`openai_sdk_helpers.agent.translator.TranslatorAgent`**
|
|
421
|
+
Translates text into target languages with optional context.
|
|
422
|
+
|
|
423
|
+
- **`openai_sdk_helpers.agent.validation.ValidatorAgent`**
|
|
424
|
+
Validates user inputs and agent outputs against safety guardrails.
|
|
425
|
+
|
|
426
|
+
### Response Module (Built on `openai` SDK)
|
|
427
|
+
|
|
428
|
+
These modules use the standard `openai` SDK for direct API interactions with fine-grained control over request/response cycles.
|
|
429
|
+
|
|
430
|
+
- **`openai_sdk_helpers.response.base.BaseResponse`**
|
|
431
|
+
Manages complete OpenAI API interaction lifecycle including input construction,
|
|
432
|
+
tool execution, message history, and structured output parsing. Uses the
|
|
433
|
+
`client.responses.create()` API (from the OpenAI Responses API, distinct from
|
|
434
|
+
the Chat Completions API) for direct control over conversation flow.
|
|
435
|
+
|
|
436
|
+
- **`openai_sdk_helpers.response.runner`**
|
|
437
|
+
Convenience functions for executing response workflows with automatic cleanup
|
|
438
|
+
in both synchronous and asynchronous contexts.
|
|
439
|
+
|
|
440
|
+
### Configuration and Data Structures (Shared)
|
|
441
|
+
|
|
442
|
+
- **`openai_sdk_helpers.config.OpenAISettings`**
|
|
443
|
+
Centralizes OpenAI API configuration with environment variable support.
|
|
444
|
+
Creates configured OpenAI clients with consistent settings.
|
|
445
|
+
|
|
446
|
+
- **`openai_sdk_helpers.structure.BaseStructure`**
|
|
447
|
+
Pydantic-based foundation for all structured outputs. Provides JSON schema
|
|
448
|
+
generation, validation, and serialization helpers.
|
|
449
|
+
|
|
450
|
+
- **`openai_sdk_helpers.structure.plan`**
|
|
451
|
+
Task and plan structures for multi-step workflows with status tracking.
|
|
452
|
+
|
|
453
|
+
### Utilities (Shared)
|
|
454
|
+
|
|
455
|
+
- **`openai_sdk_helpers.prompt.PromptRenderer`**
|
|
456
|
+
Jinja2-based template rendering for dynamic prompt generation.
|
|
457
|
+
|
|
458
|
+
- **`openai_sdk_helpers.vector_storage.VectorStorage`**
|
|
459
|
+
Minimal abstraction over OpenAI vector stores with search and file management.
|
|
460
|
+
|
|
461
|
+
- **`openai_sdk_helpers.utils`**
|
|
462
|
+
JSON serialization helpers, logging utilities, and common validation functions.
|
|
463
|
+
|
|
464
|
+
## Contributing
|
|
465
|
+
|
|
466
|
+
Contributions are welcome! We appreciate functional changes accompanied by
|
|
467
|
+
relevant tests and documentation.
|
|
468
|
+
|
|
469
|
+
### Guidelines
|
|
470
|
+
|
|
471
|
+
1. **Fork and clone** the repository
|
|
472
|
+
2. **Create a feature branch** from `main`
|
|
473
|
+
3. **Make your changes** following the project conventions
|
|
474
|
+
4. **Add or update tests** to cover your changes
|
|
475
|
+
5. **Run all quality checks** (see [Development](#development))
|
|
476
|
+
6. **Submit a pull request** with a clear description
|
|
477
|
+
|
|
478
|
+
### Code Style
|
|
479
|
+
|
|
480
|
+
- Follow **PEP 8** for Python code formatting
|
|
481
|
+
- Use **NumPy-style docstrings** as outlined in `AGENTS.md`
|
|
482
|
+
- Write clear, descriptive commit messages in the imperative mood
|
|
483
|
+
- Keep implementations Pythonic and maintainable
|
|
484
|
+
|
|
485
|
+
### Documentation
|
|
486
|
+
|
|
487
|
+
- Document all public classes, methods, and functions
|
|
488
|
+
- Include a `Methods` section in class docstrings listing public methods
|
|
489
|
+
- Add type hints to all function signatures
|
|
490
|
+
- Provide examples in docstrings where helpful
|
|
491
|
+
|
|
492
|
+
### Testing
|
|
493
|
+
|
|
494
|
+
- Write unit tests for new functionality
|
|
495
|
+
- Maintain minimum 70% code coverage
|
|
496
|
+
- Ensure all tests pass before submitting
|
|
497
|
+
|
|
498
|
+
See `AGENTS.md` for detailed contributing guidelines and conventions.
|
|
499
|
+
|
|
500
|
+
## License
|
|
501
|
+
|
|
502
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
|
|
503
|
+
for details.
|
|
504
|
+
|
|
505
|
+
## Troubleshooting
|
|
506
|
+
|
|
507
|
+
### Common Issues
|
|
508
|
+
|
|
509
|
+
**"OPENAI_API_KEY is required" error**
|
|
510
|
+
|
|
511
|
+
Ensure your OpenAI API key is set in the environment:
|
|
512
|
+
```bash
|
|
513
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
Or create a `.env` file in your project root:
|
|
517
|
+
```
|
|
518
|
+
OPENAI_API_KEY=your-api-key-here
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
**"Prompt template not found" error**
|
|
522
|
+
|
|
523
|
+
Vector search workflows require custom prompt templates. Either:
|
|
524
|
+
1. Create the required `.jinja` files in your `prompt_dir`
|
|
525
|
+
2. Omit the `prompt_dir` parameter to use built-in defaults (for text agents only)
|
|
526
|
+
|
|
527
|
+
**Import errors after installation**
|
|
528
|
+
|
|
529
|
+
Ensure you're using Python 3.10 or higher:
|
|
530
|
+
```bash
|
|
531
|
+
python --version
|
|
532
|
+
```
|
|
533
|
+
|
|
534
|
+
If using an older version, upgrade Python or create a virtual environment with
|
|
535
|
+
Python 3.10+.
|
|
536
|
+
|
|
537
|
+
**Type checking issues in your IDE**
|
|
538
|
+
|
|
539
|
+
The package ships with `py.typed` for full type support. If your IDE isn't
|
|
540
|
+
recognizing types:
|
|
541
|
+
1. Ensure your IDE's Python plugin is up to date
|
|
542
|
+
2. Restart your IDE after installing the package
|
|
543
|
+
3. Check that your IDE is using the correct Python interpreter
|
|
544
|
+
|
|
545
|
+
### Getting Help
|
|
546
|
+
|
|
547
|
+
- Check the [Key Modules](#key-modules) section for API documentation
|
|
548
|
+
- Review examples in the [Quickstart](#quickstart) and [Advanced Usage](#advanced-usage) sections
|
|
549
|
+
- Open an issue on GitHub for bugs or feature requests
|
|
550
|
+
|