From c391d0af75381f9d89b4e525abcf346e9d6fd015 Mon Sep 17 00:00:00 2001 From: J S <49557684+svilupp@users.noreply.github.com> Date: Fri, 3 May 2024 19:16:58 +0100 Subject: [PATCH] add --- Project.toml | 2 +- app.jl | 38 +++++++++++++++++++++++++++++++++++--- src/view_chat.jl | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 8 deletions(-) diff --git a/Project.toml b/Project.toml index 4112815..72155f1 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "ProToPortal" uuid = "f9496bd6-a3bb-4afc-927d-7268532ebfa9" authors = ["J S <49557684+svilupp@users.noreply.github.com> and contributors"] -version = "0.1.0" +version = "0.2.0-DEV" [deps] GenieFramework = "a59fdf5c-6bf0-4f5d-949c-a137c9e2f353" diff --git a/app.jl b/app.jl index 260a5c5..5b14e07 100644 --- a/app.jl +++ b/app.jl @@ -12,9 +12,10 @@ using GenieFramework.Genie.Requests: postpayload Stipple.Layout.add_script("https://cdn.tailwindcss.com") #! CONFIGURATION -const HISTORY_DIR = joinpath(@__DIR__, "chat_history") +# Change if you want to save conversations to a specific folder +const HISTORY_DIR = get(ENV, "PROTO_HISTORY_DIR", joinpath(@__DIR__, "chat_history")) # Change if you don't want to auto-save conversations (after clicking "New chat") -const HISTORY_SAVE = true +const HISTORY_SAVE = get(ENV, "PROTO_HISTORY_SAVE", true) @appname Portal @@ -78,6 +79,7 @@ const HISTORY_SAVE = true @in chat_submit = false @in chat_reset = false @in chat_rm_last_msg = false + @in chat_fork = false # Template browser @in template_filter = "" @in template_submit = false @@ -91,6 +93,7 @@ const HISTORY_SAVE = true # Dashboard logic @onchange isready begin @info "> Dashboard is ready!" + isdir(HISTORY_DIR) || mkpath(HISTORY_DIR) end @onbutton model_submit begin if !isempty(model_input) @@ -224,6 +227,12 @@ const HISTORY_SAVE = true pop!(conv_displayed) conv_displayed = conv_displayed end + @onbutton chat_fork begin + @info "> Forking conversation (reset+load)!" + conv_displayed_temp = deepcopy(conv_displayed) + chat_reset = true + conv_displayed = conv_displayed_temp + end ### Template browsing behavior @onbutton template_submit begin @info "> Template filter: $template_filter" @@ -261,8 +270,32 @@ end ## TODO: add cost tracking on configuration pages + token tracking ## TODO: add RAG/knowledge loading from folder or URL # Required for the JS events + +# set focus to the first variable when it changes +@watch begin + raw""" + chat_template_variables() { + this.$nextTick(() => { + this.$refs.variables[0].focus(); + }) + } + + """ +end @methods begin raw""" + buttonFunc(index) { + console.log("buttonFunc",index); + console.log("length", this.conv_displayed.length); + if (this.conv_displayed.length==index) { + console.log("woowza"); + } + }, + focusTemplateSelect() { + this.$nextTick(() => { + this.$refs.tpl_select.focus(); + }); + }, filterFn (val, update) { if (val === '') { update(() => { @@ -271,7 +304,6 @@ end }) return } - update(() => { // filter down based on user provided input const needle = val.toLowerCase() diff --git a/src/view_chat.jl b/src/view_chat.jl index 8f812a6..f0d76e2 100644 --- a/src/view_chat.jl +++ b/src/view_chat.jl @@ -12,13 +12,15 @@ function tab_chat_settings() [ btn("Delete last message", icon = "delete", @click(:chat_rm_last_msg)), - btn("New Chat", icon = "refresh", @click(:chat_reset))]), + btn("New Chat", icon = "refresh", @click(:chat_reset)), + btn("Fork Conversation", icon = "refresh", @click(:chat_fork)) + ]), separator(), p("Generation Settings", class = "text-lg text-weight-bold pt-4"), p("Temperature (0=conservative, 2=crazy)"), slider( 0.0:0.1:2, :chat_temperature, labelalways = true, snap = true, - markers = 1, label = "Temperature"), + markers = 1), ##, separator(), p("Code Evaluation", class = "text-lg text-weight-bold"), @@ -66,6 +68,7 @@ function tab_chat_templates() dense = true, densetoggle = true, v__model = :chat_template_expanded, + @on(:click, "focusTemplateSelect"), expandseparator = true, headerstyle = "bg-blue-1", [ @@ -75,6 +78,7 @@ function tab_chat_templates() label = "Template", clearable = true, useinput = true, + ref = "tpl_select", class = "pb-4", @on(:filter, "filterFn") ), @@ -87,7 +91,8 @@ function tab_chat_templates() key! = R"item.id", [ textfield(R"item.variable", v__model = "item.content", - @on("keyup.enter.ctrl", "chat_submit!=chat_submit") + ref = "variables", + @on("keyup.enter.ctrl", "chat_submit=true") ) ]) ] @@ -118,7 +123,12 @@ function tab_chat_messages() btngroup(flat = true, class = "absolute bottom-0 right-0", [ btn(flat = true, round = true, size = "xs", - icon = "content_copy", @click("copyToClipboard(index)")) + icon = "content_copy", @click("copyToClipboard(index)")), + ## show only for the last, no confirmation required + btn(flat = true, round = true, size = "xs", + icon = "delete", @iif("index == conv_displayed.length-1"), + @click(:chat_rm_last_msg) + ) ])] ) end