-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
245 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#' Generate Embeddings | ||
#' | ||
#' @param text text vector to generate embeddings for. | ||
#' @inheritParams query | ||
#' | ||
#' @return a tibble with embeddings. | ||
#' @export | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' embed_text(c("Here is an article about llamas...", | ||
#' "R is a language and environment for statistical computing and graphics.")) | ||
#' } | ||
embed_text <- function(text, | ||
model = NULL, | ||
server = NULL) { | ||
|
||
if (is.null(model)) model <- getOption("rollama_model", default = "llama2") | ||
if (is.null(server)) server <- getOption("rollama_server", default = "http://localhost:11434") | ||
spinner <- getOption("rollama_spinner", default = interactive()) | ||
|
||
purrr::map(seq_along(text), function(i) { | ||
req_data <- list(model = model, | ||
prompt = text[i], | ||
stream = FALSE) | ||
|
||
if (spinner) { | ||
cli::cli_progress_step("{cli::pb_spin} {model} is embedding text {i}", ) | ||
rp <- callr::r_bg(make_req, | ||
args = list(req_data = req_data, | ||
server = server, | ||
endpoint = "/api/embeddings"), | ||
package = TRUE) | ||
while (rp$is_alive()) { | ||
cli::cli_progress_update() | ||
Sys.sleep(2 / 100) | ||
} | ||
resp <- rp$get_result() | ||
cli::cli_progress_done() | ||
} else { | ||
resp <- make_req(req_data, server, "/api/embeddings") | ||
} | ||
|
||
if (!is.null(resp$error)) { | ||
if (grepl("model.+not found, try pulling it first", resp$error)) { | ||
resp$error <- paste(resp$error, "with {.code pull_model(\"{model}\")}") | ||
} | ||
cli::cli_abort(resp$error) | ||
} | ||
names(resp$embedding) <- paste0("dim_", seq_along(resp$embedding)) | ||
tibble::as_tibble(resp$embedding) | ||
}) |> | ||
dplyr::bind_rows() | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM llama2 | ||
# sets the temperature to 1 [higher is more creative, lower is more coherent] | ||
PARAMETER temperature 1 | ||
# sets the context window size to 4096, this controls how many tokens the LLM can use as context to generate the next token | ||
PARAMETER num_ctx 4096 | ||
|
||
# sets a custom system message to specify the behavior of the chat assistant | ||
SYSTEM You are Mario from super mario bros, acting as an assistant. Blubb |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.