|
12 | 12 | from pathlib import Path |
13 | 13 | from typing import Any |
14 | 14 |
|
15 | | -from anthropic import Anthropic |
16 | | -from google import genai |
17 | | -from mistralai import Mistral |
18 | | -from openai import OpenAI |
19 | 15 | from pydantic import TypeAdapter, ValidationError |
20 | 16 |
|
21 | 17 | from ._caller_context import capture_caller_context |
22 | 18 | from ._lazy_client import LazyClient |
23 | | -from .clients.grok_client import GROK_BASE_URL |
24 | | -from .clients.openrouter_client import OPENROUTER_BASE_URL |
25 | 19 | from .exceptions import StructuredOutputParsingError |
26 | 20 | from .keys import ( |
27 | 21 | get_anthropic_api_key, |
@@ -105,33 +99,49 @@ def _require_key( |
105 | 99 | ) -> str: |
106 | 100 | return require_api_key(override or getter(), provider) |
107 | 101 |
|
108 | | - def _create_openai_client(self) -> OpenAI: |
| 102 | + def _create_openai_client(self): |
| 103 | + from openai import OpenAI |
| 104 | + |
109 | 105 | api_key = self._require_key(self._openai_api_key, "openai", get_openai_api_key) |
110 | 106 | return OpenAI(api_key=api_key) |
111 | 107 |
|
112 | | - def _create_openrouter_client(self) -> OpenAI: |
| 108 | + def _create_openrouter_client(self): |
| 109 | + from openai import OpenAI |
| 110 | + |
| 111 | + from .clients.openrouter_client import OPENROUTER_BASE_URL |
| 112 | + |
113 | 113 | api_key = self._require_key( |
114 | 114 | self._openrouter_api_key, "openrouter", get_openrouter_api_key |
115 | 115 | ) |
116 | 116 | return OpenAI(api_key=api_key, base_url=OPENROUTER_BASE_URL) |
117 | 117 |
|
118 | | - def _create_gemini_client(self) -> genai.Client: |
| 118 | + def _create_gemini_client(self): |
| 119 | + from google import genai |
| 120 | + |
119 | 121 | api_key = self._require_key(self._gemini_api_key, "gemini", get_gemini_api_key) |
120 | 122 | return genai.Client(api_key=api_key) |
121 | 123 |
|
122 | | - def _create_mistral_client(self) -> Mistral: |
| 124 | + def _create_mistral_client(self): |
| 125 | + from mistralai import Mistral |
| 126 | + |
123 | 127 | api_key = self._require_key( |
124 | 128 | self._mistral_api_key, "mistral", get_mistral_api_key |
125 | 129 | ) |
126 | 130 | return Mistral(api_key=api_key) |
127 | 131 |
|
128 | | - def _create_anthropic_client(self) -> Anthropic: |
| 132 | + def _create_anthropic_client(self): |
| 133 | + from anthropic import Anthropic |
| 134 | + |
129 | 135 | api_key = self._require_key( |
130 | 136 | self._anthropic_api_key, "anthropic", get_anthropic_api_key |
131 | 137 | ) |
132 | 138 | return Anthropic(api_key=api_key) |
133 | 139 |
|
134 | | - def _create_grok_client(self) -> OpenAI: |
| 140 | + def _create_grok_client(self): |
| 141 | + from openai import OpenAI |
| 142 | + |
| 143 | + from .clients.grok_client import GROK_BASE_URL |
| 144 | + |
135 | 145 | api_key = self._require_key(self._grok_api_key, "grok", get_grok_api_key) |
136 | 146 | return OpenAI(api_key=api_key, base_url=GROK_BASE_URL) |
137 | 147 |
|
|
0 commit comments