Skip to content

Commit

Permalink
Merge pull request #51 from frankroeder/feat-gh-models
Browse files Browse the repository at this point in the history
Add support for GitHub models beta API
  • Loading branch information
frankroeder authored Aug 27, 2024
2 parents 72643e7 + bd3c77f commit effbf48
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ While this project is still under development, a substantial part of the code is
+ [Gemini API](https://ai.google.dev/gemini-api/docs)
+ [Groq API](https://console.groq.com)
+ Local and offline serving via [ollama](https://github.com/ollama/ollama)
+ [GitHub Models](https://github.com/marketplace/models)
- Flexible API credential management from various sources:
+ Environment variables
+ Bash commands
Expand Down Expand Up @@ -181,6 +182,9 @@ The minimal requirement is to at least set up one provider, hence one from the s
openai = {
api_key = os.getenv "OPENAI_API_KEY",
},
github = {
api_key = os.getenv "GITHUB_TOKEN",
},
},
}
end,
Expand Down
13 changes: 13 additions & 0 deletions lua/parrot/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ local defaults = {
command = { temperature = 1.5, top_p = 1 },
},
},
github = {
api_key = "",
endpoint = "https://models.inference.ai.azure.com/chat/completions",
topic_prompt = topic_prompt,
topic = {
model = "gpt-4o-mini",
params = {},
},
params = {
chat = { temperature = 1.5, top_p = 1 },
command = { temperature = 1.5, top_p = 1 },
},
},
},
cmd_prefix = "Prt",
curl_params = {},
Expand Down
65 changes: 65 additions & 0 deletions lua/parrot/provider/github.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
local OpenAI = require("parrot.provider.openai")

local GitHub = setmetatable({}, { __index = OpenAI })
GitHub.__index = GitHub

-- Available API parameters for GitHub models
local AVAILABLE_API_PARAMETERS = {
-- required
messages = true,
model = true,
-- optional
max_tokens = true,
temperature = true,
top_p = true,
stop = true,
best_of = true,
presence_penalty = true,
stream = true,
}

function GitHub:new(endpoint, api_key)
local instance = OpenAI.new(self, endpoint, api_key)
instance.name = "github"
return setmetatable(instance, self)
end

-- Preprocesses the payload before sending to the API
---@param payload table
---@return table
function GitHub:preprocess_payload(payload)
for _, message in ipairs(payload.messages) do
message.content = message.content:gsub("^%s*(.-)%s*$", "%1")
end
return utils.filter_payload_parameters(AVAILABLE_API_PARAMETERS, payload)
end

-- Returns the list of available models
---@param online boolean
---@return string[]
function GitHub:get_available_models(online)
return {
"AI21-Jamba-Instruct",
"Cohere-command-r",
"Cohere-command-r-plus",
"Meta-Llama-3-70B-Instruct",
"Meta-Llama-3-8B-Instruct",
"Meta-Llama-3.1-405B-Instruct",
"Meta-Llama-3.1-70B-Instruct",
"Meta-Llama-3.1-8B-Instruct",
"Mistral-small",
"Mistral-Nemo",
"Mistral-large-2407",
"Mistral-large",
"gpt-4o-mini",
"gpt-4o",
"Phi-3-medium-128k-instruct",
"Phi-3-medium-4k-instruct",
"Phi-3-mini-128k-instruct",
"Phi-3-mini-4k-instruct",
"Phi-3-small-128k-instruct",
"Phi-3-small-8k-instruct",
}
end

return GitHub
2 changes: 2 additions & 0 deletions lua/parrot/provider/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local Mistral = require("parrot.provider.mistral")
local Ollama = require("parrot.provider.ollama")
local OpenAI = require("parrot.provider.openai")
local Perplexity = require("parrot.provider.perplexity")
local GitHub = require("parrot.provider.github")
local logger = require("parrot.logger")

local M = {}
Expand All @@ -17,6 +18,7 @@ M.init_provider = function(prov_name, endpoint, api_key)
local providers = {
anthropic = Anthropic,
gemini = Gemini,
github = GitHub,
groq = Groq,
mistral = Mistral,
ollama = Ollama,
Expand Down

0 comments on commit effbf48

Please sign in to comment.