diff --git a/articles/ollamar.html b/articles/ollamar.html index e12f625..70cc2d7 100644 --- a/articles/ollamar.html +++ b/articles/ollamar.html @@ -469,13 +469,39 @@
The chat()
and generate()
functions support
+structured
+outputs, making it possible to constrain a model’s output to a
+specified format defined by a JSON schema (R list).
+# define a JSON schema as a list to constrain a model's output
+format <- list(
+ type = "object",
+ properties = list(
+ name = list(type = "string"),
+ capital = list(type = "string"),
+ languages = list(type = "array",
+ items = list(type = "string")
+ )
+ ),
+ required = list("name", "capital", "languages")
+ )
+
+generate("llama3.1", "tell me about Canada", output = "structured", format = format)
+
+msg <- create_message("tell me about Canada")
+chat("llama3.1", msg, format = format, output = "structured")
For the generate()
and chat()
endpoints/functions, you can specify output = 'req'
in the
function so the functions return httr2_request
objects
instead of httr2_response
objects.
+prompt <- "Tell me a 10-word story" req <- generate("llama3.1", prompt, output = "req") # returns a httr2_request object
When you have multiple
httr2_request
objects in a list, @@ -483,7 +509,7 @@Parallel requests
httr2
documentation for details. -+library(httr2) prompt <- "Tell me a 5-word story" @@ -501,7 +527,7 @@
Parallel requests# [5] "She found the diamond ring."
Example sentiment analysis with parallel requests with
-generate()
function+library(httr2) library(glue) library(dplyr) @@ -524,7 +550,7 @@
Parallel requests# [3] "'neutral' translates to... 'other'."
Example sentiment analysis with parallel requests with
-chat()
function+library(httr2) library(dplyr) diff --git a/index.html b/index.html index 2c21d57..eca372a 100644 --- a/index.html +++ b/index.html @@ -76,7 +76,7 @@
The Ollama R library is the easiest way to integrate R with Ollama, which lets you run language models locally on your own machine.
The library also makes it easy to work with data structures (e.g., conversational/chat histories) that are standard for different LLMs (such as those provided by OpenAI and Anthropic). It also lets you specify different output formats (e.g., dataframes, text/vector, lists) that best suit your need, allowing easy integration with other libraries/tools and parallelization via the
httr2
library.To use this R library, ensure the Ollama app is installed. Ollama can use GPUs for accelerating LLM inference. See Ollama GPU documentation for more information.
-See Ollama’s Github page for more information. This library uses the Ollama REST API (see documentation for details) and has been tested on Ollama v0.1.30 and above. It was last tested on Ollama v0.3.10.
+See Ollama’s Github page for more information. This library uses the Ollama REST API (see documentation for details) and was last tested on v0.5.4.
diff --git a/news/index.html b/news/index.html index c6bb7d3..66cf350 100644 --- a/news/index.html +++ b/news/index.html @@ -40,7 +40,14 @@ +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.
- +
+generate()
andchat()
support structured output viaformat
parameter.- +
+test_connection()
returns boolean instead ofhttr2
object. #29- +
+chat()
supports tool calling viatools
parameter. Addedget_tool_calls()
helper function to process tools. #30- Simplify README and add Get started vignette with more examples.
+ollamar 1.2.1
CRAN release: 2024-08-25
- diff --git a/pkgdown.yml b/pkgdown.yml index 7f87cd4..eea6e9f 100644 --- a/pkgdown.yml +++ b/pkgdown.yml @@ -3,7 +3,7 @@ pkgdown: 2.1.1 pkgdown_sha: ~ articles: ollamar: ollamar.html -last_built: 2024-12-26T03:41Z +last_built: 2024-12-26T04:50Z urls: reference: https://hauselin.github.io/ollama-r/reference article: https://hauselin.github.io/ollama-r/articles diff --git a/reference/chat.html b/reference/chat.html index 7d011f5..9e8c511 100644 --- a/reference/chat.html +++ b/reference/chat.html @@ -50,8 +50,9 @@
Usage messages, tools = list(), stream = FALSE, + format = list(), keep_alive = "5m", - output = c("resp", "jsonlist", "raw", "df", "text", "req", "tools"), + output = c("resp", "jsonlist", "raw", "df", "text", "req", "tools", "structured"), endpoint = "/api/chat", host = NULL, ... @@ -78,12 +79,16 @@
Argumentsformat +
- + +
Format to return a response in. Format can be json/list (structured response).
- keep_alive
The duration to keep the connection alive. Default is "5m".
- output
-- +
The output format. Default is "resp". Other options are "jsonlist", "raw", "df", "text", "req" (httr2_request object), "tools" (tool calling)
The output format. Default is "resp". Other options are "jsonlist", "raw", "df", "text", "req" (httr2_request object), "tools" (tool calling), "structured" (structured output)
- endpoint
diff --git a/reference/generate.html b/reference/generate.html index 0e38769..b334ae4 100644 --- a/reference/generate.html +++ b/reference/generate.html @@ -50,13 +50,14 @@Usage prompt, suffix = "", images = "", + format = list(), system = "", template = "", context = list(), stream = FALSE, raw = FALSE, keep_alive = "5m", - output = c("resp", "jsonlist", "raw", "df", "text", "req"), + output = c("resp", "jsonlist", "raw", "df", "text", "req", "structured"), endpoint = "/api/generate", host = NULL, ... @@ -83,6 +84,10 @@
Arguments +
- format
+- + +
Format to return a response in. Format can be json/list (structured response).
- system
- diff --git a/reference/resp_process.html b/reference/resp_process.html index 509fd05..d42450e 100644 --- a/reference/resp_process.html +++ b/reference/resp_process.html @@ -60,7 +60,7 @@
A character string of the system prompt (overrides what is defined in the Modelfile). Default is "".
Argumentsoutput -
- +
The output format. Default is "df". Other options are "jsonlist", "raw", "resp" (httr2 response object), "text", "tools" (tool_calls)
The output format. Default is "df". Other options are "jsonlist", "raw", "resp" (httr2 response object), "text", "tools" (tool_calls), "structured" (structured output).