Make openai dependency optional (#236)
* Make openai optional dependency * Set openai as an extra dependency
This commit is contained in:
		
							parent
							
								
									1f8fd72acb
								
							
						
					
					
						commit
						68933e7e90
					
				|  | @ -23,7 +23,6 @@ dependencies = [ | |||
|   "duckduckgo-search>=6.3.7", | ||||
|   "python-dotenv>=1.0.1", | ||||
|   "e2b-code-interpreter>=1.0.3", | ||||
|   "openai>=1.58.1", | ||||
| ] | ||||
| 
 | ||||
| [project.optional-dependencies] | ||||
|  | @ -37,12 +36,13 @@ torch = [ | |||
| litellm = [ | ||||
|   "litellm>=1.55.10", | ||||
| ] | ||||
| openai = ["openai>=1.58.1"] | ||||
| quality = [ | ||||
|   "ruff>=0.9.0", | ||||
| ] | ||||
| test = [ | ||||
|   "pytest>=8.1.0", | ||||
|   "smolagents[audio,litellm,torch]", | ||||
|   "smolagents[audio,litellm,openai,torch]", | ||||
| ] | ||||
| dev = [ | ||||
|   "smolagents[quality,test]", | ||||
|  | @ -59,4 +59,4 @@ lint.ignore = ["F403"] | |||
| [tool.ruff.lint.per-file-ignores] | ||||
| "examples/*" = [ | ||||
|   "E402", # module-import-not-at-top-of-file | ||||
| ] | ||||
| ] | ||||
|  |  | |||
|  | @ -34,8 +34,6 @@ from transformers import ( | |||
| ) | ||||
| from transformers.utils.import_utils import _is_package_available | ||||
| 
 | ||||
| import openai | ||||
| 
 | ||||
| from .tools import Tool | ||||
| 
 | ||||
| logger = logging.getLogger(__name__) | ||||
|  | @ -578,6 +576,12 @@ class OpenAIServerModel(Model): | |||
|         api_key: str, | ||||
|         **kwargs, | ||||
|     ): | ||||
|         try: | ||||
|             import openai | ||||
|         except ModuleNotFoundError: | ||||
|             raise ModuleNotFoundError( | ||||
|                 "Please install 'openai' extra to use OpenAIServerModel: `pip install 'smolagents[openai]'`" | ||||
|             ) from None | ||||
|         super().__init__() | ||||
|         self.model_id = model_id | ||||
|         self.client = openai.OpenAI( | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue