Skip to content

Add current_model function to the API - #96

Merged
sudo-tee merged 3 commits into
sudo-tee:mainfrom
guillaumeboehm:get_model_api
Nov 4, 2025
Merged

sudo-tee merged 3 commits into
sudo-tee:mainfrom
guillaumeboehm:get_model_api

Conversation

@guillaumeboehm

Copy link
Copy Markdown
Contributor

I had a little need for something like this in my confs. And I felt like it could be a useful addition so here's a PR.

I'm still testing it a bit so I'll undraft it in a bit and after adding some unit tests.

@sudo-tee
sudo-tee marked this pull request as ready for review November 4, 2025 09:54
@cameronr

cameronr commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

@sudo-tee This specific change looks fine to me.

It does make me wonder, tho, if there's a better way to initialize state.current_model. Currently, it's kind of lazily set, usually via topbar:

local function format_model_info()
if not state.current_model or state.current_model == '' then
local info = config_file.get_opencode_config()
state.current_model = info and info.model
end

Also possible it gets set by renderer:

function M._update_stats_from_message(message)
if not state.current_model and message.info.providerID and message.info.providerID ~= '' then
state.current_model = message.info.providerID .. '/' .. message.info.modelID
end

Or it can be specifically selected:

function M.configure_provider()
require('opencode.provider').select(function(selection)
if not selection then
if state.windows then
ui.focus_input()
end
return
end
local model_str = string.format('%s/%s', selection.provider, selection.model)
state.current_model = model_str

Would it be better to explicitly initialize so it's always well defined? Or maybe have a way in state to specify a default initializer function on read when a value is nil?

@sudo-tee

sudo-tee commented Nov 4, 2025 •

Copy link
Copy Markdown
Owner

You are right. I've been thinking about that lately since I got annoyed by the fact that after a restart if you had a session with a specific model it defaults back to the default model instead of picking the one from the last message.

The model should probably be set when the config is loaded if the config specifies one. And should also be determined by the last message in an active session. But it's tricky because if a new session is created after, it should be reset to default IMHO.

A default initializer is a good idea, but only triggered once the config is loaded.

I hope it makes sense?

@cameronr

cameronr commented Nov 4, 2025

Copy link
Copy Markdown
Collaborator

I'll take a stab at solving this.

@sudo-tee
sudo-tee merged commit 5a2a28e into sudo-tee:main Nov 4, 2025
5 checks passed
@guillaumeboehm
guillaumeboehm deleted the get_model_api branch November 5, 2025 07:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants