model-constructors.Rd
Convenience constructors for Agent objects based on different backends, such as Ollama or OpenAI. Users should call one of these functions to gain access to an LLM. For the local backends, every attempt is made to install the model and even the backend in some cases, so that users can call these functions in a script and expect the script to run anywhere, more or less reproducibly.
ollama_agent(name, pull = NA, server = ollama_server(), ...)
llama_cpp_agent(path, mode = c("chat", "embedding"), alias = NULL,
server_path = NULL, port = 0L, ...)
openai_agent(name = "gpt-4o-mini", ...)
azure_openai_agent(name = "gpt-4o", url = getOption("wizrd_azure_openai_url"),
...)
Name of the model as identified by the backend
Whether to pull the model from Ollama's repository. If NA
(the default), prompt the user, except when the session is
non-interactive, in which case TRUE
is assumed.
OllamaServer object. By default, looks for a server running on
localhost on the default port. If no server is found, attempts to
start the server. Note that if this ends up starting the server, the
server process will be killed when the returned object goes out of
scope. Thus, it is safest to start the server explicitly using
ollama_server
and keep a reference around (or just run
ollama serve
in a shell).
A string pointing to a
llamafile or a
file containing weights in a format compatible with
llama.cpp. This can be a simple path on the file system, a URL or
the name of an Ollama model. If it resembles a URL, the file is
downloaded and cached in a standard place (see
R_user_dir
). If it resembles an Ollama
identifier, the path to the model is automatically resolved, pulling
the model if necessary.
Whether the model is to be used for "chat"
or
"embedding"
. Embedding models are accessed via the llamafile
"v2" web server, while chat models are run through the default
llama.cpp web server.
An alternative, more human-friendly name for the model, instead of
using the path
.
The path to the llama.cpp server binary. Ignored if path
is a
(self-contained) llamafile. Otherwise, defaults to the automatic,
user-local installation of the llamafile utility, downloading and
installing it if necessary and (when interactive) the user approves.
The listening port for the llama.cpp HTTP server. By default, automatically finds an open port.
The URL of the Azure endpoint, typically ending with the hostname.
Model parameters, see LanguageModelParams
.
Using a commercial provider, like via openai_agent
or
azure_openai_agent
, requires some configuration, depending on
the provider:
OPENAI_API_KEY holds the API key
AZURE_OPENAI_API_KEY holds the API
key, and option(wizrd_azure_openai_url=)
sets the
account-specific URL (up to the hostname).
While a llamafile is supposed to work seamlessly across platforms, OS-specific issues may arise. Examples include:
On Linux, issues with binary format registration may result in a wine popup appearing when attempting to run a llamafile.
On Windows, llamafiles over 4GB in size are not supported.
See the llamafile README for workarounds.
An Agent object
These functions rely on an unexported lower level API that will eventually be exported to enable extension to additional backends.