Skip to content

Commit

Permalink
Merge pull request #88 from CALUGC/fix/first-startup-fail
Browse files Browse the repository at this point in the history
fix: change current_provider default value to nil
  • Loading branch information
frankroeder authored Jan 13, 2025
2 parents 048a77d + a8468be commit c529403
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lua/parrot/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ function State:init_file_state(available_providers)
self.file_state[prov] = { chat_model = nil, command_model = nil }
end
end
self.file_state.current_provider = self.file_state.current_provider or { chat = "", command = "" }
self.file_state.current_provider = self.file_state.current_provider or { chat = nil, command = nil }
end

--- Initializes state for a specific provider if it's not already initialized.
--- @param available_providers table
--- @param available_models table
function State:init_state(available_providers, available_models)
self._state.current_provider = self._state.current_provider or { chat = "", command = "" }
self._state.current_provider = self._state.current_provider or { chat = nil, command = nil }
for _, provider in ipairs(available_providers) do
self._state[provider] = self._state[provider] or { chat_model = nil, command_model = nil }
self:load_models(provider, "chat_model", available_models)
Expand Down
8 changes: 4 additions & 4 deletions tests/parrot/state_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ describe("State", function()

assert.are.same({
current_provider = {
chat = "",
command = "",
chat = nil,
command = nil,
},
mistral = {
chat_model = "model3",
Expand All @@ -122,7 +122,7 @@ describe("State", function()
local state = State:new("/tmp")
state:init_state({ "ollama" }, { ollama = { "model1", "model2" } })
assert.are.same({
current_provider = { chat = "", command = "" },
current_provider = { chat = nil, command = nil },
ollama = { chat_model = "model1", command_model = "model1" },
}, state._state)
end)
Expand Down Expand Up @@ -220,7 +220,7 @@ describe("State", function()
state:init_state({ "openai" }, { openai = { "gpt-4o", "gpt-3.5" } })
state:set_provider("openai", true)
assert.are.same("openai", state._state.current_provider.chat)
assert.are.same("", state._state.current_provider.command)
assert.are.same(nil, state._state.current_provider.command)

state:set_provider("groq", false)
assert.are.same("groq", state._state.current_provider.command)
Expand Down

0 comments on commit c529403

Please sign in to comment.