-
-
Notifications
You must be signed in to change notification settings - Fork 190
/
Copy pathgemini.lua
135 lines (134 loc) · 4.18 KB
/
gemini.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
local openai = require("codecompanion.adapters.openai")
---@class Gemini.Adapter: CodeCompanion.Adapter
return {
name = "gemini",
formatted_name = "Gemini",
roles = {
llm = "assistant",
user = "user",
},
opts = {
stream = true,
},
features = {
text = true,
tokens = true,
vision = true,
},
url = "https://generativelanguage.googleapis.com/v1beta/openai/chat/completions",
env = {
api_key = "GEMINI_API_KEY",
},
headers = {
Authorization = "Bearer ${api_key}",
["Content-Type"] = "application/json",
},
handlers = {
--- Use the OpenAI adapter for the bulk of the work
setup = function(self)
return openai.handlers.setup(self)
end,
tokens = function(self, data)
return openai.handlers.tokens(self, data)
end,
form_parameters = function(self, params, messages)
return openai.handlers.form_parameters(self, params, messages)
end,
form_messages = function(self, messages)
return openai.handlers.form_messages(self, messages)
end,
chat_output = function(self, data)
return openai.handlers.chat_output(self, data)
end,
inline_output = function(self, data, context)
return openai.handlers.inline_output(self, data, context)
end,
on_exit = function(self, data)
return openai.handlers.on_exit(self, data)
end,
},
schema = {
---@type CodeCompanion.Schema
model = {
order = 1,
mapping = "parameters",
type = "enum",
desc = "The model that will complete your prompt. See https://ai.google.dev/gemini-api/docs/models/gemini#model-variations for additional details and options.",
default = "gemini-2.0-flash",
choices = {
"gemini-2.5-pro-exp-03-25",
"gemini-2.0-flash",
"gemini-2.0-pro-exp-02-05",
"gemini-1.5-flash",
"gemini-1.5-pro",
"gemini-1.0-pro",
},
},
---@type CodeCompanion.Schema
maxOutputTokens = {
order = 2,
mapping = "parameters",
type = "integer",
optional = true,
default = nil,
desc = "The maximum number of tokens to include in a response candidate. Note: The default value varies by model",
validate = function(n)
return n > 0, "Must be greater than 0"
end,
},
---@type CodeCompanion.Schema
temperature = {
order = 3,
mapping = "parameters",
type = "number",
optional = true,
default = nil,
desc = "Controls the randomness of the output.",
validate = function(n)
return n >= 0 and n <= 2, "Must be between 0 and 2"
end,
},
---@type CodeCompanion.Schema
topP = {
order = 4,
mapping = "parameters",
type = "integer",
optional = true,
default = nil,
desc = "The maximum cumulative probability of tokens to consider when sampling. The model uses combined Top-k and Top-p (nucleus) sampling. Tokens are sorted based on their assigned probabilities so that only the most likely tokens are considered. Top-k sampling directly limits the maximum number of tokens to consider, while Nucleus sampling limits the number of tokens based on the cumulative probability.",
validate = function(n)
return n > 0, "Must be greater than 0"
end,
},
---@type CodeCompanion.Schema
topK = {
order = 5,
mapping = "parameters",
type = "integer",
optional = true,
default = nil,
desc = "The maximum number of tokens to consider when sampling",
validate = function(n)
return n > 0, "Must be greater than 0"
end,
},
---@type CodeCompanion.Schema
presencePenalty = {
order = 6,
mapping = "parameters",
type = "number",
optional = true,
default = nil,
desc = "Presence penalty applied to the next token's logprobs if the token has already been seen in the response",
},
---@type CodeCompanion.Schema
frequencyPenalty = {
order = 7,
mapping = "parameters",
type = "number",
optional = true,
default = nil,
desc = "Frequency penalty applied to the next token's logprobs, multiplied by the number of times each token has been seen in the response so far.",
},
},
}