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

# \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 in httr2::req_perform(req) : Failed to perform HTTP request.
#> Caused by error in `curl::curl_fetch_memory()`:
#> ! Couldn't connect to server [localhost]:
#> Failed to connect to localhost port 11434 after 0 ms: Couldn't connect to server
# }