View source: R/provider-openai-compatible.R
| chat_openai_compatible | R Documentation |
This function is for use with OpenAI-compatible APIs, also known as the
chat completions API. If you want to use OpenAI itself, we recommend
chat_openai(), which uses the newer responses API.
Many providers offer OpenAI-compatible APIs, including:
Ollama for local models
vLLM for self-hosted models
Various cloud providers with OpenAI-compatible endpoints
chat_openai_compatible(
base_url,
name = "OpenAI-compatible",
system_prompt = NULL,
api_key = NULL,
credentials = NULL,
model = NULL,
params = NULL,
api_args = list(),
api_headers = character(),
preserve_thinking = FALSE,
echo = c("none", "output", "all")
)
base_url |
The base URL to the endpoint. This parameter is required since there is no default for OpenAI-compatible APIs. |
name |
The name of the provider; this is shown in |
system_prompt |
A system prompt to set the behavior of the assistant. |
api_key |
|
credentials |
Credentials to use for authentication. If not provided,
will attempt to use the |
model |
The model to use for chat. No default; depends on your provider. |
params |
Common model parameters, usually created by |
api_args |
Named list of arbitrary extra arguments appended to the body
of every chat API call. Combined with the body object generated by ellmer
with |
api_headers |
Named character vector of arbitrary extra headers appended to every chat API call. |
preserve_thinking |
If |
echo |
One of the following options:
Note this only affects the |
A Chat object.
Other chatbots:
chat_anthropic(),
chat_aws_bedrock(),
chat_azure_openai(),
chat_cloudflare(),
chat_databricks(),
chat_deepseek(),
chat_github(),
chat_google_gemini(),
chat_groq(),
chat_huggingface(),
chat_lmstudio(),
chat_mistral(),
chat_ollama(),
chat_openai(),
chat_openrouter(),
chat_perplexity(),
chat_portkey(),
chat_posit()
## Not run:
# Example with Ollama (requires Ollama running locally)
chat <- chat_openai_compatible(
base_url = "http://localhost:11434/v1",
model = "llama2"
)
chat$chat("What is the difference between a tibble and a data frame?")
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.