girb-gemini 0.1.1 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7181aaaf0ef47945d34fbf816fac795156073eba874678e0ff206a73867946d1
4
- data.tar.gz: c27aae4cd27cdfe4aa0bfa0ea9351fc096bfece04167fe8d1553ab58c65945ae
3
+ metadata.gz: f31f46cab9413d0ab42e04ab660d422d2c2eab6aa3c24c73bd0cb92302ddee7b
4
+ data.tar.gz: 96d2cf77aec44f0d0e3e7ed58974be763f5f0fd84b5ffeeadf02b1fe501825ae
5
5
  SHA512:
6
- metadata.gz: 772fb412059de24c75cb39d166d81b68e0047fc5c90488e3d69448516dd5f3aa3a795e287e3a78365006e43a56d349bfa7639c81eb84404df6e8565dc37626ed
7
- data.tar.gz: e15f65f649f5a0f8ee16ac2b622ad1f7bcaec2dad90854ca6215e0b45486c7b54a163dcee55e7d1a817f18f7c9db76b1f870137b4514f42effe9c9445249f2bb
6
+ metadata.gz: e732d81d5c50e8e9d816c4980c0dd6ae88e050f08903bbae28a05b55a86a31c2a829893adfa8c2ddbb9a54be75b561aade611bf8ec81365de0b7483583055385
7
+ data.tar.gz: f9e9a2ce202940ed7085e4c3e3ee82cf73345233e29afb45006b4adcf2e1520d9b2c09a67fae97776c5fbd87316b5963da5b96da3e3820a5acc7e16fdbcabf82
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.3.0] - 2026-02-12
4
+
5
+ ### Added
6
+
7
+ - Web search tool powered by Google Search grounding
8
+ - Support for gemini-3-flash-preview and gemini-3-pro-preview models
9
+
10
+ ## [0.2.0] - 2026-02-07
11
+
12
+ ### Fixed
13
+
14
+ - Fix Gemini 3 thought_signature error on function calls
15
+ - Preserve thought_signature from API response and include it when sending function call history back to the API
16
+ - Clear false-positive websocket-native LoadError from ExceptionCapture after loading ruby-gemini-api
17
+
3
18
  ## [0.1.1] - 2026-02-03
4
19
 
5
20
  ### Added
