Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This adds a single file,
ChatLSP.re
, which contains all the hazel-language-server-side internals from thellama-lsp-lookahead
branch necessary to reproduce the process described in the static contextualization paper. This does not include any of the hazel frontend logic (ie prompting via??
, making the initial and followup API calls, and ensuing insertion of the response into the code).The basic entry points are
ChatLSP.Prompt.mk_init
, which creates the initial prompt to be sent to the llm, andChatLSP.Prompt.mk_error
, which, given a candidate completion as a string, creates an string error report to be sent to the llm.I've provided demos of both via the debug console (see
DebugConsole.re
). PressingShift-F9
(Fn-Shift-F9
on a macbook) will print an initial user prompt (but not the generic system prompt) relevant to the current caret position to the console:Note that the prompt printed consists of the program sketch (here i'm just using the whole program), the expected type, relevant type definitions, and relevant function headers. When experimenting with this note that there will only be relevant defs/headers included if the expected type contains user-defined types, and there will only be relevant function headers if there are actually functions in the program which involve those types.
Pressing
Shift-F10
(Fn-Shift-F10
on a macbook) will print an error report for the whole program. This will likely be useful for debugging, but note that in actual use we'll want an error report for the completion, which is slightly different in that the initial typing context and mode should reflect the cursor info of the completion location, not the generic top-level builtin initial context and synthetic mode hardcoded into this demo:Caveats: While I cleaned up the code a bit, I brought it up to date with dev in a pretty fast-and-loose way... the type internals here will need review at some point, and some should likely be moved out of ChatLSP.re to more natural homes, but this should be more than enough to get started. While ChatLSP.re is reasonably comprehensive, many of the construction details will need to be adapted somewhat, especially when it comes to forming the program sketch, representing holes in the string representation of the program, and other assorted details of building up string/JSON messages.
I'd suggest that changes should involve defining more structured intermediary data types, and only converting things to strings/JSON on the absolute edges. For example, this version has the expected type and relevant type definitions as part of the same string. if you made a record to represent the various kind of static info, and kept stuff in the internal syntax type where appropriate, then you could use that to drive pretty-printed views of that information in the sidebar.
I've also left a variety of TODOs, some new, some old; most of these are likely not obviously actionable but are good places to look if there are bugs.