From e24a8ee73c520489e30dfa5895f2a721671a42d2 Mon Sep 17 00:00:00 2001 From: TroyHernandez Date: Fri, 8 May 2026 15:56:06 -0500 Subject: [PATCH] Add provider_default_model() helper Returns the model id chat() falls back to when no model is specified, so client code (e.g., corteza's chat status line) can resolve the default upfront without reaching into .get_provider_config(). --- DESCRIPTION | 2 +- NAMESPACE | 1 + NEWS.md | 7 +++++++ R/providers.R | 18 ++++++++++++++++++ inst/tinytest/test_providers.R | 9 +++++++++ man/provider_default_model.Rd | 24 ++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 man/provider_default_model.Rd diff --git a/DESCRIPTION b/DESCRIPTION index 0c58fe6..7bcdce0 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: llm.api Title: Minimal LLM Chat Interface -Version: 0.1.2 +Version: 0.1.2.1 Authors@R: c( person("Troy", "Hernandez", role = c("aut", "cre"), email = "troy@cornball.ai", diff --git a/NAMESPACE b/NAMESPACE index 752c85a..bcd8181 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -20,5 +20,6 @@ export(mcp_start) export(mcp_tools) export(mcp_tools_for_api) export(mcp_tools_for_claude) +export(provider_default_model) S3method(print,mcp_connection) diff --git a/NEWS.md b/NEWS.md index afe50a9..ba175e3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +# llm.api 0.1.2.1 + +* New exported helper `provider_default_model(provider)`. Returns the + model id `chat()` falls back to when no model is specified, so client + code can display the resolved model upfront without duplicating the + lookup table or reaching into internals. + # llm.api 0.1.2 * `chat()` now returns `$thinking` and `$finish_reason`. Reasoning models diff --git a/R/providers.R b/R/providers.R index 26097a6..011d02a 100644 --- a/R/providers.R +++ b/R/providers.R @@ -69,6 +69,24 @@ ) } +#' Default model for a provider +#' +#' Returns the model name `chat()` falls back to when the caller +#' doesn't specify one. Useful for client code that wants to display +#' the resolved model upfront (e.g., in a status line) without +#' duplicating the lookup table. +#' +#' @param provider Character. One of `"openai"`, `"anthropic"`, +#' `"moonshot"`, `"ollama"`. +#' @return Character. The default model id for that provider. +#' @export +#' @examples +#' provider_default_model("anthropic") +#' provider_default_model("moonshot") +provider_default_model <- function(provider) { + .get_provider_config(provider)$default_model +} + #' Chat with OpenAI #' #' Convenience wrapper for 'OpenAI' models. diff --git a/inst/tinytest/test_providers.R b/inst/tinytest/test_providers.R index 47ad1fd..7ee6291 100644 --- a/inst/tinytest/test_providers.R +++ b/inst/tinytest/test_providers.R @@ -76,3 +76,12 @@ expect_null(cfg$api_key) # Unknown provider errors expect_error(llm.api:::.get_provider_config("unknown"), pattern = "Unknown provider") + +# provider_default_model() exposes the default model id for each +# supported provider so client code (e.g., status lines) can resolve it +# upfront without reaching into internals. +expect_equal(provider_default_model("openai"), "gpt-4o-mini") +expect_equal(provider_default_model("anthropic"), "claude-sonnet-4-6") +expect_equal(provider_default_model("moonshot"), "kimi-k2") +expect_equal(provider_default_model("ollama"), "llama3.2") +expect_error(provider_default_model("nonsense"), pattern = "Unknown provider") diff --git a/man/provider_default_model.Rd b/man/provider_default_model.Rd new file mode 100644 index 0000000..99abd6c --- /dev/null +++ b/man/provider_default_model.Rd @@ -0,0 +1,24 @@ +% tinyrox says don't edit this manually, but it can't stop you! +\name{provider_default_model} +\alias{provider_default_model} +\title{Default model for a provider} +\usage{ +provider_default_model(provider) +} +\arguments{ +\item{provider}{Character. One of `"openai"`, `"anthropic"`, +`"moonshot"`, `"ollama"`.} +} +\value{ +Character. The default model id for that provider. +} +\description{ +Returns the model name `chat()` falls back to when the caller +doesn't specify one. Useful for client code that wants to display +the resolved model upfront (e.g., in a status line) without +duplicating the lookup table. +} +\examples{ +provider_default_model("anthropic") +provider_default_model("moonshot") +}