Skip to content
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

feat: add prompt comparison feature #704

Merged
merged 2 commits into from
Jan 5, 2025
Merged

Conversation

poroyo
Copy link
Contributor

@poroyo poroyo commented Jan 5, 2025

PR Checklist

  • Have you checked if it works normally in all models? Ignore this if it doesn't use models.
  • Have you checked if it works normally in all web, local, and node hosted versions? If it doesn't, have you blocked it in those versions?
  • Have you added type definitions?

Description

This PR adds a prompt comparison feature to the prompt preset interface. Now, users can compare two different prompts to identify differences.

How to Use

  1. Open the prompt preset window.
  2. Click the diff button (next to the copy button) for the first prompt to use as the baseline. The button will turn green, indicating selection.
c
  1. Click the diff button for the second prompt to compare against the baseline. A diff view will appear.
  2. Clicking the same diff button twice will clear the selection.

Diff Display Details

  • Line-level comparison
  • Modified lines: blue vertical line.
  • Deleted content: red text on red background with red vertical line.
  • Added content: green text on light green background with green vertical line.
b
  • If the prompt content is identical, the following message will be displayed at the top
a

Implementation Details

  1. handleDiffMode manages prompt selection and clearing.
  2. checkDiff compares prompts and uses highlightChanges to mark differences.
  3. Special characters are escaped with escapeHtml to ensure the text is displayed as-is.
  4. resultHtml is rendered via alertMd.

Notes

  • This feature uses the jsdiff library to compare prompts efficiently.
  • The comparison includes the role, type1, and type2 fields (e.g., ## system; plain; main). Even if the prompts' text is identical, differences in these fields will be treated as a mismatch.
  • The rendering process in alertMd appears to sanitize potentially dangerous content. However, additional escaping is applied to ensure that the text is displayed as-is.
  • botpreset.svelte grew significantly due to this feature; modularization was considered but not implemented.
  • The reason for using the "Prompt Preset" window instead of the "Prompt Preview" feature is that "Prompt Preview" displays the final form with CBS processing applied. Even if the content in "Prompt Preview" appears identical, the actual prompts can differ significantly.

If this feature, its implementation, or any other issue doesn't fit the project's vision, feel free to reject this PR! Thank you for reviewing!

@kwaroran kwaroran merged commit 7d1e9dc into kwaroran:main Jan 5, 2025
@poroyo poroyo deleted the feat/prompt-diff branch January 5, 2025 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants