|
| 1 | +""" |
| 2 | +OpenAI Assistant Agent implementation. |
| 3 | +
|
| 4 | +This module is deprecated starting v0.7.0 and will be removed in a future version. |
| 5 | +""" |
| 6 | +# pyright: ignore |
| 7 | +# mypy: ignore-errors |
| 8 | + |
1 | 9 | import asyncio |
2 | 10 | import json |
3 | 11 | import logging |
4 | 12 | import os |
| 13 | +import warnings |
| 14 | +from functools import wraps |
5 | 15 | from typing import ( |
6 | 16 | Any, |
7 | 17 | AsyncGenerator, |
|
57 | 67 | from openai.types.shared_params.function_definition import FunctionDefinition |
58 | 68 | from openai.types.vector_store import VectorStore |
59 | 69 |
|
| 70 | +# Deprecation warning |
| 71 | +warnings.warn( |
| 72 | + "The OpenAIAssistantAgent module is deprecated and will be removed in a future version, use OpenAIAgent instead.", |
| 73 | + DeprecationWarning, |
| 74 | + stacklevel=2, |
| 75 | +) |
| 76 | + |
60 | 77 | event_logger = logging.getLogger(EVENT_LOGGER_NAME) |
61 | 78 |
|
62 | 79 |
|
| 80 | +def deprecated_class(reason: str) -> Callable[[type], type]: |
| 81 | + """Decorator to mark a class as deprecated.""" |
| 82 | + |
| 83 | + def decorator(cls: type) -> type: |
| 84 | + original_init = cls.__init__ |
| 85 | + |
| 86 | + @wraps(original_init) |
| 87 | + def new_init(self, *args, **kwargs) -> None: |
| 88 | + warnings.warn(f"{cls.__name__} is deprecated: {reason}", DeprecationWarning, stacklevel=2) |
| 89 | + original_init(self, *args, **kwargs) |
| 90 | + |
| 91 | + cls.__init__ = new_init |
| 92 | + return cls |
| 93 | + |
| 94 | + return decorator |
| 95 | + |
| 96 | + |
63 | 97 | def _convert_tool_to_function_param(tool: Tool) -> "FunctionToolParam": |
64 | 98 | """Convert an autogen Tool to an OpenAI Assistant function tool parameter.""" |
65 | 99 |
|
@@ -90,14 +124,22 @@ class OpenAIAssistantAgentState(BaseModel): |
90 | 124 | uploaded_file_ids: List[str] = Field(default_factory=list) |
91 | 125 |
|
92 | 126 |
|
| 127 | +@deprecated_class( |
| 128 | + "This class is deprecated starting v0.7.0 and will be removed in a future version. Use OpenAIAgent instead." |
| 129 | +) |
93 | 130 | class OpenAIAssistantAgent(BaseChatAgent): |
94 | 131 | """An agent implementation that uses the Assistant API to generate responses. |
95 | 132 |
|
| 133 | + .. warning:: |
| 134 | +
|
| 135 | + This module is deprecated starting v0.7.0 and will be removed in a future version. |
| 136 | + Please use :class:`~autogen_ext.agents.openai.OpenAIAgent` instead. |
| 137 | +
|
96 | 138 | Installation: |
97 | 139 |
|
98 | 140 | .. code-block:: bash |
99 | 141 |
|
100 | | - pip install "autogen-ext[openai]" |
| 142 | + pip install "autogen-ext[openai]" # For OpenAI Assistant |
101 | 143 | # pip install "autogen-ext[openai,azure]" # For Azure OpenAI Assistant |
102 | 144 |
|
103 | 145 |
|
@@ -146,7 +188,7 @@ async def example(): |
146 | 188 |
|
147 | 189 | # Create an assistant with code interpreter |
148 | 190 | assistant = OpenAIAssistantAgent( |
149 | | - name="Python Helper", |
| 191 | + name="PythonHelper", |
150 | 192 | description="Helps with Python programming", |
151 | 193 | client=client, |
152 | 194 | model="gpt-4", |
@@ -197,7 +239,7 @@ async def example(): |
197 | 239 |
|
198 | 240 | # Create an assistant with code interpreter |
199 | 241 | assistant = OpenAIAssistantAgent( |
200 | | - name="Python Helper", |
| 242 | + name="PythonHelper", |
201 | 243 | description="Helps with Python programming", |
202 | 244 | client=client, |
203 | 245 | model="gpt-4o", |
|
0 commit comments