Skip to content

Use system_prompt in solver configuration (breaking change) #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 2, 2025

Conversation

Delfshkrimm
Copy link
Contributor

@Delfshkrimm Delfshkrimm commented Feb 3, 2025

Summary by CodeRabbit

  • New Features
    • Improved configuration flexibility for chat prompts by supporting a customizable system prompt.
  • Bug Fixes
    • Ensured the system prompt is always present in chat interactions for consistent behavior.
  • Refactor
    • Updated default OpenAI model to "gpt-4o-mini" for enhanced performance.
    • Deprecated and simplified legacy persona solver, directing users to the newer solver.
  • Chores
    • Updated plugin entry point to reference the latest solver implementation.

Copy link
Contributor

coderabbitai bot commented Feb 3, 2025

Walkthrough

This update deprecates the OpenAIPersonaSolver class, removing its custom persona and chat history handling, and directs users to use OpenAIChatCompletionsSolver instead. The plugin entry point in setup.py is updated to reference OpenAICompletionsSolver in the engines module. Prompt handling across the codebase is standardized by replacing the initial_prompt configuration with system_prompt, ensuring the system prompt is always present in chat interactions. The default OpenAI model is also changed from "text-davinci-002" to "gpt-4o-mini", and type hints are refined for clarity.

Changes

File(s) Change Summary
ovos_solver_openai_persona/__init__.py Deprecated OpenAIPersonaSolver, removed persona/chat history logic, and updated demo solver key; now issues a deprecation warning.
ovos_solver_openai_persona/dialog_transformers.py Replaced initial_prompt with system_prompt in solver initialization, allowing config override for the prompt text.
setup.py Changed plugin entry point to use OpenAICompletionsSolver from the engines submodule.
ovos_solver_openai_persona/engines.py Changed default model to "gpt-4o-mini", replaced initial_prompt with system_prompt, ensured system prompt in chat, and updated type hints.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Plugin
    participant OpenAICompletionsSolver
    participant OpenAIChatCompletionsSolver

    User->>Plugin: Sends query
    Plugin->>OpenAIChatCompletionsSolver: Passes query and config (with system_prompt)
    OpenAIChatCompletionsSolver->>OpenAICompletionsSolver: Ensures system_prompt is present
    OpenAICompletionsSolver->>OpenAI API: Sends request with system_prompt and query
    OpenAI API-->>OpenAICompletionsSolver: Returns response
    OpenAICompletionsSolver-->>OpenAIChatCompletionsSolver: Forwards response
    OpenAIChatCompletionsSolver-->>Plugin: Returns processed answer
    Plugin-->>User: Delivers answer
Loading

Possibly related PRs

Suggested labels

fix

Suggested reviewers

  • goldyfruit

Poem

A hop and a skip, the persona’s retired,
New solvers and prompts are now required.
With system prompts clear and models anew,
The plugin hops forward—so much to do!
Deprecated paths, we bid you adieu,
As rabbits code on, with a bright point of view!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 82cc2b1 and 15bdb83.

