elelem-gemini 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/release.yml +74 -0
- data/.release-please-manifest.json +3 -0
- data/.rspec +1 -0
- data/.rubocop.yml +62 -0
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +4 -0
- data/exe/elelem-gemini +8 -0
- data/lib/elelem/gemini/provider.rb +50 -0
- data/lib/elelem/gemini/version.rb +7 -0
- data/lib/elelem/gemini.rb +24 -0
- data/release-please-config.json +12 -0
- data/spec/elelem/gemini/provider_spec.rb +96 -0
- data/spec/elelem/gemini/registration_spec.rb +69 -0
- data/spec/spec_helper.rb +11 -0
- metadata +81 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ca853e2da2077749e02e4b4afa580d76c4a5b6023521a03d542f329f6adccdef
|
|
4
|
+
data.tar.gz: ac0ebaec816f41655468cede56a5096723346e0febd686287f69c56a5b9e17c3
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: fdef6dda8167f382faee3c6dfe1b4dd2336351dc143de57df8b6c90407222625d4f90a6d24242601668348a635b6c852562226eb9b053fda840e17169895c596
|
|
7
|
+
data.tar.gz: 305b20143922deae4592a509f434dd902bab31a29fc6d1f7ffc46325b75007370d5a709473bef6f95ca378351a1e02659afca85d437199dea07550902014b956
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
name: Release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
workflow_dispatch:
|
|
7
|
+
|
|
8
|
+
permissions: {}
|
|
9
|
+
|
|
10
|
+
concurrency:
|
|
11
|
+
group: release
|
|
12
|
+
cancel-in-progress: false
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
runs-on: ubuntu-latest
|
|
17
|
+
permissions:
|
|
18
|
+
contents: read
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
21
|
+
with:
|
|
22
|
+
persist-credentials: false
|
|
23
|
+
- uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1.299.0
|
|
24
|
+
with:
|
|
25
|
+
ruby-version: "4.0"
|
|
26
|
+
bundler-cache: true
|
|
27
|
+
- run: bin/test
|
|
28
|
+
- run: bin/lint
|
|
29
|
+
|
|
30
|
+
release-please:
|
|
31
|
+
needs: test
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
permissions:
|
|
34
|
+
contents: write
|
|
35
|
+
issues: write
|
|
36
|
+
pull-requests: write
|
|
37
|
+
outputs:
|
|
38
|
+
release_created: ${{ steps.release.outputs.release_created }}
|
|
39
|
+
steps:
|
|
40
|
+
- id: release
|
|
41
|
+
uses: googleapis/release-please-action@45996ed1f6d02564a971a2fa1b5860e934307cf7 # v5.0.0
|
|
42
|
+
with:
|
|
43
|
+
config-file: release-please-config.json
|
|
44
|
+
manifest-file: .release-please-manifest.json
|
|
45
|
+
target-branch: main
|
|
46
|
+
|
|
47
|
+
publish:
|
|
48
|
+
needs: release-please
|
|
49
|
+
if: needs.release-please.outputs.release_created == 'true'
|
|
50
|
+
runs-on: ubuntu-latest
|
|
51
|
+
permissions:
|
|
52
|
+
contents: write
|
|
53
|
+
id-token: write
|
|
54
|
+
steps:
|
|
55
|
+
- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4.4.0
|
|
56
|
+
with:
|
|
57
|
+
persist-credentials: false
|
|
58
|
+
- uses: ruby/setup-ruby@3ff19f5e2baf30647122352b96108b1fbe250c64 # v1.299.0
|
|
59
|
+
with:
|
|
60
|
+
ruby-version: "4.0"
|
|
61
|
+
bundler-cache: true
|
|
62
|
+
- shell: bash
|
|
63
|
+
run: |
|
|
64
|
+
set -euo pipefail
|
|
65
|
+
jwt=$(curl -sS --fail-with-body -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=rubygems.org" | jq -r .value)
|
|
66
|
+
echo "::add-mask::$jwt"
|
|
67
|
+
key=$(jq -n --arg jwt "$jwt" '{jwt: $jwt, owner: "66898"}' | curl -sS --fail-with-body -H "content-type: application/json" -d @- https://rubygems.org/api/v1/oidc/trusted_publisher/exchange_token | jq -r .rubygems_api_key)
|
|
68
|
+
test -n "$key" -a "$key" != null
|
|
69
|
+
echo "::add-mask::$key"
|
|
70
|
+
printf 'GEM_HOST_API_KEY=%s\nBUNDLE_GEM__PUSH_KEY=%s\nRUBYGEMS_API_KEY=%s\n' "$key" "$key" "$key" >> "$GITHUB_ENV"
|
|
71
|
+
- uses: rubygems/release-gem@7f9650160c1a4e7989fdc9855807bdbd421d8b6b # v1.4.1
|
|
72
|
+
with:
|
|
73
|
+
setup-trusted-publisher: false
|
|
74
|
+
await-release: false
|
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
NewCops: enable
|
|
3
|
+
TargetRubyVersion: 4.0
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
Exclude:
|
|
6
|
+
- "pkg/**/*"
|
|
7
|
+
- "bin/**/*"
|
|
8
|
+
- "vendor/**/*"
|
|
9
|
+
- "fixtures/**/*"
|
|
10
|
+
|
|
11
|
+
Metrics:
|
|
12
|
+
Enabled: false
|
|
13
|
+
|
|
14
|
+
Naming/PredicateMethod:
|
|
15
|
+
AllowedMethods:
|
|
16
|
+
- call
|
|
17
|
+
- run
|
|
18
|
+
- summarize
|
|
19
|
+
- prompt
|
|
20
|
+
|
|
21
|
+
Naming/MethodParameterName:
|
|
22
|
+
AllowedNames:
|
|
23
|
+
- me
|
|
24
|
+
- id
|
|
25
|
+
- as
|
|
26
|
+
- io
|
|
27
|
+
|
|
28
|
+
Style/GlobalVars:
|
|
29
|
+
Exclude:
|
|
30
|
+
- "spec/**/*"
|
|
31
|
+
|
|
32
|
+
Lint/EmptyBlock:
|
|
33
|
+
Exclude:
|
|
34
|
+
- "spec/**/*"
|
|
35
|
+
|
|
36
|
+
Lint/UselessDefaultValueArgument:
|
|
37
|
+
Enabled: false
|
|
38
|
+
|
|
39
|
+
Lint/RedundantRequireStatement:
|
|
40
|
+
Enabled: false
|
|
41
|
+
|
|
42
|
+
Lint/UnusedBlockArgument:
|
|
43
|
+
IgnoreEmptyBlocks: true
|
|
44
|
+
AllowUnusedKeywordArguments: true
|
|
45
|
+
|
|
46
|
+
Style/Documentation:
|
|
47
|
+
Enabled: false
|
|
48
|
+
|
|
49
|
+
Style/FormatStringToken:
|
|
50
|
+
Enabled: false
|
|
51
|
+
|
|
52
|
+
Style/FrozenStringLiteralComment:
|
|
53
|
+
Enabled: true
|
|
54
|
+
|
|
55
|
+
Style/StringLiterals:
|
|
56
|
+
EnforcedStyle: double_quotes
|
|
57
|
+
|
|
58
|
+
Style/StringLiteralsInInterpolation:
|
|
59
|
+
EnforcedStyle: double_quotes
|
|
60
|
+
|
|
61
|
+
Layout/LineLength:
|
|
62
|
+
Max: 120
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 (2026-11-16)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* elelem-gemini connects elelem to Gemini through elelem-openai ([9282dd1](https://github.com/elelem-sh/gemini/commit/9282dd1efd923d77f1a50983b900e5a16e272ee2))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* require elelem-openai 0.3, which takes a base url with a trailing slash ([27c8c6c](https://github.com/elelem-sh/gemini/commit/27c8c6ce5cc306930446772d231d191f0a58df7d))
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 mo khan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# elelem-gemini
|
|
2
|
+
|
|
3
|
+
A [Google Gemini](https://aistudio.google.com/apikey) provider plugin for [elelem](https://elelem.sh).
|
|
4
|
+
It talks to Google Gemini's OpenAI-compatible Chat Completions API
|
|
5
|
+
through [elelem-openai](https://github.com/elelem-sh/openai).
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
gem install elelem-gemini
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Use
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
export GEMINI_API_KEY=...
|
|
17
|
+
elelem -p gemini --model MODEL
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
* `GEMINI_API_KEY` (required): get one at https://aistudio.google.com/apikey
|
|
21
|
+
* `GEMINI_MODEL`: the model, when `--model` is not given
|
|
22
|
+
* `GEMINI_BASE_URL`: overrides `https://generativelanguage.googleapis.com/v1beta/openai`
|
|
23
|
+
|
|
24
|
+
There is no default model, since free model lists change often. With
|
|
25
|
+
no model set, elelem stops and names `GEMINI_MODEL`. A variable that is
|
|
26
|
+
set but empty counts as unset.
|
|
27
|
+
|
|
28
|
+
Free tier limits are on Google Gemini's own page: https://ai.google.dev/gemini-api/docs/rate-limits
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
```sh
|
|
33
|
+
bin/setup
|
|
34
|
+
bin/test
|
|
35
|
+
bin/lint
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## License
|
|
39
|
+
|
|
40
|
+
MIT. See LICENSE.txt.
|
data/Rakefile
ADDED
data/exe/elelem-gemini
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Elelem
|
|
4
|
+
module Gemini
|
|
5
|
+
# Gemini's OpenAI-compatible endpoint differs from Chat Completions in two ways:
|
|
6
|
+
#
|
|
7
|
+
# * Streamed tool calls carry no `index`. Each call arrives whole, with its own `id`.
|
|
8
|
+
# * A tool call may carry `extra_content.google.thought_signature`, which Gemini 3
|
|
9
|
+
# models require back on that tool call in the next request, or they answer 400.
|
|
10
|
+
class Provider < Elelem::OpenAI::Provider
|
|
11
|
+
def initialize(...)
|
|
12
|
+
super
|
|
13
|
+
@extra_content = {}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
|
|
18
|
+
def build_request_body(messages, tools)
|
|
19
|
+
body = super
|
|
20
|
+
body.merge(messages: body[:messages].map { |message| with_extra_content(message) })
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def with_extra_content(message)
|
|
24
|
+
calls = message[:tool_calls]
|
|
25
|
+
return message unless calls
|
|
26
|
+
|
|
27
|
+
message.merge(tool_calls: calls.map { |call| with_signature(call) })
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def with_signature(call)
|
|
31
|
+
extra = @extra_content[call[:id]]
|
|
32
|
+
extra ? call.merge(extra_content: extra) : call
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def accumulate_tool_calls(incoming_tool_calls, tool_calls)
|
|
36
|
+
# A chunk with no id continues the call before it, even within one delta.
|
|
37
|
+
last = tool_calls.keys.last
|
|
38
|
+
incoming = incoming_tool_calls.map do |tool_call|
|
|
39
|
+
id = tool_call["id"]
|
|
40
|
+
@extra_content[id] = tool_call["extra_content"] if id && tool_call["extra_content"]
|
|
41
|
+
next tool_call if tool_call.key?("index")
|
|
42
|
+
|
|
43
|
+
last = id if id
|
|
44
|
+
tool_call.merge("index" => last)
|
|
45
|
+
end
|
|
46
|
+
super(incoming, tool_calls)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "elelem/openai"
|
|
4
|
+
|
|
5
|
+
require_relative "gemini/version"
|
|
6
|
+
require_relative "gemini/provider"
|
|
7
|
+
|
|
8
|
+
Elelem.configure do |config|
|
|
9
|
+
config.provider(:gemini) do |model: nil, **|
|
|
10
|
+
# A variable that is set but empty counts as unset.
|
|
11
|
+
env = ->(name) { ENV[name].to_s.strip.then { |v| v.empty? ? nil : v } }
|
|
12
|
+
key = env.call("GEMINI_API_KEY")
|
|
13
|
+
raise KeyError, "GEMINI_API_KEY is not set" if key.nil?
|
|
14
|
+
|
|
15
|
+
model = env.call("GEMINI_MODEL") if model.to_s.strip.empty?
|
|
16
|
+
raise KeyError, "GEMINI_MODEL is not set. Pass --model or set GEMINI_MODEL" if model.nil?
|
|
17
|
+
|
|
18
|
+
Elelem::Gemini::Provider.new(
|
|
19
|
+
model:,
|
|
20
|
+
api_key: key,
|
|
21
|
+
base_url: env.call("GEMINI_BASE_URL") || "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
22
|
+
)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe Elelem::Gemini::Provider do
|
|
4
|
+
subject(:provider) do
|
|
5
|
+
described_class.new(model: "gemini-3.5-flash", api_key: "test-key", http:)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
let(:messages) { [{ role: "user", content: "read README.md and Gemfile at the same time" }] }
|
|
9
|
+
let(:signature) { { "google" => { "thought_signature" => "c2lnbmF0dXJl" } } }
|
|
10
|
+
|
|
11
|
+
# Two tool calls in the shape Gemini streams them: no index, each whole in its own chunk,
|
|
12
|
+
# and a thought signature on the first.
|
|
13
|
+
let(:events) do
|
|
14
|
+
[
|
|
15
|
+
{ "choices" => [{ "delta" => { "role" => "assistant", "tool_calls" => [
|
|
16
|
+
{ "extra_content" => signature, "id" => "call_1", "type" => "function",
|
|
17
|
+
"function" => { "name" => "read", "arguments" => '{"path":"README.md"}' } }
|
|
18
|
+
] } }] },
|
|
19
|
+
{ "choices" => [{ "delta" => { "role" => "assistant", "tool_calls" => [
|
|
20
|
+
{ "id" => "call_2", "type" => "function",
|
|
21
|
+
"function" => { "name" => "read", "arguments" => '{"path":"Gemfile"}' } }
|
|
22
|
+
] } }] },
|
|
23
|
+
{ "choices" => [{ "delta" => { "role" => "assistant" }, "finish_reason" => "stop" }] }
|
|
24
|
+
]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
let(:http) do
|
|
28
|
+
Class.new do
|
|
29
|
+
attr_reader :bodies
|
|
30
|
+
|
|
31
|
+
def initialize(chunk)
|
|
32
|
+
@chunk = chunk
|
|
33
|
+
@bodies = []
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def post(_uri, body:, **)
|
|
37
|
+
@bodies << body
|
|
38
|
+
response = Net::HTTPOK.new("1.1", "200", "OK")
|
|
39
|
+
chunk = @chunk
|
|
40
|
+
response.define_singleton_method(:read_body) { |&block| block.call(chunk) }
|
|
41
|
+
yield response
|
|
42
|
+
end
|
|
43
|
+
end.new(sse(events))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def sse(events)
|
|
47
|
+
events.map { |event| "data: #{JSON.generate(event)}\n" }.join << "data: [DONE]\n"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "keeps parallel tool calls apart when they carry no index" do
|
|
51
|
+
calls = provider.fetch(messages, []) {}
|
|
52
|
+
|
|
53
|
+
expect(calls).to eq(
|
|
54
|
+
[
|
|
55
|
+
{ id: "call_1", name: "read", arguments: { "path" => "README.md" } },
|
|
56
|
+
{ id: "call_2", name: "read", arguments: { "path" => "Gemfile" } }
|
|
57
|
+
]
|
|
58
|
+
)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
context "when a call's arguments arrive in pieces with no id" do
|
|
62
|
+
let(:events) do
|
|
63
|
+
[
|
|
64
|
+
{ "choices" => [{ "delta" => { "tool_calls" => [
|
|
65
|
+
{ "id" => "call_1", "function" => { "name" => "read", "arguments" => '{"path":"README.md"}' } }
|
|
66
|
+
] } }] },
|
|
67
|
+
{ "choices" => [{ "delta" => { "tool_calls" => [
|
|
68
|
+
{ "id" => "call_2", "function" => { "name" => "read", "arguments" => '{"path":' } },
|
|
69
|
+
{ "function" => { "arguments" => '"Gem' } }
|
|
70
|
+
] } }] },
|
|
71
|
+
{ "choices" => [{ "delta" => { "tool_calls" => [{ "function" => { "arguments" => 'file"}' } }] } }] }
|
|
72
|
+
]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "joins each piece to the call before it" do
|
|
76
|
+
calls = provider.fetch(messages, []) {}
|
|
77
|
+
|
|
78
|
+
expect(calls.map { |call| [call[:id], call[:arguments]] }).to eq(
|
|
79
|
+
[["call_1", { "path" => "README.md" }], ["call_2", { "path" => "Gemfile" }]]
|
|
80
|
+
)
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
it "sends each tool call's thought signature back with it" do
|
|
85
|
+
calls = provider.fetch(messages, []) {}
|
|
86
|
+
history = messages + [
|
|
87
|
+
{ role: "assistant", content: "", tool_calls: calls },
|
|
88
|
+
{ role: "tool", tool_call_id: "call_1", content: "{}" },
|
|
89
|
+
{ role: "tool", tool_call_id: "call_2", content: "{}" }
|
|
90
|
+
]
|
|
91
|
+
provider.fetch(history, []) {}
|
|
92
|
+
|
|
93
|
+
sent = http.bodies.last[:messages][1][:tool_calls]
|
|
94
|
+
expect(sent.map { |call| call[:extra_content] }).to eq([signature, nil])
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
RSpec.describe "the gemini provider" do
|
|
4
|
+
around do |example|
|
|
5
|
+
saved = ENV.to_h.slice("GEMINI_API_KEY", "GEMINI_BASE_URL", "GEMINI_MODEL")
|
|
6
|
+
example.run
|
|
7
|
+
ensure
|
|
8
|
+
%w[GEMINI_API_KEY GEMINI_BASE_URL GEMINI_MODEL].each { |k| ENV.delete(k) }
|
|
9
|
+
ENV.update(saved)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
ENV["GEMINI_API_KEY"] = "test-key"
|
|
14
|
+
ENV["GEMINI_MODEL"] = "env-model"
|
|
15
|
+
ENV.delete("GEMINI_BASE_URL")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def build(**) = Elelem::Config.build_provider("gemini", **)
|
|
19
|
+
def uri(**) = build(**).instance_variable_get(:@uri).to_s
|
|
20
|
+
def model(**) = build(**).instance_variable_get(:@model)
|
|
21
|
+
|
|
22
|
+
it "registers provider gemini" do
|
|
23
|
+
expect(Elelem::Config.names).to include("gemini")
|
|
24
|
+
expect(build).to be_a(Elelem::OpenAI::Provider)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "talks to Gemini by default" do
|
|
28
|
+
expect(uri).to eq("https://generativelanguage.googleapis.com/v1beta/openai/chat/completions")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "sends GEMINI_API_KEY" do
|
|
32
|
+
expect(build.instance_variable_get(:@api_key)).to eq("test-key")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "names GEMINI_API_KEY when the key is missing or empty" do
|
|
36
|
+
ENV.delete("GEMINI_API_KEY")
|
|
37
|
+
expect { build }.to raise_error(KeyError, /GEMINI_API_KEY/)
|
|
38
|
+
|
|
39
|
+
ENV["GEMINI_API_KEY"] = " "
|
|
40
|
+
expect { build }.to raise_error(KeyError, /GEMINI_API_KEY/)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "names GEMINI_MODEL when no model is set, and treats an empty one as unset" do
|
|
44
|
+
ENV.delete("GEMINI_MODEL")
|
|
45
|
+
expect { build }.to raise_error(KeyError, /GEMINI_MODEL/)
|
|
46
|
+
|
|
47
|
+
ENV["GEMINI_MODEL"] = ""
|
|
48
|
+
expect { build }.to raise_error(KeyError, /GEMINI_MODEL/)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "takes the model from GEMINI_MODEL" do
|
|
52
|
+
expect(model).to eq("env-model")
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "prefers --model over GEMINI_MODEL" do
|
|
56
|
+
expect(model(model: "flag-model")).to eq("flag-model")
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "uses GEMINI_BASE_URL, with or without a trailing slash, and treats an empty one as unset" do
|
|
60
|
+
ENV["GEMINI_BASE_URL"] = "http://127.0.0.1:8080/v1/"
|
|
61
|
+
expect(uri).to eq("http://127.0.0.1:8080/v1/chat/completions")
|
|
62
|
+
|
|
63
|
+
ENV["GEMINI_BASE_URL"] = "http://127.0.0.1:8080/v1"
|
|
64
|
+
expect(uri).to eq("http://127.0.0.1:8080/v1/chat/completions")
|
|
65
|
+
|
|
66
|
+
ENV["GEMINI_BASE_URL"] = ""
|
|
67
|
+
expect(uri).to eq("https://generativelanguage.googleapis.com/v1beta/openai/chat/completions")
|
|
68
|
+
end
|
|
69
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: elelem-gemini
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- mo khan
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: elelem-openai
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0.3'
|
|
19
|
+
- - "<"
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1'
|
|
22
|
+
type: :runtime
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
requirements:
|
|
26
|
+
- - ">="
|
|
27
|
+
- !ruby/object:Gem::Version
|
|
28
|
+
version: '0.3'
|
|
29
|
+
- - "<"
|
|
30
|
+
- !ruby/object:Gem::Version
|
|
31
|
+
version: '1'
|
|
32
|
+
description: A Google Gemini provider plugin for elelem.
|
|
33
|
+
email:
|
|
34
|
+
- mo@mokhan.ca
|
|
35
|
+
executables:
|
|
36
|
+
- elelem-gemini
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- ".github/workflows/release.yml"
|
|
41
|
+
- ".release-please-manifest.json"
|
|
42
|
+
- ".rspec"
|
|
43
|
+
- ".rubocop.yml"
|
|
44
|
+
- CHANGELOG.md
|
|
45
|
+
- LICENSE.txt
|
|
46
|
+
- README.md
|
|
47
|
+
- Rakefile
|
|
48
|
+
- exe/elelem-gemini
|
|
49
|
+
- lib/elelem/gemini.rb
|
|
50
|
+
- lib/elelem/gemini/provider.rb
|
|
51
|
+
- lib/elelem/gemini/version.rb
|
|
52
|
+
- release-please-config.json
|
|
53
|
+
- spec/elelem/gemini/provider_spec.rb
|
|
54
|
+
- spec/elelem/gemini/registration_spec.rb
|
|
55
|
+
- spec/spec_helper.rb
|
|
56
|
+
homepage: https://elelem.sh
|
|
57
|
+
licenses:
|
|
58
|
+
- MIT
|
|
59
|
+
metadata:
|
|
60
|
+
allowed_push_host: https://rubygems.org
|
|
61
|
+
homepage_uri: https://elelem.sh
|
|
62
|
+
source_code_uri: https://github.com/elelem-sh/gemini
|
|
63
|
+
rubygems_mfa_required: 'true'
|
|
64
|
+
rdoc_options: []
|
|
65
|
+
require_paths:
|
|
66
|
+
- lib
|
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
68
|
+
requirements:
|
|
69
|
+
- - ">="
|
|
70
|
+
- !ruby/object:Gem::Version
|
|
71
|
+
version: 4.0.0
|
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
|
+
requirements:
|
|
74
|
+
- - ">="
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubygems_version: 4.0.6
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: A Google Gemini provider plugin for elelem.
|
|
81
|
+
test_files: []
|