From ef06ca587f52d9ec18a12225092e90d5420ad938 Mon Sep 17 00:00:00 2001 From: Hause Lin Date: Sat, 24 Aug 2024 23:36:29 -0400 Subject: [PATCH] Update readme and citation --- NEWS.md | 1 + README.Rmd | 36 +++++++++++++++++++++++++++++++++ README.md | 40 +++++++++++++++++++++++++++++++++++++ inst/CITATION | 18 +++++++++++++++++ tests/testthat/test-utils.R | 21 +++++++++++++++++++ 5 files changed, 116 insertions(+) create mode 100644 inst/CITATION diff --git a/NEWS.md b/NEWS.md index 380a05b..19ed95b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ - Add `encode_images_in_messages()` to encode images in messages for `chat()` function. - Add `create_messages()` to create messages easily. - Helper functions for managing messages accept `...` parameter to pass additional options. +- Update README and docs to reflect changes. # ollamar 1.2.0 diff --git a/README.Rmd b/README.Rmd index 0ae4900..b03176d 100644 --- a/README.Rmd +++ b/README.Rmd @@ -29,6 +29,24 @@ See [Ollama's Github page](https://github.com/ollama/ollama) for more informatio > Note: You should have at least 8 GB of RAM available to run the 7B models, 16 GB to run the 13B models, and 32 GB to run the 33B models. +## Citing `ollamar` + +If you use this library, please cite [this paper](https://doi.org/10.31234/osf.io/zsrg5) using the following BibTeX entry: + +```bibtex +@article{Lin2024Aug, + author = {Lin, Hause and Safi, Tawab}, + title = {{ollamar: An R package for running large language models}}, + journal = {PsyArXiv}, + year = {2024}, + month = aug, + urldate = {2024-08-24}, + publisher = {OSF}, + doi = {10.31234/osf.io/zsrg5}, + url = {https://doi.org/10.31234/osf.io/zsrg5} +} +``` + ## Ollama R versus Ollama Python/JavaScript This library has been inspired by the official [Ollama Python](https://github.com/ollama/ollama-python) and [Ollama JavaScript](https://github.com/ollama/ollama-js) libraries. If you're coming from Python or JavaScript, you should feel right at home. Alternatively, if you plan to use Ollama with Python or JavaScript, using this R library will help you understand the Python/JavaScript libraries as well. @@ -295,6 +313,24 @@ messages <- create_messages( ) ``` +You can convert `data.frame`, `tibble` or `data.table` objects to `list()` of messages and vice versa with functions from base R or other popular libraries. + +```{r eval=FALSE} +# create a list of messages +messages <- create_messages( + create_message("You're a knowledgeable tour guide.", role = "system"), + create_message("What is the capital of Australia?") +) + +# convert to dataframe +df <- dplyr::bind_rows(messages) # with dplyr library +df <- data.table::rbindlist(messages) # with data.table library + +# convert dataframe to list with apply, purrr functions +apply(df, 1, as.list) # convert each row to a list with base R apply +purrr::transpose(df) # with purrr library +``` + ## Advanced usage ### Parallel requests diff --git a/README.md b/README.md index 0c09e9a..2fb9ac8 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,26 @@ for details)](https://github.com/ollama/ollama/blob/main/docs/api.md). > Note: You should have at least 8 GB of RAM available to run the 7B > models, 16 GB to run the 13B models, and 32 GB to run the 33B models. +## Citing `ollamar` + +If you use this library, please cite [this +paper](https://doi.org/10.31234/osf.io/zsrg5) using the following BibTeX +entry: + +``` bibtex +@article{Lin2024Aug, + author = {Lin, Hause and Safi, Tawab}, + title = {{ollamar: An R package for running large language models}}, + journal = {PsyArXiv}, + year = {2024}, + month = aug, + urldate = {2024-08-24}, + publisher = {OSF}, + doi = {10.31234/osf.io/zsrg5}, + url = {https://doi.org/10.31234/osf.io/zsrg5} +} +``` + ## Ollama R versus Ollama Python/JavaScript This library has been inspired by the official [Ollama @@ -342,6 +362,26 @@ messages <- create_messages( ) ``` +You can convert `data.frame`, `tibble` or `data.table` objects to +`list()` of messages and vice versa with functions from base R or other +popular libraries. + +``` r +# create a list of messages +messages <- create_messages( + create_message("You're a knowledgeable tour guide.", role = "system"), + create_message("What is the capital of Australia?") +) + +# convert to dataframe +df <- dplyr::bind_rows(messages) # with dplyr library +df <- data.table::rbindlist(messages) # with data.table library + +# convert dataframe to list with apply, purrr functions +apply(df, 1, as.list) # convert each row to a list with base R apply +purrr::transpose(df) # with purrr library +``` + ## Advanced usage ### Parallel requests diff --git a/inst/CITATION b/inst/CITATION new file mode 100644 index 0000000..e4e6a25 --- /dev/null +++ b/inst/CITATION @@ -0,0 +1,18 @@ +citHeader("To cite ollamar in publications use:") + +citEntry( + entry = "Article", + title = "ollamar: An R package for running large language models", + author = "Lin Hause and Tawab Safi", + journal = "PsyArXiv", + year = "2024", + month = "aug", + publisher = "OSF", + doi = "10.31234/osf.io/zsrg5", + url = "https://doi.org/10.31234/osf.io/zsrg5", + textVersion = paste0( + "Lin, H., & Safi, T. (2024). ", + "ollamar: An R package for running large language models. ", + "PsyArXiv. https://doi.org/10.31234/osf.io/zsrg5" + ) +) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index b248688..5d044af 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -131,4 +131,25 @@ test_that("copy function works with basic input", { expect_true(length(messages4) == 4) expect_true(messages4[[2]]$new_inserted == "NEW_INS") + + + + # # convert from list to data.frame + # messages1 <- create_messages( + # list(role = "system", content = "be nice"), + # list(role = "user", content = "hello"), + # list(role = "assistant", content = "hi") + # ) + # expect_true(nrow(dplyr::bind_rows(messages1)) == 3) + # expect_true(ncol(dplyr::bind_rows(messages1)) == 2) + # expect_true(nrow(data.table::rbindlist(messages1)) == 3) + # expect_true(ncol(data.table::rbindlist(messages1)) == 2) + # + # d0 <- data.table::rbindlist(messages1) + # # convert from data.frame to list + # expect_equal(apply(d0, 1, as.list), messages1) + # expect_equal(purrr::transpose(d0), messages1) + # expect_equal(lapply(1:nrow(d0), function(i) as.list(d0[i, ])), messages1) + + })