| Title: | Process text with Ollama, retrieve structured results, cache them locally in DuckDB |
|---|---|
| Description: | Process text with Ollama, store results in DuckDB. |
| Authors: | Giorgio Comai [aut, cre, cph] (ORCID: <https://orcid.org/0000-0002-0515-9542>) |
| Maintainer: | Giorgio Comai <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0.9001 |
| Built: | 2026-06-05 07:28:30 UTC |
| Source: | https://github.com/giocomai/quackingllama |
Disable caching for the current session
ql_disable_db()ql_disable_db()
Nothing, used for its side effects.
Other database:
ql_enable_db(),
ql_set_db_options()
ql_disable_db()ql_disable_db()
Enable storing data in a database for the current session
ql_enable_db(db_type = "DuckDB")ql_enable_db(db_type = "DuckDB")
db_type |
Defaults to |
Nothing, used for its side effects.
Other database:
ql_disable_db(),
ql_set_db_options()
ql_enable_db()ql_enable_db()
Generate a response and return the result in a data frame
ql_generate( prompt_df, only_cached = FALSE, host = NULL, messages = NULL, keep_alive = NULL, timeout = NULL, error = c("fail", "warn") )ql_generate( prompt_df, only_cached = FALSE, host = NULL, messages = NULL, keep_alive = NULL, timeout = NULL, error = c("fail", "warn") )
prompt_df |
A data frame with all inputs passed to the LLM, typically
created with |
only_cached |
Defaults to |
host |
The address where the Ollama API can be reached, e.g.
|
messages |
Defaults to NULL. If given, in line with official Ollama documentation: "the messages of the chat, this can be used to keep a chat memory". |
keep_alive |
Defaults to "5m". Controls how long the model will stay loaded into memory following the request. |
timeout |
If not set with |
error |
Defines how errors should be handled, defaults to "fail", i.e.
if an error emerges while querying the LLM, the function stops. If set to
"warn", it sets the response to |
A data frame, including a response column, as well as other information returned by the model.
## Not run: ql_prompt("a haiku") |> ql_generate() ## End(Not run)## Not run: ql_prompt("a haiku") |> ql_generate() ## End(Not run)
Retrieve previously set Ollama API keys typically used for cloud models
ql_get_api_keys(api_keys = NULL)ql_get_api_keys(api_keys = NULL)
api_keys |
Valid Ollama API keys, typically used for cloud models. |
API keys if previously set with ql_set_api_keys(), an empty string
if not set, or the same keys provided as input to this function.
ql_set_api_keys("<your_api_keys_here>") ql_get_api_keys()ql_set_api_keys("<your_api_keys_here>") ql_get_api_keys()
Retrieve
ql_get_db_options(options = c("db", "db_type", "db_folder", "db_filename"))ql_get_db_options(options = c("db", "db_type", "db_folder", "db_filename"))
options |
Available options that |
A list with the selected options.
ql_get_db_options() ## Retrieve only selected option ql_get_db_options("db_type")ql_get_db_options() ## Retrieve only selected option ql_get_db_options("db_type")
Get available models
ql_get_models(host = "http://localhost:11434")ql_get_models(host = "http://localhost:11434")
host |
Defaults to "http://localhost:11434", where locally deployed Ollama usually responds. |
A data frame (a tibble) with details on all locally available models.
## Not run: ql_get_models() ## End(Not run)## Not run: ql_get_models() ## End(Not run)
Get options
ql_get_options( options = c("system", "model", "think", "host", "temperature", "seed", "keep_alive", "timeout"), system = NULL, model = NULL, think = NULL, host = NULL, temperature = NULL, seed = NULL, keep_alive = NULL, timeout = NULL )ql_get_options( options = c("system", "model", "think", "host", "temperature", "seed", "keep_alive", "timeout"), system = NULL, model = NULL, think = NULL, host = NULL, temperature = NULL, seed = NULL, keep_alive = NULL, timeout = NULL )
options |
A character vector used to filter which options should effectively be returned. Defaults to all available. |
A list with all available options (or those selected with
options)
ql_set_options( model = "llama3.2", host = "http://localhost:11434", system = "You are a helpful assistant.", temperature = 0, seed = 42, keep_alive = "5m" ) ql_get_options()ql_set_options( model = "llama3.2", host = "http://localhost:11434", system = "You are a helpful assistant.", temperature = 0, seed = 42, keep_alive = "5m" ) ql_get_options()
Mostly used internally.
ql_hash(prompt_df)ql_hash(prompt_df)
prompt_df |
A data frame with all inputs passed to the LLM, typically
created with |
A tibble, such as those returned by ql_prompt(), but always
including a hash column.
ql_prompt("a haiku", hash = FALSE) |> ql_hash()ql_prompt("a haiku", hash = FALSE) |> ql_hash()
Typically passed to ql_generate().
ql_prompt( prompt, system = NULL, format = NULL, model = NULL, think = NULL, images = NULL, temperature = NULL, seed = NULL, host = NULL, hash = TRUE )ql_prompt( prompt, system = NULL, format = NULL, model = NULL, think = NULL, images = NULL, temperature = NULL, seed = NULL, host = NULL, hash = TRUE )
prompt |
A prompt for the LLM. |
system |
System message to pass to the model. See official documentation for details. For example: "You are a helpful assistant." |
format |
A json schema used to format the response. See README for examples. |
model |
The name of the model, e.g. |
think |
If TRUE, Ollama enables thinking mode for models which support it. For more information, see Ollama's announcement of 'thinking' capabilities. |
temperature |
Numeric value comprised between 0 and 1 passed to the model. When set to 0 and with the same seed, the response to the same prompt is always exactly the same. When closer to one, the response is more variable and creative. Use 0 for consistent responses. Setting this to 0.7 is a common choice for creative or interactive tasks. |
seed |
An integer. When temperature is set to 0 and the seed is constant, the model consistently returns the same response to the same prompt. |
host |
The address where the Ollama API can be reached, e.g.
|
hash |
Defaults to |
For more details and context about each parameter, see https://github.com/ollama/ollama/blob/main/docs/api.md.
A tibble with all main components of a query, to be passed to
ql_generate().
ql_prompt("a haiku")ql_prompt("a haiku")
Read image in order to pass it to multimodal models
ql_read_images(path)ql_read_images(path)
path |
Path to image file. |
A list object of character vectors of base 64 encoded images.
if (interactive()) { library("quackingllama") img_path <- fs::file_temp(ext = "png") download.file( url = "https://ollama.com/public/ollama.png", destfile = img_path ) resp_df <- ql_prompt( prompt = "what is this?", images = img_path, model = "llama3.2-vision" ) |> ql_generate() resp_df resp_df$response }if (interactive()) { library("quackingllama") img_path <- fs::file_temp(ext = "png") download.file( url = "https://ollama.com/public/ollama.png", destfile = img_path ) resp_df <- ql_prompt( prompt = "what is this?", images = img_path, model = "llama3.2-vision" ) |> ql_generate() resp_df resp_df$response }
httr2 request for both generate and chat endpointsCreate httr2 request for both generate and chat endpoints
ql_request( prompt_df, endpoint = "generate", host = NULL, messages = NULL, keep_alive = NULL, timeout = NULL )ql_request( prompt_df, endpoint = "generate", host = NULL, messages = NULL, keep_alive = NULL, timeout = NULL )
endpoint |
Defaults to "generate". Must be either "generate" or "chat". |
host |
The address where the Ollama API can be reached, e.g.
|
messages |
Defaults to NULL. If given, in line with official Ollama documentation: "the messages of the chat, this can be used to keep a chat memory". |
keep_alive |
Defaults to "5m". Controls how long the model will stay loaded into memory following the request. |
timeout |
If not set with |
A httr2 request object.
ql_prompt(prompt = "a haiku") ql_prompt(prompt = "a haiku") |> ql_request() |> httr2::req_dry_run()ql_prompt(prompt = "a haiku") ql_prompt(prompt = "a haiku") |> ql_request() |> httr2::req_dry_run()
Set Ollama API keys typically used for cloud models
ql_set_api_keys(api_keys)ql_set_api_keys(api_keys)
api_keys |
Valid Ollama API keys, typically used for cloud models. |
Invisibly returns API keys, mainly used for its side effects.
ql_set_api_keys("<your_api_keys_here>")ql_set_api_keys("<your_api_keys_here>")
Set options for the local database and enables caching
ql_set_db_options(db_filename = NULL, db_type = "DuckDB", db_folder = ".")ql_set_db_options(db_filename = NULL, db_type = "DuckDB", db_folder = ".")
db_filename |
Defaults |
db_type |
Defaults to |
db_folder |
Defaults to |
Nothing, used for its side effects.
Other database:
ql_disable_db(),
ql_enable_db()
ql_set_db_options(db_filename = "testing_ground")ql_set_db_options(db_filename = "testing_ground")
Set basic options for the current session.
ql_set_options( system = NULL, model = NULL, think = NULL, host = NULL, temperature = NULL, seed = NULL, keep_alive = NULL, timeout = NULL )ql_set_options( system = NULL, model = NULL, think = NULL, host = NULL, temperature = NULL, seed = NULL, keep_alive = NULL, timeout = NULL )
system |
System message to pass to the model. See official documentation for details. For example: "You are a helpful assistant." |
model |
The name of the model, e.g. |
think |
If TRUE, Ollama enables thinking mode for models which support it. For more information, see Ollama's announcement of 'thinking' capabilities. |
host |
The address where the Ollama API can be reached, e.g.
|
temperature |
Numeric value comprised between 0 and 1 passed to the model. When set to 0 and with the same seed, the response to the same prompt is always exactly the same. When closer to one, the response is more variable and creative. Use 0 for consistent responses. Setting this to 0.7 is a common choice for creative or interactive tasks. |
seed |
An integer. When temperature is set to 0 and the seed is constant, the model consistently returns the same response to the same prompt. |
keep_alive |
Defaults to "5m". Controls how long the model will stay loaded into memory following the request. |
timeout |
Time in seconds before the request times out. Defaults to 300 (corresponding to 5 minutes). |
Nothing, used for its side effects. Options can be retrieved with
ql_get_db_options()
ql_set_options( model = "llama3.2", host = "http://localhost:11434", system = "You are a helpful assistant.", temperature = 0, seed = 42 ) ql_get_options()ql_set_options( model = "llama3.2", host = "http://localhost:11434", system = "You are a helpful assistant.", temperature = 0, seed = 42 ) ql_get_options()
Translate strings relying on dedicated models
ql_translate( text, source_language = NULL, source_language_code = NULL, target_language = NULL, target_language_code = NULL, translation_model = "translategemma:4b", temperature = NULL, seed = NULL, host = NULL, hash = TRUE, only_cached = FALSE, keep_alive = NULL, timeout = NULL, error = c("fail", "warn") )ql_translate( text, source_language = NULL, source_language_code = NULL, target_language = NULL, target_language_code = NULL, translation_model = "translategemma:4b", temperature = NULL, seed = NULL, host = NULL, hash = TRUE, only_cached = FALSE, keep_alive = NULL, timeout = NULL, error = c("fail", "warn") )
text |
Text to be translated. |
source_language |
Defaults to |
source_language_code |
Defaults to |
target_language |
Defaults to |
target_language_code |
Defaults to |
translation_model |
Defaults to |
temperature |
Numeric value comprised between 0 and 1 passed to the model. When set to 0 and with the same seed, the response to the same prompt is always exactly the same. When closer to one, the response is more variable and creative. Use 0 for consistent responses. Setting this to 0.7 is a common choice for creative or interactive tasks. |
seed |
An integer. When temperature is set to 0 and the seed is constant, the model consistently returns the same response to the same prompt. |
host |
The address where the Ollama API can be reached, e.g.
|
hash |
Defaults to |
only_cached |
Defaults to |
keep_alive |
Defaults to "5m". Controls how long the model will stay loaded into memory following the request. |
timeout |
If not set with |
error |
Defines how errors should be handled, defaults to "fail", i.e.
if an error emerges while querying the LLM, the function stops. If set to
"warn", it sets the response to |
A data frame such as those returned by ql_generate() with the
translation of the given input text in the response column.
## Not run: translation <- ql_translate( text = "A new collection of open translation models built on Gemma 3, helping people communicate across 55 languages.", target_language = "french" ) translation$response ## End(Not run)## Not run: translation <- ql_translate( text = "A new collection of open translation models built on Gemma 3, helping people communicate across 55 languages.", target_language = "french" ) translation$response ## End(Not run)