Skip to content

Commit

Permalink
tested injecting editor statics. WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusD123 committed Feb 8, 2025
1 parent 743fe57 commit e0af80d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
33 changes: 32 additions & 1 deletion src/haz3lweb/app/assistant/AssistantModel.re
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module Update = {
[@deriving (show({with_path: false}), sexp, yojson)]
type t =
| SendMessage(Model.message)
| SendSketch
| NewChat
| Respond(Model.message);

Expand All @@ -65,7 +66,13 @@ module Update = {
};

let update =
(~settings: Settings.t, ~action, ~model: Model.t, ~schedule_action)
(
~settings: Settings.t,
~action,
~editor: CellEditor.Model.t,
~model: Model.t,
~schedule_action,
)
: Updated.t(Model.t) => {
switch (action) {
| SendMessage(message) =>
Expand Down Expand Up @@ -97,6 +104,30 @@ module Update = {
| Respond(message) =>
Model.{chat: ListUtil.leading(model.chat) @ [message], currSender: LS}
|> Updated.return_quiet
| SendSketch =>
Util.OptUtil.Syntax.(
switch (
{
let* index = Indicated.index(editor.editor.state.zipper);
let* ci = Id.Map.find_opt(index, editor.statics.info_map);
let sketch_seg =
Zipper.smart_seg(
~dump_backpack=true,
~erase_buffer=true,
editor.editor.state.zipper,
);
ChatLSP.Prompt.mk_init(ChatLSP.Options.init, ci, sketch_seg);
}
) {
| None => print_endline("prompt generation failed")
| Some(openai_prompt) =>
List.iter(
(message: OpenAI.message) => print_endline(message.content),
openai_prompt,
)
}
);
Model.{chat: model.chat, currSender: LS} |> Updated.return_quiet;
};
};
};
Expand Down
8 changes: 6 additions & 2 deletions src/haz3lweb/debug/DebugConsole.re
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ let print =
let* ci = Id.Map.find_opt(index, map);
let sketch_seg =
Zipper.smart_seg(~dump_backpack=true, ~erase_buffer=true, zipper);
ChatLSP.Prompt.static_context(ChatLSP.Options.init, ci, sketch_seg);
ChatLSP.Prompt.mk_init(ChatLSP.Options.init, ci, sketch_seg);
}
) {
| None => print_endline("prompt generation failed")
| Some(prompt) => print_endline(prompt)
| Some(openai_prompt) =>
List.iter(
(message: OpenAI.message) => print_endline(message.content),
openai_prompt,
)
}
);
| "F10" =>
Expand Down
12 changes: 11 additions & 1 deletion src/haz3lweb/view/Page.re
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,19 @@ module Update = {
{...model, explain_this};
| Assistant(action) =>
let settings = globals.settings.assistant;
let ed: CellEditor.Model.t =
switch (model.editors) {
| Scratch(m) => List.nth(m.scratchpads, m.current) |> snd
| Documentation(m) => List.nth(m.scratchpads, m.current) |> snd
| Exercises(m) => List.nth(m.exercises, m.current).cells.user_impl // Todo this is an error
};
let* assistant =
AssistantModel.Update.update(
~settings, ~action, ~model=model.assistant, ~schedule_action=a =>
~settings,
~action,
~model=model.assistant,
~editor=ed,
~schedule_action=a =>
schedule_action(Assistant(a))
);
{...model, assistant};
Expand Down

0 comments on commit e0af80d

Please sign in to comment.