Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ Imports:
methods,
waiter,
igraph,
httr
httr,
shinyWidgets
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
78 changes: 78 additions & 0 deletions R/project_visualiser.R
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,60 @@ 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",
"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(),
Expand Down Expand Up @@ -897,6 +949,27 @@ define_app_ui <- function(network_title) {
")
),
# Define network plot title/subtitle divs
shiny::fluidRow(align = 'center',
shinyWidgets::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) {
shiny::HTML(paste(
shiny::tags$img(src=flagUrl,
width=20,
height=15),
language
))
},
SIMPLIFY = FALSE,
USE.NAMES = FALSE)))
),
shiny::HTML(
paste0(
'<div id="titlehtmlwidget-b9361e0bc6cd12c5d6d9" style="font-family: ',
Expand Down Expand Up @@ -924,6 +997,7 @@ define_app_ui <- function(network_title) {
' to load its contents into a new browser tab.</div>'
)
),
shiny::br(),
# Define main panel
shiny::fluidRow(
shiny::column(
Expand Down Expand Up @@ -962,7 +1036,9 @@ define_app_ui <- function(network_title) {
#'
#' @return Shiny app server logic
define_app_server <- function(network_object, project_path) {

function(input, output, session) {

# Keep track of the current tab's output ID
currentTabId <- shiny::reactiveVal(NULL)

Expand Down Expand Up @@ -1020,7 +1096,9 @@ define_app_server <- function(network_object, project_path) {
currentTabId(tab_name)

# Query AI:
print(input$language)
ai_response <- summarise_function_with_LLM(
text_language = input$language,
foo_name = function_name,
llm_api_url = Sys.getenv("LLM_API_URL"),
llm_api_key = Sys.getenv("LLM_API_KEY")
Expand Down
22 changes: 15 additions & 7 deletions R/summarise_function_with_LLM.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
#' @export
#' @examples
#' \dontrun{
#' summarise_function_with_LLM("calculate_costs")
#' summarise_function_with_LLM("check_init")
#' }
#'
summarise_function_with_LLM <- function(foo_name,
text_language = "English",
llm_api_url = Sys.getenv("LLM_API_URL"),
llm_api_key = Sys.getenv("LLM_API_KEY")){
# get the function data list (function arguments and body)
Expand All @@ -27,6 +28,7 @@ summarise_function_with_LLM <- function(foo_name,
foo_body = l_foo_data[["body"]],
foo_title = l_foo_data[["title"]],
foo_desc = l_foo_data[["desc"]],
text_language = text_language,
model_name = "gpt-3.5-turbo-0125",
llm_api_url = llm_api_url,
llm_api_key = llm_api_key
Expand Down Expand Up @@ -114,6 +116,7 @@ summarise_function_from_arguments_and_body <- function(foo_name,
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")) {
Expand All @@ -122,7 +125,8 @@ summarise_function_from_arguments_and_body <- function(foo_name,
foo_body = foo_body,
foo_name = foo_name,
foo_title = foo_title,
foo_desc = foo_desc)
foo_desc = foo_desc,
text_language = text_language)

# POST BODY
body <- list(model = model_name,
Expand Down Expand Up @@ -157,13 +161,15 @@ summarise_function_from_arguments_and_body <- function(foo_name,
#' @param foo_name function name
#' @param foo_title function title
#' @param foo_desc function description
#' @param text_language the language to return the summary in
#'
#' @return a single prompt in the form of a character string
#' @export
#'
#' @examples
#' \dontrun{
#' create_prompt(
#' text_language = "Spanish",
#' foo_arguments = LETTERS[1:3],
#' foo_body = "D <- A+B+C; return(D)",
#' foo_name = "calculate_QALYs",
Expand All @@ -174,15 +180,17 @@ create_prompt <- function(foo_arguments,
foo_body,
foo_name,
foo_desc,
foo_title){
foo_title,
text_language = "English"){

prompt <- paste0(
collapse = " ",
c(
"I am reviewing some R code. I have a single function called '",
paste0(foo_name),
paste0("' with a title, description, arguments and a body. Summarise what the function does in two paragraphs,"),
paste0("returning your output as HTML code. The Roxygen title and description is as follows"),
paste0("I am reviewing some R code. I have a single function called"),
paste0("'", foo_name, "'"),
paste0("with a title, description, arguments and a body. Summarise what the function does in two paragraphs,"),
paste0("in the language '", text_language, "' using the fewest tokens possible."),
paste0("The Roxygen title and description is as follows."),
paste0("title: '", foo_title, "';"),
paste0("description: '", foo_desc, "';"),
paste0("The function arguments are: "),
Expand Down
12 changes: 11 additions & 1 deletion man/create_prompt.Rd

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

3 changes: 3 additions & 0 deletions man/summarise_function_from_arguments_and_body.Rd

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

5 changes: 4 additions & 1 deletion man/summarise_function_with_LLM.Rd

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