📒 Files selected for processing (1)
  • ovos_solver_openai_persona/engines.py (6 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • ovos_solver_openai_persona/engines.py
✨ Finishing Touches
  • 📝 Docstrings were successfully generated. (🔄 Check again to generate docstrings again)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
ovos_solver_openai_persona/__init__.py (1)

37-42: Consider adding docstring for the new method.

The new stream_chat_utterances method implementation looks good, but it's missing documentation.

Add a docstring to improve code maintainability:

 def stream_chat_utterances(self, messages: List[Dict[str, str]],
                            lang: Optional[str] = None,
                            units: Optional[str] = None) -> Iterable[str]:
+    """Stream chat utterances with system prompt prepended.
+
+    Args:
+        messages (List[Dict[str, str]]): List of message dictionaries with 'role' and 'content'.
+        lang (Optional[str], optional): Language code. Defaults to None.
+        units (Optional[str], optional): Units for the query. Defaults to None.
+
+    Yields:
+        str: Generated utterances from the chat model.
+    """
     messages = [{"role": "system", "content": self.system_prompt }] + messages
     answer = super().stream_chat_utterances(messages, lang, units)
     yield from answer
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b9ccf8 and badaf9c.

📒 Files selected for processing (4)
  • README.md (2 hunks)
  • ovos_solver_openai_persona/__init__.py (3 hunks)
  • ovos_solver_openai_persona/engines.py (2 hunks)
  • ovos_solver_openai_persona/version.py (1 hunks)
🔥 Files not summarized due to errors (1)
  • ovos_solver_openai_persona/engines.py: Error: Disallowed special token found: <|im_end|>
✅ Files skipped from review due to trivial changes (1)
  • ovos_solver_openai_persona/version.py
🔇 Additional comments (4)
ovos_solver_openai_persona/__init__.py (2)

12-12: LGTM! Good default system prompt.

The default system prompt is well-crafted, providing clear personality traits that align with a helpful assistant.


15-15: LGTM! Clean persona parameter handling.

The method correctly forwards the system prompt to the parent class, maintaining backward compatibility by keeping the unused persona parameter.

README.md (2)

16-16: LGTM! Clear example of system prompt usage.

The example demonstrates the new parameter name with a clear and descriptive prompt value.


36-36: LGTM! Configuration example updated correctly.

The configuration example has been updated to use the new parameter name with a simple, clear default value.

@Delfshkrimm Delfshkrimm changed the title Use system_prompt in solver configuration Use system_prompt in solver configuration (breaking change) Feb 3, 2025
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
ovos_solver_openai_persona/__init__.py (1)

26-26: Consider updating example comments to reflect new class.

The bot instantiation correctly uses OpenAIChatCompletionsSolver. However, the example output comments below might benefit from being regenerated using the new class to ensure they accurately reflect current behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a9ca8f2 and 0176017.

📒 Files selected for processing (2)
  • ovos_solver_openai_persona/__init__.py (2 hunks)
  • ovos_solver_openai_persona/engines.py (5 hunks)
🔥 Files not summarized due to errors (1)
  • ovos_solver_openai_persona/engines.py: Error: Disallowed special token found: <|im_end|>
🔇 Additional comments (2)
ovos_solver_openai_persona/__init__.py (2)

1-1: LGTM!

The warnings import is correctly added to support the deprecation warning.


5-11: Implementation matches requested changes.

The deprecation warning has been implemented exactly as requested by JarbasAl, with proper warning message, deprecation type, and stack level.

Delfshkrimm and others added 6 commits May 2, 2025 12:48
Cleaned system_prompt saving in init method
Changed references to initial_prompt to system_prompt to unify
Bumped major version to signify breaking change
Removed specific OpenAIPersonaSolver class to use OpenAIChatCompletionsSolver
Moved specifics for system_prompt to OpenAIChatCompletionsSolver
Updated docs to reflect changes
…rent class

Prepend message system prompt to continue_chat method when not streaming utterances from OpenAI API
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
ovos_solver_openai_persona/engines.py (1)

110-115: Good deprecation pattern for system_prompt implementation

The code properly handles the transition from 'initial_prompt' to 'system_prompt' with:

  1. Clear deprecation warning
  2. Fallback to initial_prompt if system_prompt is not set
  3. Default value if neither is provided

Consider using LOG.warning instead of LOG.error for the default message since this is a fallback behavior rather than a true error condition.

-            LOG.error(f"system prompt not set in config! defaulting to '{self.system_prompt}'")
+            LOG.warning(f"system prompt not set in config! defaulting to '{self.system_prompt}'")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b61365b and 040f589.

📒 Files selected for processing (4)
  • ovos_solver_openai_persona/__init__.py (1 hunks)
  • ovos_solver_openai_persona/dialog_transformers.py (1 hunks)
  • ovos_solver_openai_persona/engines.py (6 hunks)
  • setup.py (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • ovos_solver_openai_persona/dialog_transformers.py
  • setup.py
  • ovos_solver_openai_persona/init.py
🔇 Additional comments (5)
ovos_solver_openai_persona/engines.py (5)

27-27: Model upgrade is a breaking change, but well-documented

Changing the default model from "text-davinci-002" to "gpt-4o-mini" is a significant update that might affect response behavior, token usage, and costs for users. This change aligns with the PR title indicating a breaking change, which is good for transparency.


187-190: Parameter update for get_chat_history is consistent

The method now accepts an optional system_prompt parameter and uses the same fallback logic as the class initialization. The fallback chain (parameter -> self.system_prompt -> default) is clear and maintainable.


198-200: Simplified get_messages implementation

The updated method correctly forwards the system_prompt parameter to get_chat_history, maintaining the function's purpose while supporting the new system_prompt configuration.


217-219: Ensure system messages are present in continue_chat

This is a good defensive check to ensure the first message is always a system message, which is required for consistent behavior with the OpenAI API. The implementation automatically prepends the system prompt if needed, providing backward compatibility.


242-244: Ensure system messages are present in stream_chat_utterances

Similar to the continue_chat method, this change ensures the conversation always starts with a system message. Maintaining this consistency across both methods is important for reliable behavior.

coderabbitai bot added a commit that referenced this pull request May 2, 2025
Docstrings generation was requested by @JarbasAl.

* #19 (comment)

The following files were modified:

* `ovos_solver_openai_persona/__init__.py`
* `ovos_solver_openai_persona/dialog_transformers.py`
* `ovos_solver_openai_persona/engines.py`
Copy link
Contributor

coderabbitai bot commented May 2, 2025

Note

Generated docstrings for this pull request at #26

@JarbasAl JarbasAl merged commit 8ff7430 into OpenVoiceOS:dev May 2, 2025
1 check passed
JarbasAl added a commit that referenced this pull request May 2, 2025
* 📝 Add docstrings to `patch-1`

Docstrings generation was requested by @JarbasAl.

* #19 (comment)

The following files were modified:

* `ovos_solver_openai_persona/__init__.py`
* `ovos_solver_openai_persona/dialog_transformers.py`
* `ovos_solver_openai_persona/engines.py`

* Update engines.py

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAI <[email protected]>
JarbasAl added a commit that referenced this pull request May 2, 2025
* Update downstream dependencies for ovos-openai-plugin

* Update downstream dependencies for ovos-openai-plugin

* Update downstream dependencies for ovos-openai-plugin

* Update downstream dependencies for ovos-openai-plugin

* Update downstream dependencies for ovos-openai-plugin

* Merge pull request #19 from Delfshkrimm/patch-1

Use system_prompt in solver configuration (breaking change)

* 📝 Add docstrings to `patch-1` (#26)

* 📝 Add docstrings to `patch-1`

Docstrings generation was requested by @JarbasAl.

* #19 (comment)

The following files were modified:

* `ovos_solver_openai_persona/__init__.py`
* `ovos_solver_openai_persona/dialog_transformers.py`
* `ovos_solver_openai_persona/engines.py`

* Update engines.py

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAI <[email protected]>

* Increment Version to 2.0.2a1

* Update Changelog

* Update README.md

* Update downstream dependencies for ovos-openai-plugin

* Update README.md

* Update README.md

* Update README.md

* Update release_workflow.yml

* Increment Version to 2.0.2a2

* fix: setup.py (#29)

* Increment Version to 2.0.2a3

* Update Changelog

* Update __init__.py

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Delfshkrimm <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Co-authored-by: JarbasAI <[email protected]>
Co-authored-by: JarbasAl <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants