agent-framework-openai 1.0.0rc6__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.
- agent_framework_openai-1.0.0rc6/LICENSE +21 -0
- agent_framework_openai-1.0.0rc6/PKG-INFO +133 -0
- agent_framework_openai-1.0.0rc6/README.md +106 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/__init__.py +87 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_assistant_provider.py +564 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_assistants_client.py +968 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_chat_client.py +2729 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_chat_completion_client.py +1326 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_embedding_client.py +509 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_exceptions.py +90 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/_shared.py +629 -0
- agent_framework_openai-1.0.0rc6/agent_framework_openai/py.typed +0 -0
- agent_framework_openai-1.0.0rc6/pyproject.toml +98 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-framework-openai
|
|
3
|
+
Version: 1.0.0rc6
|
|
4
|
+
Summary: OpenAI integration for Microsoft Agent Framework.
|
|
5
|
+
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: agent-framework-core>=1.0.0rc6
|
|
20
|
+
Requires-Dist: openai>=1.99.0,<3
|
|
21
|
+
Requires-Dist: packaging>=24.1,<25
|
|
22
|
+
Project-URL: homepage, https://aka.ms/agent-framework
|
|
23
|
+
Project-URL: issues, https://github.com/microsoft/agent-framework/issues
|
|
24
|
+
Project-URL: release_notes, https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true
|
|
25
|
+
Project-URL: source, https://github.com/microsoft/agent-framework/tree/main/python
|
|
26
|
+
|
|
27
|
+
# agent-framework-openai
|
|
28
|
+
|
|
29
|
+
OpenAI integration for Microsoft Agent Framework.
|
|
30
|
+
|
|
31
|
+
This package provides:
|
|
32
|
+
|
|
33
|
+
- `OpenAIChatClient` for the OpenAI Responses API
|
|
34
|
+
- `OpenAIChatCompletionClient` for the Chat Completions API
|
|
35
|
+
- `OpenAIEmbeddingClient` for embeddings
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
pip install agent-framework-openai --pre
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Which chat client should I use?
|
|
44
|
+
|
|
45
|
+
Use `OpenAIChatClient` for new work unless you specifically need the Chat Completions API.
|
|
46
|
+
|
|
47
|
+
- `OpenAIChatClient` uses the Responses API and is the preferred general-purpose chat client.
|
|
48
|
+
- `OpenAIChatCompletionClient` uses the Chat Completions API and is mainly for compatibility with
|
|
49
|
+
existing Chat Completions-based integrations.
|
|
50
|
+
|
|
51
|
+
The deprecated `OpenAIResponsesClient` alias points to `OpenAIChatClient`.
|
|
52
|
+
|
|
53
|
+
## Environment variables
|
|
54
|
+
|
|
55
|
+
### OpenAI
|
|
56
|
+
|
|
57
|
+
These variables are used when the client is configured for OpenAI:
|
|
58
|
+
|
|
59
|
+
| Variable | Purpose |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `OPENAI_API_KEY` | OpenAI API key |
|
|
62
|
+
| `OPENAI_ORG_ID` | OpenAI organization ID |
|
|
63
|
+
| `OPENAI_BASE_URL` | Custom OpenAI-compatible base URL |
|
|
64
|
+
| `OPENAI_MODEL` | Generic fallback model |
|
|
65
|
+
| `OPENAI_RESPONSES_MODEL` | Preferred model for `OpenAIChatClient` |
|
|
66
|
+
| `OPENAI_CHAT_MODEL` | Preferred model for `OpenAIChatCompletionClient` |
|
|
67
|
+
| `OPENAI_EMBEDDING_MODEL` | Preferred model for `OpenAIEmbeddingClient` |
|
|
68
|
+
|
|
69
|
+
Model lookup order:
|
|
70
|
+
|
|
71
|
+
- `OpenAIChatClient`: `OPENAI_RESPONSES_MODEL` -> `OPENAI_MODEL`
|
|
72
|
+
- `OpenAIChatCompletionClient`: `OPENAI_CHAT_MODEL` -> `OPENAI_MODEL`
|
|
73
|
+
- `OpenAIEmbeddingClient`: `OPENAI_EMBEDDING_MODEL` -> `OPENAI_MODEL`
|
|
74
|
+
|
|
75
|
+
### Azure OpenAI
|
|
76
|
+
|
|
77
|
+
These variables are used when the client is configured for Azure OpenAI:
|
|
78
|
+
|
|
79
|
+
| Variable | Purpose |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `AZURE_OPENAI_ENDPOINT` | Azure OpenAI resource endpoint |
|
|
82
|
+
| `AZURE_OPENAI_BASE_URL` | Full Azure OpenAI base URL (`.../openai/v1`) |
|
|
83
|
+
| `AZURE_OPENAI_API_KEY` | Azure OpenAI API key |
|
|
84
|
+
| `AZURE_OPENAI_API_VERSION` | Azure OpenAI API version |
|
|
85
|
+
| `AZURE_OPENAI_DEPLOYMENT_NAME` | Generic fallback deployment |
|
|
86
|
+
| `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIChatClient` |
|
|
87
|
+
| `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIChatCompletionClient` |
|
|
88
|
+
| `AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIEmbeddingClient` |
|
|
89
|
+
|
|
90
|
+
Deployment lookup order:
|
|
91
|
+
|
|
92
|
+
- `OpenAIChatClient`: `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
93
|
+
- `OpenAIChatCompletionClient`: `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
94
|
+
- `OpenAIEmbeddingClient`: `AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
95
|
+
|
|
96
|
+
When both OpenAI and Azure environment variables are present, the generic clients prefer OpenAI
|
|
97
|
+
when `OPENAI_API_KEY` is configured. To use Azure explicitly, pass `azure_endpoint` or
|
|
98
|
+
`credential`.
|
|
99
|
+
|
|
100
|
+
## OpenAI example
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from agent_framework.openai import OpenAIChatClient
|
|
104
|
+
|
|
105
|
+
client = OpenAIChatClient(model="gpt-4.1")
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
## Azure OpenAI example
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
from azure.identity.aio import AzureCliCredential
|
|
112
|
+
|
|
113
|
+
from agent_framework.openai import OpenAIChatClient
|
|
114
|
+
|
|
115
|
+
client = OpenAIChatClient(
|
|
116
|
+
model="my-responses-deployment",
|
|
117
|
+
azure_endpoint="https://my-resource.openai.azure.com",
|
|
118
|
+
credential=AzureCliCredential(),
|
|
119
|
+
)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## ChatClient vs ChatCompletionClient
|
|
123
|
+
|
|
124
|
+
Use `OpenAIChatClient` when you want the Responses API as your default chat surface.
|
|
125
|
+
|
|
126
|
+
Use `OpenAIChatCompletionClient` when you specifically need the Chat Completions API:
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
from agent_framework.openai import OpenAIChatCompletionClient
|
|
130
|
+
|
|
131
|
+
client = OpenAIChatCompletionClient(model="gpt-4o-mini")
|
|
132
|
+
```
|
|
133
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# agent-framework-openai
|
|
2
|
+
|
|
3
|
+
OpenAI integration for Microsoft Agent Framework.
|
|
4
|
+
|
|
5
|
+
This package provides:
|
|
6
|
+
|
|
7
|
+
- `OpenAIChatClient` for the OpenAI Responses API
|
|
8
|
+
- `OpenAIChatCompletionClient` for the Chat Completions API
|
|
9
|
+
- `OpenAIEmbeddingClient` for embeddings
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install agent-framework-openai --pre
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Which chat client should I use?
|
|
18
|
+
|
|
19
|
+
Use `OpenAIChatClient` for new work unless you specifically need the Chat Completions API.
|
|
20
|
+
|
|
21
|
+
- `OpenAIChatClient` uses the Responses API and is the preferred general-purpose chat client.
|
|
22
|
+
- `OpenAIChatCompletionClient` uses the Chat Completions API and is mainly for compatibility with
|
|
23
|
+
existing Chat Completions-based integrations.
|
|
24
|
+
|
|
25
|
+
The deprecated `OpenAIResponsesClient` alias points to `OpenAIChatClient`.
|
|
26
|
+
|
|
27
|
+
## Environment variables
|
|
28
|
+
|
|
29
|
+
### OpenAI
|
|
30
|
+
|
|
31
|
+
These variables are used when the client is configured for OpenAI:
|
|
32
|
+
|
|
33
|
+
| Variable | Purpose |
|
|
34
|
+
| --- | --- |
|
|
35
|
+
| `OPENAI_API_KEY` | OpenAI API key |
|
|
36
|
+
| `OPENAI_ORG_ID` | OpenAI organization ID |
|
|
37
|
+
| `OPENAI_BASE_URL` | Custom OpenAI-compatible base URL |
|
|
38
|
+
| `OPENAI_MODEL` | Generic fallback model |
|
|
39
|
+
| `OPENAI_RESPONSES_MODEL` | Preferred model for `OpenAIChatClient` |
|
|
40
|
+
| `OPENAI_CHAT_MODEL` | Preferred model for `OpenAIChatCompletionClient` |
|
|
41
|
+
| `OPENAI_EMBEDDING_MODEL` | Preferred model for `OpenAIEmbeddingClient` |
|
|
42
|
+
|
|
43
|
+
Model lookup order:
|
|
44
|
+
|
|
45
|
+
- `OpenAIChatClient`: `OPENAI_RESPONSES_MODEL` -> `OPENAI_MODEL`
|
|
46
|
+
- `OpenAIChatCompletionClient`: `OPENAI_CHAT_MODEL` -> `OPENAI_MODEL`
|
|
47
|
+
- `OpenAIEmbeddingClient`: `OPENAI_EMBEDDING_MODEL` -> `OPENAI_MODEL`
|
|
48
|
+
|
|
49
|
+
### Azure OpenAI
|
|
50
|
+
|
|
51
|
+
These variables are used when the client is configured for Azure OpenAI:
|
|
52
|
+
|
|
53
|
+
| Variable | Purpose |
|
|
54
|
+
| --- | --- |
|
|
55
|
+
| `AZURE_OPENAI_ENDPOINT` | Azure OpenAI resource endpoint |
|
|
56
|
+
| `AZURE_OPENAI_BASE_URL` | Full Azure OpenAI base URL (`.../openai/v1`) |
|
|
57
|
+
| `AZURE_OPENAI_API_KEY` | Azure OpenAI API key |
|
|
58
|
+
| `AZURE_OPENAI_API_VERSION` | Azure OpenAI API version |
|
|
59
|
+
| `AZURE_OPENAI_DEPLOYMENT_NAME` | Generic fallback deployment |
|
|
60
|
+
| `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIChatClient` |
|
|
61
|
+
| `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIChatCompletionClient` |
|
|
62
|
+
| `AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME` | Preferred deployment for `OpenAIEmbeddingClient` |
|
|
63
|
+
|
|
64
|
+
Deployment lookup order:
|
|
65
|
+
|
|
66
|
+
- `OpenAIChatClient`: `AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
67
|
+
- `OpenAIChatCompletionClient`: `AZURE_OPENAI_CHAT_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
68
|
+
- `OpenAIEmbeddingClient`: `AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME` -> `AZURE_OPENAI_DEPLOYMENT_NAME`
|
|
69
|
+
|
|
70
|
+
When both OpenAI and Azure environment variables are present, the generic clients prefer OpenAI
|
|
71
|
+
when `OPENAI_API_KEY` is configured. To use Azure explicitly, pass `azure_endpoint` or
|
|
72
|
+
`credential`.
|
|
73
|
+
|
|
74
|
+
## OpenAI example
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from agent_framework.openai import OpenAIChatClient
|
|
78
|
+
|
|
79
|
+
client = OpenAIChatClient(model="gpt-4.1")
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Azure OpenAI example
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
from azure.identity.aio import AzureCliCredential
|
|
86
|
+
|
|
87
|
+
from agent_framework.openai import OpenAIChatClient
|
|
88
|
+
|
|
89
|
+
client = OpenAIChatClient(
|
|
90
|
+
model="my-responses-deployment",
|
|
91
|
+
azure_endpoint="https://my-resource.openai.azure.com",
|
|
92
|
+
credential=AzureCliCredential(),
|
|
93
|
+
)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## ChatClient vs ChatCompletionClient
|
|
97
|
+
|
|
98
|
+
Use `OpenAIChatClient` when you want the Responses API as your default chat surface.
|
|
99
|
+
|
|
100
|
+
Use `OpenAIChatCompletionClient` when you specifically need the Chat Completions API:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from agent_framework.openai import OpenAIChatCompletionClient
|
|
104
|
+
|
|
105
|
+
client = OpenAIChatCompletionClient(model="gpt-4o-mini")
|
|
106
|
+
```
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""OpenAI integration for Microsoft Agent Framework.
|
|
4
|
+
|
|
5
|
+
This package provides OpenAI client implementations for the Agent Framework,
|
|
6
|
+
including clients for the Responses API and Chat Completions API.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import importlib.metadata
|
|
10
|
+
import sys
|
|
11
|
+
|
|
12
|
+
if sys.version_info >= (3, 13):
|
|
13
|
+
from warnings import deprecated # type: ignore # pragma: no cover
|
|
14
|
+
else:
|
|
15
|
+
from typing_extensions import deprecated # type: ignore # pragma: no cover
|
|
16
|
+
|
|
17
|
+
from ._assistant_provider import OpenAIAssistantProvider
|
|
18
|
+
from ._assistants_client import (
|
|
19
|
+
AssistantToolResources,
|
|
20
|
+
OpenAIAssistantsClient, # type: ignore[reportDeprecated]
|
|
21
|
+
OpenAIAssistantsOptions,
|
|
22
|
+
)
|
|
23
|
+
from ._chat_client import (
|
|
24
|
+
OpenAIChatClient,
|
|
25
|
+
OpenAIChatOptions,
|
|
26
|
+
OpenAIContinuationToken,
|
|
27
|
+
RawOpenAIChatClient,
|
|
28
|
+
)
|
|
29
|
+
from ._chat_completion_client import (
|
|
30
|
+
OpenAIChatCompletionClient,
|
|
31
|
+
OpenAIChatCompletionOptions,
|
|
32
|
+
RawOpenAIChatCompletionClient,
|
|
33
|
+
)
|
|
34
|
+
from ._embedding_client import OpenAIEmbeddingClient, OpenAIEmbeddingOptions
|
|
35
|
+
from ._exceptions import ContentFilterResultSeverity, OpenAIContentFilterException
|
|
36
|
+
from ._shared import OpenAISettings
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
__version__ = importlib.metadata.version("agent-framework-openai")
|
|
40
|
+
except importlib.metadata.PackageNotFoundError:
|
|
41
|
+
__version__ = "0.0.0" # Fallback for development mode
|
|
42
|
+
|
|
43
|
+
# Deprecated aliases for old names — use subclasses so the warning only fires for the alias
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
@deprecated(
|
|
47
|
+
"OpenAIResponsesClient is deprecated, use OpenAIChatClient instead.",
|
|
48
|
+
category=DeprecationWarning,
|
|
49
|
+
)
|
|
50
|
+
class OpenAIResponsesClient(OpenAIChatClient): # type: ignore[misc]
|
|
51
|
+
"""Deprecated alias for :class:`OpenAIChatClient`."""
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@deprecated(
|
|
55
|
+
"RawOpenAIResponsesClient is deprecated, use RawOpenAIChatClient instead.",
|
|
56
|
+
category=DeprecationWarning,
|
|
57
|
+
)
|
|
58
|
+
class RawOpenAIResponsesClient(RawOpenAIChatClient): # type: ignore[misc]
|
|
59
|
+
"""Deprecated alias for :class:`RawOpenAIChatClient`."""
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
OpenAIResponsesOptions = OpenAIChatOptions
|
|
63
|
+
"""Deprecated alias for :class:`OpenAIChatOptions`."""
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
__all__ = [
|
|
67
|
+
"AssistantToolResources",
|
|
68
|
+
"ContentFilterResultSeverity",
|
|
69
|
+
"OpenAIAssistantProvider",
|
|
70
|
+
"OpenAIAssistantsClient",
|
|
71
|
+
"OpenAIAssistantsOptions",
|
|
72
|
+
"OpenAIChatClient",
|
|
73
|
+
"OpenAIChatCompletionClient",
|
|
74
|
+
"OpenAIChatCompletionOptions",
|
|
75
|
+
"OpenAIChatOptions",
|
|
76
|
+
"OpenAIContentFilterException",
|
|
77
|
+
"OpenAIContinuationToken",
|
|
78
|
+
"OpenAIEmbeddingClient",
|
|
79
|
+
"OpenAIEmbeddingOptions",
|
|
80
|
+
"OpenAIResponsesClient",
|
|
81
|
+
"OpenAIResponsesOptions",
|
|
82
|
+
"OpenAISettings",
|
|
83
|
+
"RawOpenAIChatClient",
|
|
84
|
+
"RawOpenAIChatCompletionClient",
|
|
85
|
+
"RawOpenAIResponsesClient",
|
|
86
|
+
"__version__",
|
|
87
|
+
]
|