Robitx / gp.nvim

Gp.nvim (GPT prompt) Neovim AI plugin: ChatGPT sessions & Instructable text/code operations & Speech to text [OpenAI, Ollama, Anthropic, ..]
MIT License
810 stars 68 forks source link

Whisper API endpoint and key. Groq, ollama and other custom providers #220

Open Himujjal opened 4 days ago

Himujjal commented 4 days ago

What is the issue?

Error that shows up:

image Error in text:

Gp.nvim: Whisper query, no text:
'{"error":{"message":"Invalid API Key","type":"invalid_request_error","code":"invalid_api_key"}}\n'

Relevant resources:

My config for reference:

local OPENAI_KEY = env.OPENAI_KEY
local GROQ_KEY = env.GROQ_KEY
local OPENAI_HOST = "https://api.openai.com/v1/chat/completions"
local GROQ_HOST = "https://api.groq.com/openai/v1/chat/completions"
local GROQ_AUDIO = "https://api.groq.com/openai/v1/audio/transcriptions"

local config = {
  providers = {
    openai = {
      disable = false,
      endpoint = OPENAI_HOST,
      secret = OPENAI_KEY,
    },
    groq = {
      disable = false,
      endpoint = GROQ_HOST,
      secret = GROQ_KEY,
    },
  },

  chat_shortcut_respond = { modes = { "n", "i", "v", "x" }, shortcut = "<C-g><cr>" },
  chat_confirm_delete = false,

  -- prefix for all commands
  cmd_prefix = "Gp",

  default_chat_agent = "GroqLLAMA_8B",
  whisper = {
    -- -- TODO: In the future, when gpnvim will support whisper options
    endpoint = GROQ_AUDIO,
    secret = GROQ_KEY,
  },

  agents = {
    {
      provider = "openai",
      name = "ChatGPT4o",
      chat = false,
      command = true,
      -- string with model name or table with model name and parameters
      model = { model = "gpt-4o", temperature = 0.8, top_p = 1 },
      -- system prompt (use this to specify the persona/role of the AI)
      system_prompt = "You are an AI working as a code editor.\n\n"
        .. "Please AVOID COMMENTARY OUTSIDE OF THE SNIPPET RESPONSE.\n"
        .. "START AND END YOUR ANSWER WITH:\n\n```",
    },
    {
      provider = "openai",
      name = "ChatGPT4o-mini",
      chat = true,
      command = true,
      -- string with model name or table with model name and parameters
      model = { model = "gpt-4o-mini", temperature = 0.8, top_p = 1 },
      -- system prompt (use this to specify the persona/role of the AI)
      system_prompt = "You are an AI working as a code editor.\n\n"
        .. "Please AVOID COMMENTARY OUTSIDE OF THE SNIPPET RESPONSE.\n"
        .. "START AND END YOUR ANSWER WITH:\n\n```",
    },
    {
      provider = "groq",
      name = "GroqLLAMA_8B",
      chat = true,
      command = true,
      -- string with model name or table with model name and parameters
      model = { model = "llama-3.1-70b-versatile", temperature = 0.8, top_p = 1 },
      system_prompt = "You are an AI helping the user with code and other tasks\n\n"
        .. "Please AVOID COMMENTARY OUTSIDE OF THE SNIPPET RESPONSE.\n",
    },
    {
      provider = "groq",
      name = "GroqLLAMA_8B",
      chat = true,
      command = true,
      -- string with model name or table with model name and parameters
      model = { model = "llama-3.2-11b-text-preview", temperature = 0.8, top_p = 1 },
      system_prompt = "Given a task or problem, please provide a concise and well-formatted solution or answer.\n\n"
        .. "Please keep your response within a code snippet, and avoid unnecessary commentary.\n",
    },
  },
}
Himujjal commented 4 days ago

Added a PR: https://github.com/Robitx/gp.nvim/pull/221 w.r.t. this issue. Please review and merge it