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

fix: detect and remove markdown block syntax that llms sometimes hallucinate for file actions #886

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wonderwhy-er
Copy link
Collaborator

@wonderwhy-er wonderwhy-er commented Dec 24, 2024

Reason for Change

Sometimes AI responds with files wrapped in markdown code block syntax, causing issues and wasting tokens. The goal is to clean this up for non-Markdown files to improve efficiency and output clarity.

What Was Done

  • Added logic in message-parser.ts to detect and remove markdown code block syntax for non-Markdown files using regex.
  • lint:fix made minor formatting and readability improvements in DataTab.tsx

Example Chat for Testing where problem is present

https://gist.github.com/wonderwhy-er/969023d7146a5f3e3ec90ec99ba4bc4e

const match = content.match(codeBlockRegex);

if (match) {
content = match[1].replace(/^[ ]{4}/gm, '').trim(); // Remove common leading 4-space indent
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think its good idea to remove any indenting manually, cuz not all models use that. the reason its happening is the system prompt has the extra indentation in the examples we can first try and remove that and see if the llms are still adding this.

for python codes this can cause issues if not done correctly

@thecodacus thecodacus changed the title fix: Detect and remove markdown block syntax that llms sometimes hallucinate for file actions fix: detect and remove markdown block syntax that llms sometimes hallucinate for file actions Dec 24, 2024
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