data/README.md CHANGED
@@ -6,52 +6,103 @@ Google Gemini LLM provider for [girb](https://github.com/rira100000000/girb) (AI
6
6
 
7
7
  ## Installation
8
8
 
9
+ ### For Rails Projects
10
+
9
11
  Add to your Gemfile:
10
12
 
11
13
  ```ruby
12
- gem 'girb'
13
- gem 'girb-gemini'
14
+ group :development do
15
+ gem 'girb-gemini'
16
+ end
14
17
  ```
15
18
 
16
- Or install directly:
19
+ Then run:
17
20
 
18
21
  ```bash
19
- gem install girb girb-gemini
22
+ bundle install
20
23
  ```
21
24
 
22
- ## Setup
25
+ Create a `.girbrc` file in your project root:
23
26
 
24
- ### Option 1: Configure in ~/.irbrc (Recommended)
27
+ ```ruby
28
+ # .girbrc
29
+ require 'girb-gemini'
25
30
 
26
- Add to your `~/.irbrc`:
31
+ Girb.configure do |c|
32
+ c.provider = Girb::Providers::Gemini.new(
33
+ api_key: ENV['GEMINI_API_KEY'],
34
+ model: 'gemini-2.5-flash'
35
+ )
36
+ end
37
+ ```
38
+
39
+ Now `rails console` will automatically load girb!
40
+
41
+ ### For Non-Rails Projects
42
+
43
+ Install globally:
44
+
45
+ ```bash
46
+ gem install girb girb-gemini
47
+ ```
48
+
49
+ Create a `.girbrc` file in your project directory:
27
50
 
28
51
  ```ruby
52
+ # .girbrc
29
53
  require 'girb-gemini'
30
54
 
31
55
  Girb.configure do |c|
32
56
  c.provider = Girb::Providers::Gemini.new(
33
- api_key: 'your-api-key',
57
+ api_key: ENV['GEMINI_API_KEY'],
34
58
  model: 'gemini-2.5-flash'
35
59
  )
36
60
  end
37
61
  ```
38
62
 
39
- Then use regular `irb` command.
63
+ Then use `girb` command instead of `irb`.
40
64
 
41
- ### Option 2: Configure via environment variables
65
+ ## Configuration
66
+
67
+ Set your API key as an environment variable:
42
68
 
43
69
  ```bash
44
- export GIRB_PROVIDER=girb-gemini
45
- export GIRB_MODEL=gemini-2.5-flash # optional, defaults to gemini-2.5-flash
46
70
  export GEMINI_API_KEY=your-api-key
47
71
  ```
48
72
 
49
- Then start with `girb` command.
50
-
51
73
  ## Available Models
52
74
 
53
75
  - `gemini-2.5-flash` (default) - Fast and efficient
54
76
  - `gemini-2.5-pro` - More capable, slower
77
+ - `gemini-3-flash-preview` - Next generation, fast
78
+ - `gemini-3-pro-preview` - Next generation, more capable
79
+
80
+ ## Web Search
81
+
82
+ girb-gemini includes a built-in web search tool powered by Google Search. This allows the AI to retrieve up-to-date information during your IRB session.
83
+
84
+ Web search is **enabled by default**. To disable it:
85
+
86
+ ```ruby
87
+ Girb.configure do |c|
88
+ c.provider = Girb::Providers::Gemini.new(
89
+ api_key: ENV['GEMINI_API_KEY'],
90
+ model: 'gemini-2.5-flash',
91
+ google_search: false
92
+ )
93
+ end
94
+ ```
95
+
96
+ ## Alternative: Environment Variable Configuration
97
+
98
+ For the `girb` command, you can also configure via environment variables (used when no `.girbrc` is found):
99
+
100
+ ```bash
101
+ export GIRB_PROVIDER=girb-gemini
102
+ export GIRB_MODEL=gemini-2.5-flash # optional, defaults to gemini-2.5-flash
103
+ export GEMINI_API_KEY=your-api-key
104
+ girb
105
+ ```
55
106
 
56
107
  ## License
57
108
 
data/README_ja.md CHANGED
@@ -4,52 +4,103 @@
4
4
 
5
5
  ## インストール
6
6
 
7
+ ### Railsプロジェクトの場合
8
+
7
9
  Gemfileに追加:
8
10
 
9
11
  ```ruby
10
- gem 'girb'
11
- gem 'girb-gemini'
12
+ group :development do
13
+ gem 'girb-gemini'
14
+ end
12
15
  ```
13
16
 
14
- または直接インストール:
17
+ そして実行:
15
18
 
16
19
  ```bash
17
- gem install girb girb-gemini
20
+ bundle install
18
21
  ```
19
22
 
20
- ## セットアップ
23
+ プロジェクトルートに `.girbrc` ファイルを作成:
21
24
 
22
- ### 方法1: ~/.irbrcで設定(推奨)
25
+ ```ruby
26
+ # .girbrc
27
+ require 'girb-gemini'
23
28
 
24
- `~/.irbrc` に追加:
29
+ Girb.configure do |c|
30
+ c.provider = Girb::Providers::Gemini.new(
31
+ api_key: ENV['GEMINI_API_KEY'],
32
+ model: 'gemini-2.5-flash'
33
+ )
34
+ end
35
+ ```
36
+
37
+ これで `rails console` が自動的にgirbを読み込みます!
38
+
39
+ ### 非Railsプロジェクトの場合
40
+
41
+ グローバルにインストール:
42
+
43
+ ```bash
44
+ gem install girb girb-gemini
45
+ ```
46
+
47
+ プロジェクトディレクトリに `.girbrc` ファイルを作成:
25
48
 
26
49
  ```ruby
50
+ # .girbrc
27
51
  require 'girb-gemini'
28
52
 
29
53
  Girb.configure do |c|
30
54
  c.provider = Girb::Providers::Gemini.new(
31
- api_key: 'your-api-key',
55
+ api_key: ENV['GEMINI_API_KEY'],
32
56
  model: 'gemini-2.5-flash'
33
57
  )
34
58
  end
35
59
  ```
36
60
 
37
- 通常の `irb` コマンドで使用できます。
61
+ `irb` の代わりに `girb` コマンドを使用します。
38
62
 
39
- ### 方法2: 環境変数で設定
63
+ ## 設定
64
+
65
+ APIキーを環境変数として設定:
40
66
 
41
67
  ```bash
42
- export GIRB_PROVIDER=girb-gemini
43
- export GIRB_MODEL=gemini-2.5-flash # オプション、デフォルトは gemini-2.5-flash
44
68
  export GEMINI_API_KEY=your-api-key
45
69
  ```
46
70
 
47
- `girb` コマンドで起動します。
48
-
49
71
  ## 利用可能なモデル
50
72
 
51
73
  - `gemini-2.5-flash` (デフォルト) - 高速で効率的
52
74
  - `gemini-2.5-pro` - より高性能、やや遅い
75
+ - `gemini-3-flash-preview` - 次世代モデル、高速
76
+ - `gemini-3-pro-preview` - 次世代モデル、より高性能
77
+
78
+ ## Web検索
79
+
80
+ girb-geminiにはGoogle Searchを利用したWeb検索ツールが組み込まれています。IRBセッション中にAIが最新の情報を取得できます。
81
+
82
+ Web検索は**デフォルトで有効**です。無効にするには:
83
+
84
+ ```ruby
85
+ Girb.configure do |c|
86
+ c.provider = Girb::Providers::Gemini.new(
87
+ api_key: ENV['GEMINI_API_KEY'],
88
+ model: 'gemini-2.5-flash',
89
+ google_search: false
90
+ )
91
+ end
92
+ ```
93
+
94
+ ## 代替: 環境変数での設定
95
+
96
+ `girb` コマンドでは、`.girbrc` が見つからない場合に環境変数で設定することもできます:
97
+
98
+ ```bash
99
+ export GIRB_PROVIDER=girb-gemini
100
+ export GIRB_MODEL=gemini-2.5-flash # オプション、デフォルトは gemini-2.5-flash
101
+ export GEMINI_API_KEY=your-api-key
102
+ girb
103
+ ```
53
104
 
54
105
  ## ライセンス
55
106
 
@@ -1,6 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "gemini"
4
+ # ruby-gemini-apiがgemini/live→websocket→websocket-native(オプション)を
5
+ # requireする過程でLoadErrorが発生しrescueされるが、
6
+ # ExceptionCaptureのTracePointに捕捉される場合があるためクリアする
7
+ Girb::ExceptionCapture.clear if defined?(Girb::ExceptionCapture)
4
8
  require "girb/providers/base"
5
9
 
6
10
  module Girb
@@ -8,12 +12,19 @@ module Girb
8
12
  class Gemini < Base
9
13
  DEFAULT_MODEL = "gemini-2.5-flash"
10
14
 
11
- def initialize(api_key:, model: DEFAULT_MODEL)
15
+ def initialize(api_key:, model: DEFAULT_MODEL, google_search: true)
12
16
  @client = ::Gemini::Client.new(api_key)
13
17
  @model = model
18
+ @google_search = google_search
19
+
20
+ if @google_search
21
+ setup_web_search_tool
22
+ else
23
+ disable_web_search_tool
24
+ end
14
25
  end
15
26
 
16
- def chat(messages:, system_prompt:, tools:)
27
+ def chat(messages:, system_prompt:, tools:, binding: nil)
17
28
  contents = convert_messages(messages)
18
29
  tools_param = build_tools_param(tools)
19
30
 
@@ -41,15 +52,16 @@ module Girb
41
52
  when :assistant
42
53
  { role: "model", parts: [{ text: msg[:content] }] }
43
54
  when :tool_call
44
- {
45
- role: "model",
46
- parts: [{
47
- function_call: {
48
- name: msg[:name],
49
- args: msg[:args]
50
- }
51
- }]
55
+ part = {
56
+ functionCall: {
57
+ name: msg[:name],
58
+ args: msg[:args]
59
+ }
52
60
  }
61
+ if msg.dig(:metadata, :thought_signature)
62
+ part[:thoughtSignature] = msg[:metadata][:thought_signature]
63
+ end
64
+ { role: "model", parts: [part] }
53
65
  when :tool_result
54
66
  {
55
67
  role: "user",
@@ -109,13 +121,41 @@ module Girb
109
121
  def parse_function_calls(response)
110
122
  return [] unless response.function_calls&.any?
111
123
 
124
+ # Extract thought_signature from response parts
125
+ thought_signature = extract_thought_signature(response)
126
+
112
127
  response.function_calls.map do |fc|
113
- {
128
+ result = {
114
129
  name: fc["name"],
115
130
  args: fc["args"] || {}
116
131
  }
132
+ if thought_signature
133
+ result[:metadata] = { thought_signature: thought_signature }
134
+ end
135
+ result
117
136
  end
118
137
  end
138
+
139
+ def extract_thought_signature(response)
140
+ return nil unless response.respond_to?(:first_thought_signature)
141
+
142
+ response.first_thought_signature
143
+ rescue
144
+ nil
145
+ end
146
+
147
+ def setup_web_search_tool
148
+ require_relative "web_search_tool"
149
+ WebSearchTool.client = @client
150
+ WebSearchTool.model = @model
151
+ Girb::Tools.register(WebSearchTool)
152
+ end
153
+
154
+ def disable_web_search_tool
155
+ return unless defined?(WebSearchTool)
156
+
157
+ WebSearchTool.client = nil
158
+ end
119
159
  end
120
160
  end
121
161
  end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Girb
4
+ module Providers
5
+ class WebSearchTool < Girb::Tools::Base
6
+ @client = nil
7
+ @model = nil
8
+
9
+ class << self
10
+ attr_accessor :client, :model
11
+
12
+ def tool_name
13
+ "web_search"
14
+ end
15
+
16
+ def description
17
+ "Search the web for current information. Use this when you need up-to-date information " \
18
+ "that may not be in your training data, such as latest API documentation, recent changes " \
19
+ "to libraries/frameworks, current error messages, or any real-time information."
20
+ end
21
+
22
+ def parameters
23
+ {
24
+ type: "object",
25
+ properties: {
26
+ query: {
27
+ type: "string",
28
+ description: "The search query. Be specific and include version numbers or dates when relevant."
29
+ }
30
+ },
31
+ required: ["query"]
32
+ }
33
+ end
34
+
35
+ def available?
36
+ !@client.nil?
37
+ end
38
+ end
39
+
40
+ def execute(binding, query:)
41
+ client = self.class.client
42
+ model = self.class.model
43
+ return { error: "Web search not configured" } unless client
44
+
45
+ response = client.generate_content(
46
+ query,
47
+ model: model,
48
+ google_search: true
49
+ )
50
+
51
+ text = response.text || ""
52
+ sources = format_sources(response)
53
+
54
+ {
55
+ result: text,
56
+ sources: sources
57
+ }
58
+ rescue StandardError => e
59
+ { error: "Web search failed: #{e.message}" }
60
+ end
61
+
62
+ private
63
+
64
+ def format_sources(response)
65
+ return [] unless response.respond_to?(:grounded?) && response.grounded?
66
+
67
+ response.grounding_sources.map do |s|
68
+ "#{s[:title]}: #{s[:url]}"
69
+ end
70
+ rescue
71
+ []
72
+ end
73
+ end
74
+ end
75
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GirbGemini
4
- VERSION = "0.1.1"
5
- end
4
+ VERSION = "0.3.0"
5
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: girb-gemini
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - rira100000000
@@ -54,6 +54,7 @@ files:
54
54
  - lib/girb-gemini.rb
55
55
  - lib/girb-gemini/version.rb
56
56
  - lib/girb/providers/gemini.rb
57
+ - lib/girb/providers/web_search_tool.rb
57
58
  homepage: https://github.com/rira100000000/girb-gemini
58
59
  licenses:
59
60
  - MIT