Create a new LLM provider from an ellmer::chat()
object
Source: R/llm_providers.R
llm_provider_ellmer.Rd
This function creates a llm_provider from an ellmer::chat()
object.
This allows the user to use the various LLM providers which are supported
by the 'ellmer' R package, including respective configuration and features.
Please note that this function is experimental. This provider type may show different behavior than other LLM providers, and may not function optimally.
Usage
llm_provider_ellmer(chat, verbose = getOption("tidyprompt.verbose", TRUE))
Arguments
- chat
An
ellmer::chat()
object (e.g.,ellmer::chat_openai()
)- verbose
A logical indicating whether the interaction with the llm_provider should be printed to the console. Default is TRUE
Value
An llm_provider with api_type = "ellmer"
Details
Unlike other LLM provider classes,
LLM provider settings need to be managed in the ellmer::chat()
object
(and not in the $parameters
list). $get_chat()
and $set_chat()
may be used
to manipulate the chat object.
See also
Other llm_provider:
llm_provider-class
,
llm_provider_google_gemini()
,
llm_provider_groq()
,
llm_provider_mistral()
,
llm_provider_ollama()
,
llm_provider_openai()
,
llm_provider_openrouter()
,
llm_provider_xai()
Examples
# Various providers:
ollama <- llm_provider_ollama()
openai <- llm_provider_openai()
openrouter <- llm_provider_openrouter()
mistral <- llm_provider_mistral()
groq <- llm_provider_groq()
xai <- llm_provider_xai()
gemini <- llm_provider_google_gemini()
# From an `ellmer::chat()` (e.g., `ellmer::chat_openai()`, ...):
if (FALSE) { # \dontrun{
ellmer <- llm_provider_ellmer(ellmer::chat_openai())
} # }
# Initialize with settings:
ollama <- llm_provider_ollama(
parameters = list(
model = "llama3.2:3b",
stream = TRUE
),
verbose = TRUE,
url = "http://localhost:11434/api/chat"
)
# Change settings:
ollama$verbose <- FALSE
ollama$parameters$stream <- FALSE
ollama$parameters$model <- "llama3.1:8b"
if (FALSE) { # \dontrun{
# Try a simple chat message with '$complete_chat()':
response <- ollama$complete_chat("Hi!")
response
# $role
# [1] "assistant"
#
# $content
# [1] "How's it going? Is there something I can help you with or would you like
# to chat?"
#
# $http
# Response [http://localhost:11434/api/chat]
# Date: 2024-11-18 14:21
# Status: 200
# Content-Type: application/json; charset=utf-8
# Size: 375 B
# Use with send_prompt():
"Hi" |>
send_prompt(ollama)
# [1] "How's your day going so far? Is there something I can help you with or
# would you like to chat?"
} # }