You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
raiseImportError("If you'd like to use OpenAI models, please install the openai package by running `pip install openai`, and add 'OPENAI_API_KEY' to your environment variables.")
4
+
raiseImportError(
5
+
"If you'd like to use OpenAI models, please install the openai package by running `pip install openai`, and add 'OPENAI_API_KEY' to your environment variables."
6
+
)
5
7
6
-
importos
7
-
importjson
8
8
importbase64
9
+
importjson
10
+
importos
11
+
fromtypingimportList, Union
12
+
9
13
importplatformdirs
10
14
fromtenacityimport (
11
15
retry,
12
16
stop_after_attempt,
13
17
wait_random_exponential,
14
18
)
15
-
fromtypingimportList, Union
16
19
17
-
from .baseimportEngineLM, CachedEngine
20
+
from .baseimportCachedEngine, EngineLM
18
21
from .engine_utilsimportget_image_type_from_bytes
19
22
20
23
# Default base URL for OLLAMA
21
-
OLLAMA_BASE_URL='http://localhost:11434/v1'
24
+
OLLAMA_BASE_URL="http://localhost:11434/v1"
22
25
23
26
# Check if the user set the OLLAMA_BASE_URL environment variable
24
27
ifos.getenv("OLLAMA_BASE_URL"):
25
28
OLLAMA_BASE_URL=os.getenv("OLLAMA_BASE_URL")
26
29
27
-
classChatOpenAI(EngineLM, CachedEngine):
30
+
31
+
classBaseOpenAIEngine(EngineLM, CachedEngine):
28
32
DEFAULT_SYSTEM_PROMPT="You are a helpful, creative, and smart assistant."
Initializes an interface for interacting with Azure's OpenAI models.
169
204
170
-
This class extends the ChatOpenAI class to use Azure's OpenAI API instead of OpenAI's API. It sets up the necessary client with the appropriate API version, API key, and endpoint from environment variables.
205
+
This class extends the EngineLM and CachedEngine classes to use Azure's OpenAI API instead of OpenAI's API. It sets up the necessary client with the appropriate API version, API key, and endpoint from environment variables.
171
206
172
-
:param model_string: The model identifier for Azure OpenAI. Defaults to 'gpt-3.5-turbo'.
173
-
:param system_prompt: The default system prompt to use when generating responses. Defaults to ChatOpenAI's default system prompt.
174
-
:param kwargs: Additional keyword arguments to pass to the ChatOpenAI constructor.
207
+
:param model_string: The model identifier for Azure OpenAI. Defaults to 'gpt-35-turbo'.
208
+
:param system_prompt: The default system prompt to use when generating responses. Defaults to the default system prompt.
209
+
:param is_multimodal: Whether this is a multimodal model. Defaults to False.
210
+
:param kwargs: Additional keyword arguments.
175
211
176
212
Environment variables:
177
213
- AZURE_OPENAI_API_KEY: The API key for authenticating with Azure OpenAI.
@@ -182,19 +218,21 @@ def __init__(
182
218
ValueError: If the AZURE_OPENAI_API_KEY environment variable is not set.
183
219
"""
184
220
root=platformdirs.user_cache_dir("textgrad")
185
-
cache_path=os.path.join(root, f"cache_azure_{model_string}.db") # Changed cache path to differentiate from OpenAI cache
221
+
cache_path=os.path.join(
222
+
root, f"cache_azure_{model_string}.db"
223
+
) # Changed cache path to differentiate from OpenAI cache
raiseValueError("Please set the AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_BASE, and AZURE_OPENAI_API_VERSION environment variables if you'd like to use Azure OpenAI models.")
193
-
229
+
raiseValueError(
230
+
"Please set the AZURE_OPENAI_API_KEY, AZURE_OPENAI_API_BASE, and AZURE_OPENAI_API_VERSION environment variables if you'd like to use Azure OpenAI models."
0 commit comments