Skip to content

Commit

Permalink
Update readme and citation
Browse files Browse the repository at this point in the history
  • Loading branch information
hauselin committed Aug 25, 2024
1 parent 48f96c3 commit ef06ca5
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
36 changes: 36 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions inst/CITATION
Original file line number Diff line number Diff line change
@@ -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"
)
)
21 changes: 21 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)


})

0 comments on commit ef06ca5

Please sign in to comment.