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: invalid identifiers #133

Merged
merged 2 commits into from
Oct 6, 2024
Merged

Conversation

j4k0xb
Copy link
Contributor

@j4k0xb j4k0xb commented Sep 28, 2024

Closes #117
Also related to #111

@0xdevalias
Copy link

0xdevalias commented Sep 29, 2024

Closes #117

I would say this is a partial fix/workaround to #117, though I think there is probably a better higher level fix (that can be implemented in another PR) that I would sort of suggest should be done before we consider #117 closed entirely:

The proper fix would be to use toIdentifier from @babel/types

@j4k0xb @jehna From a 2sec search I couldn't find rendered docs, but here's the relevant source for each:

toIdentifier definitely seems like a more robust approach than the current 'prefix with _' approach for sure.

Though I wonder if a 'proper fix' should also involve tweaking how we prompt for/filter the suggestions coming back from the LLM itself as well. Like instead of just forcing an invalid suggestion to be valid (with toIdentifier), we could detect that it's invalid (with isValidIdentifier) and then provide that feedback to the LLM, asking it to give a new suggestion; probably with some max retry limit; after which we could fall back to using the invalid suggestion run through toIdentifier, or log a warning and leave it un-renamed or similar.

Originally posted by @0xdevalias in #117 (comment)


Also related to #111

For context/continuity, while it's related to the 2nd part of the bugs identified in #111, your other fix PR is related to the original error on it:

@jehna jehna added the bug Something isn't working label Oct 6, 2024
@jehna
Copy link
Owner

jehna commented Oct 6, 2024

@0xdevalias good point! I opened another issue for that implementation at #147

@jehna jehna merged commit 7f9e0b4 into jehna:main Oct 6, 2024
3 of 4 checks passed
assert.equal(result, "const thisKLength = 1;");
});

test("should handle space in identifier name (happens for some reason though it shouldn't)", async () => {
Copy link
Contributor Author

@j4k0xb j4k0xb Oct 6, 2024

Choose a reason for hiding this comment

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

gbnf`A good name would be '${/[a-zA-Z] [a-zA-Z0-9]{2,12}/}'`

maybe because the regex has a space
and would ^ $ make a difference?

Copy link
Owner

@jehna jehna Oct 6, 2024

Choose a reason for hiding this comment

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

This regex is actually a representation of gbnf, which is a superset of regex that allows strings edit: spaces in between. If it were a normal regex, all variable names should have a space in them, right?

To me this seems like an issue with the llama.cpp gbnf handling

Copy link
Owner

Choose a reason for hiding this comment

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

Another thing I'll need to check from the previous issues is that whether the users were using local or openai mode. Local mode is much more robust, openai does not have any actual guarantees about returning a valid identifier name.

Choose a reason for hiding this comment

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

@jehna From memory, for at least some of the ones I was looking at/debugging, I believe they were using openai, not local.

@j4k0xb j4k0xb deleted the fix/invalid-identifiers branch October 6, 2024 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Syntax Error on Babel?
3 participants