Skip to contents

Create an OpenAI-compatible LLM Object

Usage

create_OpenAI(
  model_name,
  system_prompt = SYSTEM_PROMPT_DEFAULT,
  temperature = TEMPERATURE_DEFAULT,
  output_schema = NULL,
  name = NULL,
  base_url = OPENAI_URL_DEFAULT,
  api_key = NULL,
  api_key_env = OPENAI_API_KEY_ENV_DEFAULT,
  keychain_service = NULL,
  organization = NULL,
  project = NULL,
  timeout = OPENAI_TIMEOUT_DEFAULT,
  extra_headers = NULL,
  extra_body = NULL,
  enable_thinking = NULL,
  validate_model = FALSE
)

Arguments

model_name

Character: The name of the LLM model to use.

system_prompt

Character: The system prompt to use.

temperature

Numeric [0, 2]: The temperature for the model.

output_schema

Optional Schema: Output schema created using schema.

name

Optional character: Name for the LLM object.

base_url

Character: Base URL of the OpenAI-compatible server.

api_key

Optional character: API key.

api_key_env

Character: Environment variable containing the API key.

keychain_service

Optional character: macOS Keychain service containing the API key.

organization

Optional character: OpenAI organization id.

project

Optional character: OpenAI project id.

timeout

Numeric (0, Inf): Request timeout in seconds.

extra_headers

Optional list: Additional HTTP headers.

extra_body

Optional list: Additional request body fields.

enable_thinking

Optional logical: Whether to enable model thinking for compatible local servers.

validate_model

Logical: Whether to validate model availability using the models endpoint.

Value

OpenAI LLM object

Author

EDG

Examples

llm <- create_OpenAI(
   model_name = "local-model",
   base_url = "http://localhost:1234/v1",
   system_prompt = "You are a meticulous research assistant.",
   validate_model = FALSE
)