Skip to content

Commit

Permalink
Merge pull request #78 from JamesHWade/feat/better-save-interaction
Browse files Browse the repository at this point in the history
Feat/better save interaction
  • Loading branch information
JamesHWade authored Feb 14, 2024
2 parents f5ee5c2 + b58dc1d commit 1e6fe36
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: gpttools
Title: Extensions and Tools for gptstudio
Version: 0.0.8.9012
Version: 0.0.8.9013
Authors@R:
person("James", "Wade", , "github@jameshwade.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9740-1905"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(gpttools_index_all_scraped_data)
export(ingest_pdf)
export(insert_text)
export(install_sentence_transformers)
export(launch_settings)
export(list_index)
export(load_index)
export(prep_data_prompt)
Expand Down
6 changes: 1 addition & 5 deletions R/history.R
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,7 @@ chat_with_context <- function(query,
content =
glue(
"You are a helpful chat bot that answers questions based on
on the context provided by the user. If the user does not
provide context and you need context to respond correctly,
answer the quest but first say \"I am not able to answer
that question with the context you gave me, but here is my
best but here is my best answer."
the context provided by the user."
)
)
)
Expand Down
31 changes: 26 additions & 5 deletions inst/retriever/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,6 @@ api_services <-

ui <- page_fillable(
useWaiter(),
waiterOnBusy(
html = spin_3circles(),
color = transparent(0.5)
),
shinyjs::useShinyjs(),
window_height_ui("height"),
theme = bs_theme(bootswatch = "litera") |>
Expand Down Expand Up @@ -317,6 +313,20 @@ server <- function(input, output, session) {
))
observe({
toggle_popover("settings", show = FALSE)
modalDialog(
"Would you like to save your settings and close the app?",
title = "Save Settings",
footer = tagList(
modalButton("Cancel"),
actionButton("ok", "OK")
),
size = "m",
easyClose = FALSE,
fade = TRUE
) |> showModal()
}) |> bindEvent(input$save_settings)

observe({
save_user_config(
service = input$service,
model = input$model,
Expand All @@ -332,8 +342,17 @@ server <- function(input, output, session) {
add_context = input$add_context,
persist = TRUE
)
}) |> bindEvent(input$save_settings)
removeModal()
}) |> bindEvent(input$ok)

observe({
if (rlang::is_false(input$stream) ||
input$service %in% c("google", "azure_openai", "huggingface")) {
waiter_show(
html = spin_3circles(),
color = transparent(0.5)
)
}
interim <- chat_with_context(
query = input$chat_input,
service = input$service,
Expand All @@ -355,6 +374,8 @@ server <- function(input, output, session) {
)
new_response <- interim[[3]]

waiter_hide()

if (is.character(interim[[2]])) {
if (length(r$context_links) == 0) {
r$context_links <- "No context used so far."
Expand Down
19 changes: 17 additions & 2 deletions inst/settings/app.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,20 @@ server <- function(input, output, session) {
)

observe({
toggle_popover("settings", show = FALSE)
modalDialog(
"Would you like to save your settings and close the app?",
title = "Save Settings",
footer = tagList(
modalButton("Cancel"),
actionButton("ok", "OK")
),
size = "m",
easyClose = FALSE,
fade = TRUE
) |> showModal()
}) |> bindEvent(input$save_settings)

observe({
save_user_config(
service = input$service,
model = input$model,
Expand All @@ -179,7 +192,9 @@ server <- function(input, output, session) {
add_context = input$add_context,
persist = TRUE
)
}) |> bindEvent(input$save_settings)
removeModal()
shiny::stopApp()
}) |> bindEvent(input$ok)
}

# Run the app
Expand Down
14 changes: 14 additions & 0 deletions man/launch_settings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e6fe36

Please sign in to comment.