Skip to content

Commit

Permalink
fix(ollama): additional guard if server is not running
Browse files Browse the repository at this point in the history
  • Loading branch information
frankroeder committed Sep 28, 2024
1 parent 09df8d5 commit fdcaa6c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions lua/parrot/provider/ollama.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,19 @@ function Ollama:get_available_models()
local parsed_response = utils.parse_raw_response(job)
self:process_onexit(parsed_response)

if parsed_response == "" then
logger.debug("Ollama server not running.")
return {}
end

local success, parsed_data = pcall(vim.json.decode, parsed_response)
if not success then
logger.error("Error parsing JSON: " .. vim.inspect(parsed_data))
logger.error("Ollama - Error parsing JSON: " .. vim.inspect(parsed_data))
return {}
end

if not parsed_data.models then
logger.error("No models found. Please use 'ollama pull' to download one.")
logger.error("Ollama - No models found. Please use 'ollama pull' to download one.")
return {}
end

Expand Down
2 changes: 1 addition & 1 deletion lua/parrot/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ end
--- Initializes file state for each provider if it's empty.
--- @param available_providers table
function State:init_file_state(available_providers)
self.file_state.current_provider = self.file_state.current_provider or { chat = "", command = "" }
if next(self.file_state) == nil then
for _, prov in ipairs(available_providers) do
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 = "" }
end

--- Initializes state for a specific provider if it's not already initialized.
Expand Down

0 comments on commit fdcaa6c

Please sign in to comment.