agento11y-openai 0.10.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.
- agento11y_openai-0.10.0/LICENSE +3 -0
- agento11y_openai-0.10.0/PKG-INFO +158 -0
- agento11y_openai-0.10.0/README.md +141 -0
- agento11y_openai-0.10.0/agento11y_openai/__init__.py +19 -0
- agento11y_openai-0.10.0/agento11y_openai/provider.py +1347 -0
- agento11y_openai-0.10.0/agento11y_openai/py.typed +0 -0
- agento11y_openai-0.10.0/agento11y_openai.egg-info/PKG-INFO +158 -0
- agento11y_openai-0.10.0/agento11y_openai.egg-info/SOURCES.txt +12 -0
- agento11y_openai-0.10.0/agento11y_openai.egg-info/dependency_links.txt +1 -0
- agento11y_openai-0.10.0/agento11y_openai.egg-info/requires.txt +5 -0
- agento11y_openai-0.10.0/agento11y_openai.egg-info/top_level.txt +1 -0
- agento11y_openai-0.10.0/pyproject.toml +30 -0
- agento11y_openai-0.10.0/setup.cfg +4 -0
- agento11y_openai-0.10.0/tests/test_openai_provider.py +698 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agento11y-openai
|
|
3
|
+
Version: 0.10.0
|
|
4
|
+
Summary: OpenAI helper wrappers for the Grafana Agent Observability Python SDK
|
|
5
|
+
License: SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
|
|
7
|
+
See /LICENSE at repository root for full license text.
|
|
8
|
+
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: agento11y>=0.10.0
|
|
13
|
+
Requires-Dist: openai<3,>=1.66.0
|
|
14
|
+
Provides-Extra: dev
|
|
15
|
+
Requires-Dist: pytest>=9.0.3; extra == "dev"
|
|
16
|
+
Dynamic: license-file
|
|
17
|
+
|
|
18
|
+
# Sigil Python Provider Helper: OpenAI
|
|
19
|
+
|
|
20
|
+
`agento11y-openai` exposes strict OpenAI-shaped wrappers and mappers for both Chat Completions and Responses.
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
pip install agento11y agento11y-openai
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Public API
|
|
29
|
+
|
|
30
|
+
- Chat Completions namespace:
|
|
31
|
+
- `chat.completions.create(...)`
|
|
32
|
+
- `chat.completions.create_async(...)`
|
|
33
|
+
- `chat.completions.stream(...)`
|
|
34
|
+
- `chat.completions.stream_async(...)`
|
|
35
|
+
- `chat.completions.from_request_response(...)`
|
|
36
|
+
- `chat.completions.from_stream(...)`
|
|
37
|
+
|
|
38
|
+
- Responses namespace:
|
|
39
|
+
- `responses.create(...)`
|
|
40
|
+
- `responses.create_async(...)`
|
|
41
|
+
- `responses.stream(...)`
|
|
42
|
+
- `responses.stream_async(...)`
|
|
43
|
+
- `responses.from_request_response(...)`
|
|
44
|
+
- `responses.from_stream(...)`
|
|
45
|
+
|
|
46
|
+
- Embeddings namespace:
|
|
47
|
+
- `embeddings.create(...)`
|
|
48
|
+
- `embeddings.create_async(...)`
|
|
49
|
+
- `embeddings.from_request_response(...)`
|
|
50
|
+
|
|
51
|
+
## Integration styles
|
|
52
|
+
|
|
53
|
+
- Strict wrappers: call OpenAI and record in one step.
|
|
54
|
+
- Manual instrumentation: call OpenAI directly, then map strict OpenAI request/response payloads with `from_request_response` or `from_stream`.
|
|
55
|
+
|
|
56
|
+
## Responses-first wrapper example
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
from openai import OpenAI
|
|
60
|
+
from agento11y import Client, ClientConfig
|
|
61
|
+
from agento11y_openai import OpenAIOptions, responses
|
|
62
|
+
|
|
63
|
+
agento11y = Client(ClientConfig())
|
|
64
|
+
provider = OpenAI()
|
|
65
|
+
|
|
66
|
+
response = responses.create(
|
|
67
|
+
agento11y,
|
|
68
|
+
{
|
|
69
|
+
"model": "gpt-5",
|
|
70
|
+
"instructions": "Be concise",
|
|
71
|
+
"input": "Summarize rollout status in 3 bullets",
|
|
72
|
+
"max_output_tokens": 300,
|
|
73
|
+
},
|
|
74
|
+
lambda request: provider.responses.create(**request),
|
|
75
|
+
OpenAIOptions(conversation_id="conv-1", agent_name="assistant", agent_version="1.0.0"),
|
|
76
|
+
)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Chat Completions stream example
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from agento11y_openai import ChatCompletionsStreamSummary, chat
|
|
83
|
+
|
|
84
|
+
summary = chat.completions.stream(
|
|
85
|
+
agento11y,
|
|
86
|
+
{
|
|
87
|
+
"model": "gpt-5",
|
|
88
|
+
"stream": True,
|
|
89
|
+
"messages": [{"role": "user", "content": "Stream a short status update"}],
|
|
90
|
+
},
|
|
91
|
+
lambda request: ChatCompletionsStreamSummary(events=[]),
|
|
92
|
+
)
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Embeddings example
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from agento11y_openai import embeddings
|
|
99
|
+
|
|
100
|
+
embedding_response = embeddings.create(
|
|
101
|
+
agento11y,
|
|
102
|
+
{
|
|
103
|
+
"model": "text-embedding-3-small",
|
|
104
|
+
"input": ["hello", "world"],
|
|
105
|
+
},
|
|
106
|
+
lambda request: provider.embeddings.create(**request),
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Manual instrumentation example (strict mapper)
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
from agento11y import GenerationStart, ModelRef
|
|
114
|
+
from agento11y_openai import OpenAIOptions, responses
|
|
115
|
+
|
|
116
|
+
request = {
|
|
117
|
+
"model": "gpt-5",
|
|
118
|
+
"instructions": "Be concise",
|
|
119
|
+
"input": "Summarize rollout status in 3 bullets",
|
|
120
|
+
}
|
|
121
|
+
opts = OpenAIOptions(
|
|
122
|
+
conversation_id="conv-1",
|
|
123
|
+
agent_name="assistant",
|
|
124
|
+
agent_version="1.0.0",
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
with agento11y.start_generation(
|
|
128
|
+
GenerationStart(
|
|
129
|
+
conversation_id=opts.conversation_id,
|
|
130
|
+
agent_name=opts.agent_name,
|
|
131
|
+
agent_version=opts.agent_version,
|
|
132
|
+
model=ModelRef(provider=opts.provider_name, name=request["model"]),
|
|
133
|
+
)
|
|
134
|
+
) as rec:
|
|
135
|
+
try:
|
|
136
|
+
response = provider.responses.create(**request)
|
|
137
|
+
rec.set_result(responses.from_request_response(request, response, opts))
|
|
138
|
+
except Exception as exc:
|
|
139
|
+
rec.set_call_error(exc)
|
|
140
|
+
raise
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Raw artifacts (debug opt-in)
|
|
144
|
+
|
|
145
|
+
Raw artifacts are off by default.
|
|
146
|
+
|
|
147
|
+
Enable with:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
OpenAIOptions(raw_artifacts=True)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
Artifact names:
|
|
154
|
+
|
|
155
|
+
- Chat: `openai.chat.request`, `openai.chat.response`, `openai.chat.tools`, `openai.chat.stream_events`
|
|
156
|
+
- Responses: `openai.responses.request`, `openai.responses.response`, `openai.responses.tools`, `openai.responses.stream_events`
|
|
157
|
+
|
|
158
|
+
Call `client.shutdown()` during teardown to flush buffered telemetry.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# Sigil Python Provider Helper: OpenAI
|
|
2
|
+
|
|
3
|
+
`agento11y-openai` exposes strict OpenAI-shaped wrappers and mappers for both Chat Completions and Responses.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install agento11y agento11y-openai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Public API
|
|
12
|
+
|
|
13
|
+
- Chat Completions namespace:
|
|
14
|
+
- `chat.completions.create(...)`
|
|
15
|
+
- `chat.completions.create_async(...)`
|
|
16
|
+
- `chat.completions.stream(...)`
|
|
17
|
+
- `chat.completions.stream_async(...)`
|
|
18
|
+
- `chat.completions.from_request_response(...)`
|
|
19
|
+
- `chat.completions.from_stream(...)`
|
|
20
|
+
|
|
21
|
+
- Responses namespace:
|
|
22
|
+
- `responses.create(...)`
|
|
23
|
+
- `responses.create_async(...)`
|
|
24
|
+
- `responses.stream(...)`
|
|
25
|
+
- `responses.stream_async(...)`
|
|
26
|
+
- `responses.from_request_response(...)`
|
|
27
|
+
- `responses.from_stream(...)`
|
|
28
|
+
|
|
29
|
+
- Embeddings namespace:
|
|
30
|
+
- `embeddings.create(...)`
|
|
31
|
+
- `embeddings.create_async(...)`
|
|
32
|
+
- `embeddings.from_request_response(...)`
|
|
33
|
+
|
|
34
|
+
## Integration styles
|
|
35
|
+
|
|
36
|
+
- Strict wrappers: call OpenAI and record in one step.
|
|
37
|
+
- Manual instrumentation: call OpenAI directly, then map strict OpenAI request/response payloads with `from_request_response` or `from_stream`.
|
|
38
|
+
|
|
39
|
+
## Responses-first wrapper example
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from openai import OpenAI
|
|
43
|
+
from agento11y import Client, ClientConfig
|
|
44
|
+
from agento11y_openai import OpenAIOptions, responses
|
|
45
|
+
|
|
46
|
+
agento11y = Client(ClientConfig())
|
|
47
|
+
provider = OpenAI()
|
|
48
|
+
|
|
49
|
+
response = responses.create(
|
|
50
|
+
agento11y,
|
|
51
|
+
{
|
|
52
|
+
"model": "gpt-5",
|
|
53
|
+
"instructions": "Be concise",
|
|
54
|
+
"input": "Summarize rollout status in 3 bullets",
|
|
55
|
+
"max_output_tokens": 300,
|
|
56
|
+
},
|
|
57
|
+
lambda request: provider.responses.create(**request),
|
|
58
|
+
OpenAIOptions(conversation_id="conv-1", agent_name="assistant", agent_version="1.0.0"),
|
|
59
|
+
)
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Chat Completions stream example
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from agento11y_openai import ChatCompletionsStreamSummary, chat
|
|
66
|
+
|
|
67
|
+
summary = chat.completions.stream(
|
|
68
|
+
agento11y,
|
|
69
|
+
{
|
|
70
|
+
"model": "gpt-5",
|
|
71
|
+
"stream": True,
|
|
72
|
+
"messages": [{"role": "user", "content": "Stream a short status update"}],
|
|
73
|
+
},
|
|
74
|
+
lambda request: ChatCompletionsStreamSummary(events=[]),
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Embeddings example
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
from agento11y_openai import embeddings
|
|
82
|
+
|
|
83
|
+
embedding_response = embeddings.create(
|
|
84
|
+
agento11y,
|
|
85
|
+
{
|
|
86
|
+
"model": "text-embedding-3-small",
|
|
87
|
+
"input": ["hello", "world"],
|
|
88
|
+
},
|
|
89
|
+
lambda request: provider.embeddings.create(**request),
|
|
90
|
+
)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Manual instrumentation example (strict mapper)
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from agento11y import GenerationStart, ModelRef
|
|
97
|
+
from agento11y_openai import OpenAIOptions, responses
|
|
98
|
+
|
|
99
|
+
request = {
|
|
100
|
+
"model": "gpt-5",
|
|
101
|
+
"instructions": "Be concise",
|
|
102
|
+
"input": "Summarize rollout status in 3 bullets",
|
|
103
|
+
}
|
|
104
|
+
opts = OpenAIOptions(
|
|
105
|
+
conversation_id="conv-1",
|
|
106
|
+
agent_name="assistant",
|
|
107
|
+
agent_version="1.0.0",
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
with agento11y.start_generation(
|
|
111
|
+
GenerationStart(
|
|
112
|
+
conversation_id=opts.conversation_id,
|
|
113
|
+
agent_name=opts.agent_name,
|
|
114
|
+
agent_version=opts.agent_version,
|
|
115
|
+
model=ModelRef(provider=opts.provider_name, name=request["model"]),
|
|
116
|
+
)
|
|
117
|
+
) as rec:
|
|
118
|
+
try:
|
|
119
|
+
response = provider.responses.create(**request)
|
|
120
|
+
rec.set_result(responses.from_request_response(request, response, opts))
|
|
121
|
+
except Exception as exc:
|
|
122
|
+
rec.set_call_error(exc)
|
|
123
|
+
raise
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Raw artifacts (debug opt-in)
|
|
127
|
+
|
|
128
|
+
Raw artifacts are off by default.
|
|
129
|
+
|
|
130
|
+
Enable with:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
OpenAIOptions(raw_artifacts=True)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Artifact names:
|
|
137
|
+
|
|
138
|
+
- Chat: `openai.chat.request`, `openai.chat.response`, `openai.chat.tools`, `openai.chat.stream_events`
|
|
139
|
+
- Responses: `openai.responses.request`, `openai.responses.response`, `openai.responses.tools`, `openai.responses.stream_events`
|
|
140
|
+
|
|
141
|
+
Call `client.shutdown()` during teardown to flush buffered telemetry.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""OpenAI strict wrapper namespaces for Sigil Python SDK."""
|
|
2
|
+
|
|
3
|
+
from .provider import (
|
|
4
|
+
ChatCompletionsStreamSummary,
|
|
5
|
+
OpenAIOptions,
|
|
6
|
+
ResponsesStreamSummary,
|
|
7
|
+
chat,
|
|
8
|
+
embeddings,
|
|
9
|
+
responses,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
__all__ = [
|
|
13
|
+
"ChatCompletionsStreamSummary",
|
|
14
|
+
"OpenAIOptions",
|
|
15
|
+
"ResponsesStreamSummary",
|
|
16
|
+
"chat",
|
|
17
|
+
"embeddings",
|
|
18
|
+
"responses",
|
|
19
|
+
]
|