Skip to content

Commit 9e303ac

Browse files
committed
System prompt support for azure open ai
1 parent 8f1becf commit 9e303ac

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

dsp/modules/azure_openai.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,14 @@ def __init__(
5656
model: str = "gpt-3.5-turbo-instruct",
5757
api_key: Optional[str] = None,
5858
model_type: Literal["chat", "text"] = "chat",
59+
system_prompt: Optional[str] = None,
5960
**kwargs,
6061
):
6162
super().__init__(model)
6263
self.provider = "openai"
6364

65+
self.system_prompt = system_prompt
66+
6467
# Define Client
6568
if OPENAI_LEGACY:
6669
# Assert that all variables are available
@@ -132,7 +135,11 @@ def basic_request(self, prompt: str, **kwargs):
132135
kwargs = {**self.kwargs, **kwargs}
133136
if self.model_type == "chat":
134137
# caching mechanism requires hashable kwargs
135-
kwargs["messages"] = [{"role": "user", "content": prompt}]
138+
messages = [{"role": "user", "content": prompt}]
139+
if self.system_prompt:
140+
messages.insert(0, {"role": "system", "content": self.system_prompt})
141+
142+
kwargs["messages"] = messages
136143
kwargs = {"stringify_request": json.dumps(kwargs)}
137144
response = chat_request(self.client, **kwargs)
138145

0 commit comments

Comments
 (0)