From 869d5cea88883e97bcb245071ed17e6758d43835 Mon Sep 17 00:00:00 2001 From: RobertASmith Date: Tue, 7 May 2024 16:47:37 +0100 Subject: [PATCH 1/2] Adding LLM summarises in different languages --- R/project_visualiser.R | 76 +++++++++++++++++++++++++++++++++ R/summarise_function_with_LLM.R | 22 +++++++--- 2 files changed, 91 insertions(+), 7 deletions(-) diff --git a/R/project_visualiser.R b/R/project_visualiser.R index 02bf3e8..bef2294 100644 --- a/R/project_visualiser.R +++ b/R/project_visualiser.R @@ -743,6 +743,56 @@ make_closable_tab <- function( #' @return Shiny app user interface define_app_ui <- function(network_title) { + languages <- c("English", "Spanish", "Mandarin", "Hindi", "Arabic", + "Bengali", "Portuguese", "Russian", "Japanese", "German", + "Javanese", "Punjabi", "Wu", "Telugu", "Marathi", + "Vietnamese", "Korean", "French", "Turkish", "Tamil", + "Bulgarian", "Croatian", "Czech", "Danish", "Dutch", + "Estonian", "Finnish", "Greek", "Hungarian", "Irish", + "Italian", "Latvian", "Lithuanian", "Maltese", "Polish", + "Romanian", "Slovak", "Slovenian", "Swedish") + + flags <- c("https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gb.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/es.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/cn.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/in.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/sa.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/bd.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/pt.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/ru.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/jp.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/de.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/id.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/in.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/us.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/in.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/in.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/vn.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/kr.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/fr.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/tr.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/in.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/bg.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/hr.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/cz.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/dk.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/nl.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/ee.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/fi.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/gr.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/hu.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/ie.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/it.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/lv.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/lt.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/mt.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/pl.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/ro.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/sk.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/si.svg", + "https://cdn.rawgit.com/lipis/flag-icon-css/master/flags/4x3/se.svg") + + shiny::fluidPage( # Initialize shinyjs and waiter shinyjs::useShinyjs(), @@ -897,6 +947,27 @@ define_app_ui <- function(network_title) { ") ), # Define network plot title/subtitle divs + shiny::fluidRow(align = 'center', + pickerInput(inputId = "language", + label = "Language:", + choices = languages, + selected = "English", + width = "fit", + options = list( + `live-search` = TRUE), + choicesOpt = list(content = + mapply(languages, flags, + FUN = function(language, flagUrl) { + HTML(paste( + tags$img(src=flagUrl, + width=20, + height=15), + language + )) + }, + SIMPLIFY = FALSE, + USE.NAMES = FALSE))) + ), shiny::HTML( paste0( '
Date: Tue, 7 May 2024 17:00:39 +0100 Subject: [PATCH 2/2] fixing check fails --- DESCRIPTION | 3 ++- NAMESPACE | 1 + R/project_visualiser.R | 10 ++++++---- man/create_prompt.Rd | 12 +++++++++++- man/summarise_function_from_arguments_and_body.Rd | 3 +++ man/summarise_function_with_LLM.Rd | 5 ++++- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3591eae..c6d1921 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -38,4 +38,5 @@ Imports: methods, waiter, igraph, - httr + httr, + shinyWidgets diff --git a/NAMESPACE b/NAMESPACE index 51b2546..279ec4d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -50,6 +50,7 @@ importFrom(officer,body_add_par) importFrom(officer,read_docx) importFrom(roxygen2,parse_file) importFrom(rstudioapi,navigateToFile) +importFrom(shinyWidgets,pickerInput) importFrom(stats,na.omit) importFrom(stringr,str_locate_all) importFrom(stringr,str_replace) diff --git a/R/project_visualiser.R b/R/project_visualiser.R index bef2294..f3edb10 100644 --- a/R/project_visualiser.R +++ b/R/project_visualiser.R @@ -741,6 +741,8 @@ make_closable_tab <- function( #' @param network_title Character string representing the title of the network to be displayed above the network. #' #' @return Shiny app user interface +#' +#' @importFrom shinyWidgets pickerInput define_app_ui <- function(network_title) { languages <- c("English", "Spanish", "Mandarin", "Hindi", "Arabic", @@ -948,7 +950,7 @@ define_app_ui <- function(network_title) { ), # Define network plot title/subtitle divs shiny::fluidRow(align = 'center', - pickerInput(inputId = "language", + shinyWidgets::pickerInput(inputId = "language", label = "Language:", choices = languages, selected = "English", @@ -958,8 +960,8 @@ define_app_ui <- function(network_title) { choicesOpt = list(content = mapply(languages, flags, FUN = function(language, flagUrl) { - HTML(paste( - tags$img(src=flagUrl, + shiny::HTML(paste( + shiny::tags$img(src=flagUrl, width=20, height=15), language @@ -995,7 +997,7 @@ define_app_ui <- function(network_title) { ' to load its contents into a new browser tab.
' ) ), - br(), + shiny::br(), # Define main panel shiny::fluidRow( shiny::column( diff --git a/man/create_prompt.Rd b/man/create_prompt.Rd index da61b60..ea7a12a 100644 --- a/man/create_prompt.Rd +++ b/man/create_prompt.Rd @@ -4,7 +4,14 @@ \alias{create_prompt} \title{Create a prompt for a LLM} \usage{ -create_prompt(foo_arguments, foo_body, foo_name, foo_desc, foo_title) +create_prompt( + foo_arguments, + foo_body, + foo_name, + foo_desc, + foo_title, + text_language = "English" +) } \arguments{ \item{foo_arguments}{the arguments to the function} @@ -16,6 +23,8 @@ create_prompt(foo_arguments, foo_body, foo_name, foo_desc, foo_title) \item{foo_desc}{function description} \item{foo_title}{function title} + +\item{text_language}{the language to return the summary in} } \value{ a single prompt in the form of a character string @@ -27,6 +36,7 @@ for the LLM. \examples{ \dontrun{ create_prompt( +text_language = "Spanish", foo_arguments = LETTERS[1:3], foo_body = "D <- A+B+C; return(D)", foo_name = "calculate_QALYs", diff --git a/man/summarise_function_from_arguments_and_body.Rd b/man/summarise_function_from_arguments_and_body.Rd index b0528e1..67aa566 100644 --- a/man/summarise_function_from_arguments_and_body.Rd +++ b/man/summarise_function_from_arguments_and_body.Rd @@ -10,6 +10,7 @@ summarise_function_from_arguments_and_body( foo_body, foo_title, foo_desc, + text_language = "English", model_name = "gpt-3.5-turbo-0125", llm_api_url = Sys.getenv("LLM_API_URL"), llm_api_key = Sys.getenv("LLM_API_KEY") @@ -26,6 +27,8 @@ summarise_function_from_arguments_and_body( \item{foo_desc}{function description} +\item{text_language}{the language to return the summary in} + \item{model_name}{name of the LLM to use (default gpt-3.5-turbo-0125)} \item{llm_api_url}{url to the API for the LLM} diff --git a/man/summarise_function_with_LLM.Rd b/man/summarise_function_with_LLM.Rd index b475d69..e2e97e5 100644 --- a/man/summarise_function_with_LLM.Rd +++ b/man/summarise_function_with_LLM.Rd @@ -6,6 +6,7 @@ \usage{ summarise_function_with_LLM( foo_name, + text_language = "English", llm_api_url = Sys.getenv("LLM_API_URL"), llm_api_key = Sys.getenv("LLM_API_KEY") ) @@ -13,6 +14,8 @@ summarise_function_with_LLM( \arguments{ \item{foo_name}{function name} +\item{text_language}{the language to return the summary in} + \item{llm_api_url}{url to the API for the LLM} \item{llm_api_key}{key for the API for the LLM} @@ -25,7 +28,7 @@ This function summarizes another function using a Language Model. } \examples{ \dontrun{ -summarise_function_with_LLM("calculate_costs") +summarise_function_with_LLM("check_init") } }