stanfordnlp / dspy

DSPy: The framework for programming—not prompting—language models
https://dspy.ai
MIT License
19.27k stars 1.47k forks source link

dspy.LM system prompt old behaviour #1643

Closed MohammedAlhajji closed 1 month ago

MohammedAlhajji commented 1 month ago

I'm trying to migrate to dspy.LM. I noticed that I now have to pass the system prompt in the messages that I send to the module. I'd like to suggest that we allow users to still pass the system prompt in dspy.LM, since we still support passing only the prompt, not just the messages list.

I think it'd be nice to make a small change in dspy.LM at ~ line 35

        cache = kwargs.pop("cache", self.cache)
        messages = messages or [{"role": "user", "content": prompt}]
        # ------------------------------------------------------------------------------------
        if self.system_prompt:
            assert messages[0]["role"] == "user", "System prompt was passed on model intialization and in messages."
            messages.insert(0, {"role": "system", "content": self.system_prompt})
        # -------------------------------------------------------------------------------------
        kwargs = {**self.kwargs, **kwargs}

These two lines will allows users who want to use system prompt to pass system prompt on dspy.LM and then only prompting the module with a prompt

okhat commented 1 month ago

Hey @MohammedAlhajji , this doesn't work anymore because DSPy builds a system prompt now.

What you may be trying to do is to build a new Adapter. See the migration guide: https://github.com/stanfordnlp/dspy/blob/main/examples/migration.ipynb

Let me know if this addresses your goal!

MohammedAlhajji commented 1 month ago

Thanks for your response. Sorry my bad. Should've read that migration guide