|
1 | 1 | #' Summarise document using LangChain and ChatGPT |
2 | 2 | #' |
3 | | -#' This function is a R wrapper of `chatgpt_chaindoc.py`, a python function aimed |
4 | | -#' to summarise large text documents using LangChain and ChatGPT. |
| 3 | +#' This function is a R wrapper of `chatgpt_chaindoc.py`, a python script function |
| 4 | +#' aimed to elaborate large text documents using LangChain and ChatGPT. |
| 5 | +#' `chatgpt_chaindoc.py` uses the refine chain method to elaborate the text |
| 6 | +#' (see \url{https://langchain.readthedocs.io/en/latest/modules/indexes/chain_examples/summarize.html#the-refine-chain} for details). |
5 | 7 | #' |
6 | 8 | #' @param document_path The path of the txt document to summarise. |
7 | 9 | #' @param openaikey The OpenAI key token. |
8 | 10 | #' @param engine ChatGPT model (see \url{https://platform.openai.com/docs/models}). |
9 | | -#' @param temperature Level of randomness or "creativity" in the generated text (see \url{https://platform.openai.com/docs/api-reference/completions/create}) |
| 11 | +#' @param temperature Level of randomness or "creativity" in the generated text (see \url{https://platform.openai.com/docs/api-reference/completions/create}). |
| 12 | +#' @param refine_text A text useful to refine the original prompt (see \url{https://langchain.readthedocs.io/en/latest/modules/indexes/chain_examples/summarize.html#the-refine-chain} for details). |
10 | 13 | #' |
11 | 14 | #' @return A summarised text. |
12 | 15 | #' @export |
13 | | -#' |
14 | | - |
15 | | -summarise_chatgpt_wrapper <- function(document_path, openaikey, engine, temperature) { |
| 16 | +#' @examples |
| 17 | +#' \dontrun{ |
| 18 | +#' output <- |
| 19 | +#' summarise_chatgpt_wrapper( |
| 20 | +#' document_path = "inst/docs_dataverse/5636634.txt", |
| 21 | +#' openaikey = OPENAI_KEY, |
| 22 | +#' engine = "gpt-3.5-turbo", |
| 23 | +#' temperature = 0.7, |
| 24 | +#' refine_text = pars$openai$refine_prompts$p1 |
| 25 | +#' ) |
| 26 | +#' cat(output$output_text) |
| 27 | +#' } |
| 28 | +summarise_chatgpt_wrapper <- function(document_path, openaikey, engine, temperature, refine_text) { |
16 | 29 | chatgpt_chain_py <- reticulate::import("chatgpt_chaindoc") |
17 | 30 | py_function <- chatgpt_chain_py$summarize_document |
18 | | - result <- py_function(document_path, openaikey, engine, temperature) |
| 31 | + result <- py_function(document_path, openaikey, engine, temperature, refine_text) |
19 | 32 | return(result) |
20 | 33 | } |
0 commit comments