Skip to content

armgit / dspy

Public Imported from GitHub
0

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

Python

System prompt support for azure open ai

Ayush9e303ac2f6a2
diff --git a/dsp/modules/azure_openai.py b/dsp/modules/azure_openai.py
index 35e897774..c80f82088 100644
--- a/dsp/modules/azure_openai.py
+++ b/dsp/modules/azure_openai.py
@@ -56,11 +56,14 @@ class AzureOpenAI(LM):
model: str = "gpt-3.5-turbo-instruct",
api_key: Optional[str] = None,
model_type: Literal["chat", "text"] = "chat",
+ system_prompt: Optional[str] = None,
**kwargs,
):
super().__init__(model)
self.provider = "openai"
+ self.system_prompt = system_prompt
+
# Define Client
if OPENAI_LEGACY:
# Assert that all variables are available
@@ -132,7 +135,11 @@ class AzureOpenAI(LM):
kwargs = {**self.kwargs, **kwargs}
if self.model_type == "chat":
# caching mechanism requires hashable kwargs
- kwargs["messages"] = [{"role": "user", "content": prompt}]
+ messages = [{"role": "user", "content": prompt}]
+ if self.system_prompt:
+ messages.insert(0, {"role": "system", "content": self.system_prompt})
+
+ kwargs["messages"] = messages
kwargs = {"stringify_request": json.dumps(kwargs)}
response = chat_request(self.client, **kwargs)