DSPy: The framework for programming—not prompting—language models
Python
fix(dspy): add `copy` to AzureOpenAI to propagate `api_(key|version|base)`
snimu6b2c09f7db1c
diff --git a/dsp/modules/azure_openai.py b/dsp/modules/azure_openai.pyindex 6ff774e76..1c7cef225 100644--- a/dsp/modules/azure_openai.py+++ b/dsp/modules/azure_openai.py@@ -108,6 +108,10 @@ class AzureOpenAI(LM):**kwargs,} # TODO: add kwargs above for </s>+ self.api_base = api_base+ self.api_version = api_version+ self.api_key = api_key+self.history: list[dict[str, Any]] = []def _openai_client(self):@@ -219,6 +223,19 @@ class AzureOpenAI(LM):completions = [c for _, c in scored_completions]return completions++ def copy(self, **kwargs):+ """Returns a copy of the language model with the same parameters."""+ kwargs = {**self.kwargs, **kwargs}+ model = kwargs.pop("model")++ return self.__class__(+ model=model,+ api_key=self.api_key,+ api_version=self.api_version,+ api_base=self.api_base,+ **kwargs,+ )@CacheMemory.cache