Skip to content

armgit / dspy

Public Imported from GitHub
0

DSPy: The framework for programming—not prompting—language models

Python

fix: updated constructor for AzureOpenAI to accomodate for mandatory arguments

KCaverly69f201cca7e3
diff --git a/dsp/modules/azure_openai.py b/dsp/modules/azure_openai.py
index 4b3a4c592..003928105 100644
--- a/dsp/modules/azure_openai.py
+++ b/dsp/modules/azure_openai.py
@@ -50,6 +50,8 @@ class AzureOpenAI(LM):
"""Wrapper around Azure's API for OpenAI.
Args:
+ api_base (str): Azure URL endpoint for model calling, often called 'azure_endpoint'.
+ api_version (str): Version identifier for API.
model (str, optional): OpenAI or Azure supported LLM model to use. Defaults to "text-davinci-002".
api_key (Optional[str], optional): API provider Authentication token. use Defaults to None.
model_type (Literal["chat", "text"], optional): The type of model that was specified. Mainly to decide the optimal prompting strategy. Defaults to "text".
@@ -58,28 +60,27 @@ class AzureOpenAI(LM):
def __init__(
self,
+ api_base: str,
+ api_version: str,
model: str = "gpt-3.5-turbo-instruct",
api_key: Optional[str] = None,
- api_base: Optional[str] = None,
model_type: Literal["chat", "text"] = None,
**kwargs,
):
super().__init__(model)
self.provider = "openai"
- # Assert that all variables are available
- assert (
- "engine" in kwargs or "deployment_id" in kwargs
- ), "Must specify engine or deployment_id for Azure API instead of model."
- assert "api_version" in kwargs, "Must specify api_version for Azure API"
- assert api_base is not None, "Must specify api_base for Azure API"
-
# Define Client
if OPENAI_LEGACY:
+ # Assert that all variables are available
+ assert (
+ "engine" in kwargs or "deployment_id" in kwargs
+ ), "Must specify engine or deployment_id for Azure API instead of model."
+
openai.api_base = api_base
openai.api_key = api_key
openai.api_type = "azure"
- openai.api_version = kwargs["api_version"]
+ openai.api_version = api_version
self.client = None
@@ -87,7 +88,7 @@ class AzureOpenAI(LM):
client = openai.AzureOpenAI(
azure_endpoint=api_base,
api_key=api_key,
- api_version=kwargs["api_version"],
+ api_version=api_version,
)
self.client = client