DSPy: The framework for programming—not prompting—language models
Python
add system prompt to GPT
xdite6bb562a92eb6
diff --git a/dsp/modules/gpt3.py b/dsp/modules/gpt3.pyindex cd9359bc1..02d3929b9 100644--- a/dsp/modules/gpt3.py+++ b/dsp/modules/gpt3.py@@ -62,12 +62,15 @@ class GPT3(LM):api_provider: Literal["openai"] = "openai",api_base: Optional[str] = None,model_type: Literal["chat", "text"] = None,+ system_prompt: Optional[str] = None,**kwargs,):super().__init__(model)self.provider = "openai"openai.api_type = api_provider+ self.system_prompt = system_prompt+assert (api_provider != "azure"), "Azure functionality with base OpenAI has been deprecated, please use dspy.AzureOpenAI instead."@@ -118,6 +121,9 @@ class GPT3(LM):kwargs = {**self.kwargs, **kwargs}if self.model_type == "chat":# caching mechanism requires hashable kwargs+ messages = [{"role": "user", "content": prompt}]+ if self.system_prompt:+ messages.insert(0, {"role": "system", "content": self.system_prompt})kwargs["messages"] = [{"role": "user", "content": prompt}]kwargs = {"stringify_request": json.dumps(kwargs)}response = chat_request(**kwargs)