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

Update ChatCraftCommand::isCommand() criteria for slash function #567

Merged
merged 2 commits into from
Apr 5, 2024

Conversation

rjwignar
Copy link
Collaborator

@rjwignar rjwignar commented Apr 5, 2024

This fixes #500.
The issue encountered above is due to ChatBase interpreting a non-slash command (in this case, a filepath in an error message) as a slash command:
image

isCommand() currently treats every prompt starting with a forward slash as a potential slash command, then either tries to execute the slash command or parse the invalid command to notify the user (i.e [invalid command] is not a valid command!).

This PR reuses the parseCommand() Regex in isCommand() so things like filepaths aren't treated as a potential slash command:

static parseCommand(input: string): { command: string; args: string[] } | null {
const match = input.match(/^\/(\w+)(?:\s+(.*))?$/);
if (!match) return null;

How to Test

  • Test every existing slash command in the preview and confirm they still work
  • Copy/paste the codeblock from the Issue description into a new chat and confirm it is sent as a message analyzed by the LLM.

Potential Issue

I think this is a step in the right direction, but the Regex in the new isCommand() is not perfect.
If the user enters a slash command containing a non-word (special) character, it will be sent to the LLM:
image

@rjwignar rjwignar self-assigned this Apr 5, 2024
src/lib/ChatCraftCommand.ts Outdated Show resolved Hide resolved
Copy link

cloudflare-workers-and-pages bot commented Apr 5, 2024

Deploying chatcraft-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3e35593
Status: ✅  Deploy successful!
Preview URL: https://5a483f39.console-overthinker-dev.pages.dev
Branch Preview URL: https://issue-500.console-overthinker-dev.pages.dev

View logs

Copy link
Collaborator

@humphd humphd left a comment

Choose a reason for hiding this comment

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

ship it

@rjwignar rjwignar merged commit e6dd866 into main Apr 5, 2024
4 checks passed
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.

Chatcraft commands conflict with code errors
2 participants