Skip to contents

POST a chat-completion request to an OpenAI-compatible endpoint

Usage

morie_llm_request_completion(
  base_url,
  model,
  messages,
  api_key = NULL,
  timeout = 120
)

Arguments

base_url

Provider base URL.

model

Model identifier.

messages

List of role/content lists.

api_key

Optional bearer token (NULL for local Ollama).

timeout

Seconds. Default 120.

Value

Parsed JSON list (the response body).

Examples

if (requireNamespace("httr2", quietly = TRUE)) {
  # \donttest{
  msgs <- list(list(role = "user", content = "Say hello"))
  # Second arg is whatever model your Ollama server serves (see `ollama list`).
  res <- try(morie_llm_request_completion("http://localhost:11434", "your-model", msgs))
  # }
}
#> Error : http://localhost:11434 did not answer ()