geminize 0.1.1 → 1.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 +4 -4
- data/.cursor/mcp.json +3 -0
- data/.cursor/rules/isolation_rules/Core/command-execution.mdc +235 -0
- data/.cursor/rules/isolation_rules/Core/complexity-decision-tree.mdc +187 -0
- data/.cursor/rules/isolation_rules/Core/creative-phase-enforcement.mdc +145 -0
- data/.cursor/rules/isolation_rules/Core/creative-phase-metrics.mdc +195 -0
- data/.cursor/rules/isolation_rules/Core/file-verification.mdc +198 -0
- data/.cursor/rules/isolation_rules/Core/platform-awareness.mdc +71 -0
- data/.cursor/rules/isolation_rules/Level3/planning-comprehensive.mdc +159 -0
- data/.cursor/rules/isolation_rules/Level3/task-tracking-intermediate.mdc +135 -0
- data/.cursor/rules/isolation_rules/Phases/CreativePhase/creative-phase-architecture.mdc +187 -0
- data/.cursor/rules/isolation_rules/main.mdc +123 -0
- data/.cursor/rules/isolation_rules/visual-maps/archive-mode-map.mdc +277 -0
- data/.cursor/rules/isolation_rules/visual-maps/creative-mode-map.mdc +224 -0
- data/.cursor/rules/isolation_rules/visual-maps/implement-mode-map.mdc +321 -0
- data/.cursor/rules/isolation_rules/visual-maps/plan-mode-map.mdc +269 -0
- data/.cursor/rules/isolation_rules/visual-maps/qa-mode-map.mdc +495 -0
- data/.cursor/rules/isolation_rules/visual-maps/reflect-mode-map.mdc +234 -0
- data/.cursor/rules/isolation_rules/visual-maps/van-mode-map.mdc +902 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-complexity-determination.mdc +60 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-file-verification.mdc +49 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-mode-map.mdc +49 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-platform-detection.mdc +50 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/build-test.mdc +117 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/config-check.mdc +103 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/dependency-check.mdc +147 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/environment-check.mdc +104 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/file-verification.mdc +1 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-main.mdc +142 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/common-fixes.mdc +92 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/mode-transitions.mdc +101 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/reports.mdc +149 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-guide.mdc +66 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-help.mdc +19 -0
- data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-validation.md.old +363 -0
- data/.env.example +7 -0
- data/.memory_bank/activeContext.md +78 -0
- data/.memory_bank/progress.md +80 -0
- data/.memory_bank/projectbrief.md +29 -0
- data/.memory_bank/systemPatterns.md +90 -0
- data/.memory_bank/tasks.md +98 -0
- data/.memory_bank/techContext.md +73 -0
- data/.tool-versions +1 -0
- data/CHANGELOG.md +27 -1
- data/README.md +34 -98
- data/examples/README.md +7 -28
- data/examples/embeddings.rb +18 -20
- data/examples/models_api.rb +125 -0
- data/examples/multimodal.rb +9 -9
- data/lib/geminize/configuration.rb +4 -4
- data/lib/geminize/model_info.rb +87 -8
- data/lib/geminize/models/content_request.rb +1 -1
- data/lib/geminize/models/model.rb +101 -109
- data/lib/geminize/models/model_list.rb +70 -28
- data/lib/geminize/request_builder.rb +29 -0
- data/lib/geminize/version.rb +1 -1
- data/lib/geminize.rb +71 -17
- metadata +46 -20
- data/examples/rails_chat/README.md +0 -69
- data/examples/rails_chat/app/controllers/chat_controller.rb +0 -26
- data/examples/rails_chat/app/views/chat/index.html.erb +0 -112
- data/examples/rails_chat/config/routes.rb +0 -8
- data/examples/rails_initializer.rb +0 -46
- data/geminize-0.1.0.gem +0 -0
- data/lib/geminize/rails/app/controllers/concerns/geminize/controller.rb +0 -105
- data/lib/geminize/rails/app/helpers/geminize_helper.rb +0 -125
- data/lib/geminize/rails/controller_additions.rb +0 -41
- data/lib/geminize/rails/engine.rb +0 -29
- data/lib/geminize/rails/helper_additions.rb +0 -37
- data/lib/geminize/rails.rb +0 -50
- data/lib/geminize/railtie.rb +0 -33
- data/lib/generators/geminize/install_generator.rb +0 -22
- data/lib/generators/geminize/templates/README +0 -31
- data/lib/generators/geminize/templates/initializer.rb +0 -38
@@ -52,6 +52,35 @@ module Geminize
|
|
52
52
|
def build_streaming_endpoint(model_name)
|
53
53
|
build_model_endpoint(model_name, "streamGenerateContent")
|
54
54
|
end
|
55
|
+
|
56
|
+
# Build a models list request parameters
|
57
|
+
# @param page_size [Integer, nil] Number of models to return per page
|
58
|
+
# @param page_token [String, nil] Token for retrieving a specific page
|
59
|
+
# @return [Hash] The query parameters for models listing
|
60
|
+
def build_models_list_params(page_size = nil, page_token = nil)
|
61
|
+
params = {}
|
62
|
+
params[:pageSize] = page_size if page_size
|
63
|
+
params[:pageToken] = page_token if page_token
|
64
|
+
params
|
65
|
+
end
|
66
|
+
|
67
|
+
# Build a specific model endpoint for the get model info API
|
68
|
+
# @param model_name [String] The model name or ID to get info for
|
69
|
+
# @return [String] The complete API endpoint path for getting model info
|
70
|
+
def build_get_model_endpoint(model_name)
|
71
|
+
# Handle both formats: "models/gemini-1.5-pro" or just "gemini-1.5-pro"
|
72
|
+
unless model_name.start_with?("models/")
|
73
|
+
model_name = "models/#{model_name}"
|
74
|
+
end
|
75
|
+
model_name
|
76
|
+
end
|
77
|
+
|
78
|
+
# Build the endpoint for embedding generation
|
79
|
+
# @param model_name [String] The name of the model
|
80
|
+
# @return [String] The complete API endpoint path for embedding generation
|
81
|
+
def build_embedding_endpoint(model_name)
|
82
|
+
build_model_endpoint(model_name, "embedContent")
|
83
|
+
end
|
55
84
|
end
|
56
85
|
end
|
57
86
|
end
|
data/lib/geminize/version.rb
CHANGED
data/lib/geminize.rb
CHANGED
@@ -37,9 +37,6 @@ require_relative "geminize/conversation_repository"
|
|
37
37
|
require_relative "geminize/conversation_service"
|
38
38
|
require_relative "geminize/model_info"
|
39
39
|
|
40
|
-
# Conditionally load Rails integration if Rails is defined
|
41
|
-
require_relative "geminize/rails" if defined?(::Rails)
|
42
|
-
|
43
40
|
# Main module for the Geminize gem
|
44
41
|
module Geminize
|
45
42
|
class Error < StandardError; end
|
@@ -481,35 +478,92 @@ module Geminize
|
|
481
478
|
)
|
482
479
|
end
|
483
480
|
|
484
|
-
#
|
481
|
+
# List available models from the Gemini API
|
482
|
+
# @param page_size [Integer, nil] Number of models to return per page (max 1000)
|
483
|
+
# @param page_token [String, nil] Token for retrieving a specific page
|
485
484
|
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
486
485
|
# @param client_options [Hash] Options to pass to the client
|
487
486
|
# @return [Geminize::Models::ModelList] List of available models
|
488
487
|
# @raise [Geminize::GeminizeError] If the request fails
|
489
|
-
|
490
|
-
# models = Geminize.list_models
|
491
|
-
# @example Get a fresh list bypassing cache
|
492
|
-
# models = Geminize.list_models(force_refresh: true)
|
493
|
-
# @example Filter models by capability
|
494
|
-
# vision_models = Geminize.list_models.vision_models
|
495
|
-
def list_models(force_refresh: false, client_options: {})
|
488
|
+
def list_models(page_size: nil, page_token: nil, force_refresh: false, client_options: {})
|
496
489
|
validate_configuration!
|
497
490
|
model_info = ModelInfo.new(nil, client_options)
|
498
|
-
model_info.list_models(force_refresh: force_refresh)
|
491
|
+
model_info.list_models(page_size: page_size, page_token: page_token, force_refresh: force_refresh)
|
492
|
+
end
|
493
|
+
|
494
|
+
# Get all available models, handling pagination automatically
|
495
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
496
|
+
# @param client_options [Hash] Options to pass to the client
|
497
|
+
# @return [Geminize::Models::ModelList] Complete list of all available models
|
498
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
499
|
+
def list_all_models(force_refresh: false, client_options: {})
|
500
|
+
validate_configuration!
|
501
|
+
model_info = ModelInfo.new(nil, client_options)
|
502
|
+
model_info.list_all_models(force_refresh: force_refresh)
|
499
503
|
end
|
500
504
|
|
501
505
|
# Get information about a specific model
|
502
|
-
# @param
|
506
|
+
# @param model_name [String] The model name to retrieve (can be "models/gemini-1.5-pro" or just "gemini-1.5-pro")
|
503
507
|
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
504
508
|
# @param client_options [Hash] Options to pass to the client
|
505
509
|
# @return [Geminize::Models::Model] The model information
|
506
510
|
# @raise [Geminize::GeminizeError] If the request fails or model is not found
|
507
|
-
|
508
|
-
|
509
|
-
|
511
|
+
def get_model(model_name, force_refresh: false, client_options: {})
|
512
|
+
validate_configuration!
|
513
|
+
model_info = ModelInfo.new(nil, client_options)
|
514
|
+
model_info.get_model(model_name, force_refresh: force_refresh)
|
515
|
+
end
|
516
|
+
|
517
|
+
# Get models that support a specific generation method
|
518
|
+
# @param method [String] The generation method (e.g., "generateContent", "embedContent")
|
519
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
520
|
+
# @param client_options [Hash] Options to pass to the client
|
521
|
+
# @return [Geminize::Models::ModelList] List of models that support the method
|
522
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
523
|
+
def get_models_by_method(method, force_refresh: false, client_options: {})
|
510
524
|
validate_configuration!
|
511
525
|
model_info = ModelInfo.new(nil, client_options)
|
512
|
-
model_info.
|
526
|
+
model_info.get_models_by_method(method, force_refresh: force_refresh)
|
527
|
+
end
|
528
|
+
|
529
|
+
# Get models that support content generation
|
530
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
531
|
+
# @param client_options [Hash] Options to pass to the client
|
532
|
+
# @return [Geminize::Models::ModelList] List of models that support content generation
|
533
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
534
|
+
def get_content_generation_models(force_refresh: false, client_options: {})
|
535
|
+
models = list_all_models(force_refresh: force_refresh, client_options: client_options)
|
536
|
+
models.content_generation_models
|
537
|
+
end
|
538
|
+
|
539
|
+
# Get models that support embedding generation
|
540
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
541
|
+
# @param client_options [Hash] Options to pass to the client
|
542
|
+
# @return [Geminize::Models::ModelList] List of models that support embedding generation
|
543
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
544
|
+
def get_embedding_models(force_refresh: false, client_options: {})
|
545
|
+
models = list_all_models(force_refresh: force_refresh, client_options: client_options)
|
546
|
+
models.embedding_models
|
547
|
+
end
|
548
|
+
|
549
|
+
# Get models that support chat generation
|
550
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
551
|
+
# @param client_options [Hash] Options to pass to the client
|
552
|
+
# @return [Geminize::Models::ModelList] List of models that support chat generation
|
553
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
554
|
+
def get_chat_models(force_refresh: false, client_options: {})
|
555
|
+
models = list_all_models(force_refresh: force_refresh, client_options: client_options)
|
556
|
+
models.chat_models
|
557
|
+
end
|
558
|
+
|
559
|
+
# Get models that support streaming generation
|
560
|
+
# @param force_refresh [Boolean] Force a refresh from the API instead of using cache
|
561
|
+
# @param client_options [Hash] Options to pass to the client
|
562
|
+
# @return [Geminize::Models::ModelList] List of models that support streaming generation
|
563
|
+
# @raise [Geminize::GeminizeError] If the request fails
|
564
|
+
def get_streaming_models(force_refresh: false, client_options: {})
|
565
|
+
models = list_all_models(force_refresh: force_refresh, client_options: client_options)
|
566
|
+
models.streaming_models
|
513
567
|
end
|
514
568
|
|
515
569
|
# Update a conversation's system instruction
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geminize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nhat Long Nguyen
|
@@ -123,16 +123,57 @@ dependencies:
|
|
123
123
|
version: '2.8'
|
124
124
|
description: A convenient and robust Ruby interface for the Google Gemini API, enabling
|
125
125
|
easy integration of powerful generative AI models into your applications. Includes
|
126
|
-
support for text generation, chat conversations, embeddings, multimodal content
|
127
|
-
and Rails integration.
|
126
|
+
support for text generation, chat conversations, embeddings, multimodal content.
|
128
127
|
email:
|
129
128
|
- nhatlongnguyen1992@gmail.com
|
130
129
|
executables: []
|
131
130
|
extensions: []
|
132
131
|
extra_rdoc_files: []
|
133
132
|
files:
|
133
|
+
- ".cursor/mcp.json"
|
134
|
+
- ".cursor/rules/isolation_rules/Core/command-execution.mdc"
|
135
|
+
- ".cursor/rules/isolation_rules/Core/complexity-decision-tree.mdc"
|
136
|
+
- ".cursor/rules/isolation_rules/Core/creative-phase-enforcement.mdc"
|
137
|
+
- ".cursor/rules/isolation_rules/Core/creative-phase-metrics.mdc"
|
138
|
+
- ".cursor/rules/isolation_rules/Core/file-verification.mdc"
|
139
|
+
- ".cursor/rules/isolation_rules/Core/platform-awareness.mdc"
|
140
|
+
- ".cursor/rules/isolation_rules/Level3/planning-comprehensive.mdc"
|
141
|
+
- ".cursor/rules/isolation_rules/Level3/task-tracking-intermediate.mdc"
|
142
|
+
- ".cursor/rules/isolation_rules/Phases/CreativePhase/creative-phase-architecture.mdc"
|
143
|
+
- ".cursor/rules/isolation_rules/main.mdc"
|
144
|
+
- ".cursor/rules/isolation_rules/visual-maps/archive-mode-map.mdc"
|
145
|
+
- ".cursor/rules/isolation_rules/visual-maps/creative-mode-map.mdc"
|
146
|
+
- ".cursor/rules/isolation_rules/visual-maps/implement-mode-map.mdc"
|
147
|
+
- ".cursor/rules/isolation_rules/visual-maps/plan-mode-map.mdc"
|
148
|
+
- ".cursor/rules/isolation_rules/visual-maps/qa-mode-map.mdc"
|
149
|
+
- ".cursor/rules/isolation_rules/visual-maps/reflect-mode-map.mdc"
|
150
|
+
- ".cursor/rules/isolation_rules/visual-maps/van-mode-map.mdc"
|
151
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-complexity-determination.mdc"
|
152
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-file-verification.mdc"
|
153
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-mode-map.mdc"
|
154
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-platform-detection.mdc"
|
155
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/build-test.mdc"
|
156
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/config-check.mdc"
|
157
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/dependency-check.mdc"
|
158
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/environment-check.mdc"
|
159
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/file-verification.mdc"
|
160
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-main.mdc"
|
161
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/common-fixes.mdc"
|
162
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/mode-transitions.mdc"
|
163
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/reports.mdc"
|
164
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-guide.mdc"
|
165
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-help.mdc"
|
166
|
+
- ".cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-validation.md.old"
|
167
|
+
- ".env.example"
|
168
|
+
- ".memory_bank/activeContext.md"
|
169
|
+
- ".memory_bank/progress.md"
|
170
|
+
- ".memory_bank/projectbrief.md"
|
171
|
+
- ".memory_bank/systemPatterns.md"
|
172
|
+
- ".memory_bank/tasks.md"
|
173
|
+
- ".memory_bank/techContext.md"
|
134
174
|
- ".rspec"
|
135
175
|
- ".standard.yml"
|
176
|
+
- ".tool-versions"
|
136
177
|
- ".yardopts"
|
137
178
|
- CHANGELOG.md
|
138
179
|
- CODE_OF_CONDUCT.md
|
@@ -143,15 +184,10 @@ files:
|
|
143
184
|
- examples/README.md
|
144
185
|
- examples/configuration.rb
|
145
186
|
- examples/embeddings.rb
|
187
|
+
- examples/models_api.rb
|
146
188
|
- examples/multimodal.rb
|
147
|
-
- examples/rails_chat/README.md
|
148
|
-
- examples/rails_chat/app/controllers/chat_controller.rb
|
149
|
-
- examples/rails_chat/app/views/chat/index.html.erb
|
150
|
-
- examples/rails_chat/config/routes.rb
|
151
|
-
- examples/rails_initializer.rb
|
152
189
|
- examples/ruby.png
|
153
190
|
- examples/system_instructions.rb
|
154
|
-
- geminize-0.1.0.gem
|
155
191
|
- lib/geminize.rb
|
156
192
|
- lib/geminize/chat.rb
|
157
193
|
- lib/geminize/client.rb
|
@@ -176,21 +212,11 @@ files:
|
|
176
212
|
- lib/geminize/models/model.rb
|
177
213
|
- lib/geminize/models/model_list.rb
|
178
214
|
- lib/geminize/models/stream_response.rb
|
179
|
-
- lib/geminize/rails.rb
|
180
|
-
- lib/geminize/rails/app/controllers/concerns/geminize/controller.rb
|
181
|
-
- lib/geminize/rails/app/helpers/geminize_helper.rb
|
182
|
-
- lib/geminize/rails/controller_additions.rb
|
183
|
-
- lib/geminize/rails/engine.rb
|
184
|
-
- lib/geminize/rails/helper_additions.rb
|
185
|
-
- lib/geminize/railtie.rb
|
186
215
|
- lib/geminize/request_builder.rb
|
187
216
|
- lib/geminize/text_generation.rb
|
188
217
|
- lib/geminize/validators.rb
|
189
218
|
- lib/geminize/vector_utils.rb
|
190
219
|
- lib/geminize/version.rb
|
191
|
-
- lib/generators/geminize/install_generator.rb
|
192
|
-
- lib/generators/geminize/templates/README
|
193
|
-
- lib/generators/geminize/templates/initializer.rb
|
194
220
|
- sig/geminize.rbs
|
195
221
|
homepage: https://github.com/nhlongnguyen/geminize
|
196
222
|
licenses:
|
@@ -214,7 +240,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
240
|
- !ruby/object:Gem::Version
|
215
241
|
version: '0'
|
216
242
|
requirements: []
|
217
|
-
rubygems_version: 3.6.
|
243
|
+
rubygems_version: 3.6.7
|
218
244
|
specification_version: 4
|
219
245
|
summary: Ruby interface for Google's Gemini AI API
|
220
246
|
test_files: []
|
@@ -1,69 +0,0 @@
|
|
1
|
-
# Rails Chat Example
|
2
|
-
|
3
|
-
This is a basic example of how to implement a chat application with the Geminize gem in a Rails application.
|
4
|
-
|
5
|
-
## Features
|
6
|
-
|
7
|
-
- Chat interface with Google's Gemini AI
|
8
|
-
- Conversation memory between requests using Rails session
|
9
|
-
- Support for Turbo and JSON responses
|
10
|
-
- Reset conversation functionality
|
11
|
-
|
12
|
-
## Implementation
|
13
|
-
|
14
|
-
This example demonstrates:
|
15
|
-
|
16
|
-
1. How to include Geminize controller concerns
|
17
|
-
2. How to use Geminize view helpers
|
18
|
-
3. How to maintain conversation state in a Rails application
|
19
|
-
|
20
|
-
## File Structure
|
21
|
-
|
22
|
-
- `app/controllers/chat_controller.rb` - Controller with Geminize integration
|
23
|
-
- `app/views/chat/index.html.erb` - Chat interface view
|
24
|
-
- `config/routes.rb` - Routes configuration
|
25
|
-
|
26
|
-
## Setup in Your Application
|
27
|
-
|
28
|
-
1. Add Geminize to your Gemfile:
|
29
|
-
|
30
|
-
```ruby
|
31
|
-
gem 'geminize'
|
32
|
-
```
|
33
|
-
|
34
|
-
2. Run the installer:
|
35
|
-
|
36
|
-
```bash
|
37
|
-
rails generate geminize:install
|
38
|
-
```
|
39
|
-
|
40
|
-
3. Configure your API key in `config/initializers/geminize.rb`
|
41
|
-
|
42
|
-
4. Include the Geminize helpers in your `ApplicationHelper`
|
43
|
-
|
44
|
-
```ruby
|
45
|
-
module ApplicationHelper
|
46
|
-
geminize_helper
|
47
|
-
end
|
48
|
-
```
|
49
|
-
|
50
|
-
5. Create your controller with Geminize support
|
51
|
-
|
52
|
-
```ruby
|
53
|
-
class YourChatController < ApplicationController
|
54
|
-
geminize_controller
|
55
|
-
|
56
|
-
# ... your controller actions
|
57
|
-
end
|
58
|
-
```
|
59
|
-
|
60
|
-
6. Use the helper methods in your views
|
61
|
-
|
62
|
-
```erb
|
63
|
-
<%= render_gemini_conversation %>
|
64
|
-
<%= gemini_chat_form %>
|
65
|
-
```
|
66
|
-
|
67
|
-
## Styling
|
68
|
-
|
69
|
-
This example includes basic CSS to style the chat interface. Feel free to customize it to match your application's design.
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
class ChatController < ApplicationController
|
4
|
-
# Include Geminize controller functionality
|
5
|
-
geminize_controller
|
6
|
-
|
7
|
-
def index
|
8
|
-
# Reset conversation if requested
|
9
|
-
reset_gemini_conversation("Chat with Gemini") if params[:reset]
|
10
|
-
end
|
11
|
-
|
12
|
-
def create
|
13
|
-
@response = send_gemini_message(params[:message])
|
14
|
-
|
15
|
-
respond_to do |format|
|
16
|
-
format.html { redirect_to chat_path }
|
17
|
-
format.turbo_stream
|
18
|
-
format.json { render json: {message: @response.text} }
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
def reset
|
23
|
-
reset_gemini_conversation("New Chat Session")
|
24
|
-
redirect_to chat_path, notice: "Started a new conversation"
|
25
|
-
end
|
26
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
<%# Chat index view %>
|
2
|
-
<div class="chat-container">
|
3
|
-
<div class="chat-header">
|
4
|
-
<h1>Chat with Gemini</h1>
|
5
|
-
<%= link_to "Start New Chat", reset_chat_path, class: "new-chat-button", data: { turbo_method: :post } %>
|
6
|
-
</div>
|
7
|
-
|
8
|
-
<div class="conversation-container">
|
9
|
-
<div class="conversation">
|
10
|
-
<%= render_gemini_conversation(nil, include_timestamps: true) %>
|
11
|
-
</div>
|
12
|
-
</div>
|
13
|
-
|
14
|
-
<div class="chat-form-container">
|
15
|
-
<%= gemini_chat_form(
|
16
|
-
placeholder: "Ask me anything...",
|
17
|
-
submit_text: "Send",
|
18
|
-
form_class: "chat-form",
|
19
|
-
input_class: "chat-input",
|
20
|
-
submit_class: "chat-submit"
|
21
|
-
) %>
|
22
|
-
</div>
|
23
|
-
</div>
|
24
|
-
|
25
|
-
<% content_for :styles do %>
|
26
|
-
<style>
|
27
|
-
.chat-container {
|
28
|
-
max-width: 800px;
|
29
|
-
margin: 0 auto;
|
30
|
-
padding: 20px;
|
31
|
-
font-family: system-ui, -apple-system, sans-serif;
|
32
|
-
}
|
33
|
-
|
34
|
-
.chat-header {
|
35
|
-
display: flex;
|
36
|
-
justify-content: space-between;
|
37
|
-
align-items: center;
|
38
|
-
margin-bottom: 20px;
|
39
|
-
}
|
40
|
-
|
41
|
-
.new-chat-button {
|
42
|
-
background: #6200ee;
|
43
|
-
color: white;
|
44
|
-
padding: 8px 16px;
|
45
|
-
border-radius: 4px;
|
46
|
-
text-decoration: none;
|
47
|
-
}
|
48
|
-
|
49
|
-
.conversation-container {
|
50
|
-
height: 400px;
|
51
|
-
overflow-y: auto;
|
52
|
-
border: 1px solid #e0e0e0;
|
53
|
-
border-radius: 8px;
|
54
|
-
margin-bottom: 20px;
|
55
|
-
padding: 16px;
|
56
|
-
background: #f8f9fa;
|
57
|
-
}
|
58
|
-
|
59
|
-
.gemini-message {
|
60
|
-
margin-bottom: 16px;
|
61
|
-
padding: 12px;
|
62
|
-
border-radius: 8px;
|
63
|
-
}
|
64
|
-
|
65
|
-
.gemini-user-message {
|
66
|
-
background: #e3f2fd;
|
67
|
-
margin-left: 20px;
|
68
|
-
}
|
69
|
-
|
70
|
-
.gemini-ai-message {
|
71
|
-
background: #f1f3f4;
|
72
|
-
margin-right: 20px;
|
73
|
-
}
|
74
|
-
|
75
|
-
.gemini-message-role {
|
76
|
-
font-weight: bold;
|
77
|
-
margin-bottom: 8px;
|
78
|
-
}
|
79
|
-
|
80
|
-
.gemini-message-timestamp {
|
81
|
-
font-size: 0.8em;
|
82
|
-
color: #666;
|
83
|
-
margin-top: 8px;
|
84
|
-
text-align: right;
|
85
|
-
}
|
86
|
-
|
87
|
-
.chat-form {
|
88
|
-
display: flex;
|
89
|
-
gap: 8px;
|
90
|
-
}
|
91
|
-
|
92
|
-
.chat-input {
|
93
|
-
flex: 1;
|
94
|
-
padding: 12px;
|
95
|
-
border: 1px solid #e0e0e0;
|
96
|
-
border-radius: 4px;
|
97
|
-
font-family: inherit;
|
98
|
-
resize: none;
|
99
|
-
height: 80px;
|
100
|
-
}
|
101
|
-
|
102
|
-
.chat-submit {
|
103
|
-
background: #6200ee;
|
104
|
-
color: white;
|
105
|
-
border: none;
|
106
|
-
padding: 12px 24px;
|
107
|
-
border-radius: 4px;
|
108
|
-
cursor: pointer;
|
109
|
-
align-self: flex-end;
|
110
|
-
}
|
111
|
-
</style>
|
112
|
-
<% end %>
|
@@ -1,46 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# config/initializers/geminize.rb
|
4
|
-
|
5
|
-
# This is an example of how to configure the Geminize gem in a Rails application.
|
6
|
-
# Place this file in your config/initializers directory.
|
7
|
-
|
8
|
-
# Configure the Geminize gem with your API key and any other settings
|
9
|
-
Geminize.configure do |config|
|
10
|
-
# Required settings
|
11
|
-
|
12
|
-
# Get the API key from environment variables (recommended approach)
|
13
|
-
# config.api_key = ENV["GEMINI_API_KEY"]
|
14
|
-
|
15
|
-
# Or set it directly (not recommended for production)
|
16
|
-
config.api_key = "your-api-key-here"
|
17
|
-
|
18
|
-
# Optional settings with defaults
|
19
|
-
|
20
|
-
# API version to use
|
21
|
-
config.api_version = "v1beta"
|
22
|
-
|
23
|
-
# Default model to use when not specified in requests
|
24
|
-
config.default_model = "gemini-1.5-pro-latest"
|
25
|
-
|
26
|
-
# Request timeout in seconds
|
27
|
-
config.timeout = 30
|
28
|
-
|
29
|
-
# Connection open timeout in seconds
|
30
|
-
config.open_timeout = 10
|
31
|
-
|
32
|
-
# Enable request logging for development/debugging
|
33
|
-
# In production, keep this false unless debugging an issue
|
34
|
-
config.log_requests = Rails.env.development?
|
35
|
-
end
|
36
|
-
|
37
|
-
# Optionally validate the configuration during app initialization
|
38
|
-
# This will raise Geminize::ConfigurationError if the configuration is invalid
|
39
|
-
begin
|
40
|
-
Geminize.validate_configuration!
|
41
|
-
Rails.logger.info "Geminize configured successfully"
|
42
|
-
rescue Geminize::ConfigurationError => e
|
43
|
-
Rails.logger.error "Geminize configuration error: #{e.message}"
|
44
|
-
# You might want to raise the error in development but not in production
|
45
|
-
raise e if Rails.env.development?
|
46
|
-
end
|
data/geminize-0.1.0.gem
DELETED
Binary file
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Geminize
|
4
|
-
# Controller concern for including Gemini functionality in Rails controllers
|
5
|
-
module Controller
|
6
|
-
extend ActiveSupport::Concern
|
7
|
-
|
8
|
-
included do
|
9
|
-
# Helper methods for controllers using Geminize
|
10
|
-
helper_method :current_gemini_conversation if respond_to?(:helper_method)
|
11
|
-
end
|
12
|
-
|
13
|
-
# Current conversation for this controller context
|
14
|
-
# Uses session to maintain conversation state between requests
|
15
|
-
# @return [Geminize::Models::Conversation]
|
16
|
-
def current_gemini_conversation
|
17
|
-
return @current_gemini_conversation if defined?(@current_gemini_conversation)
|
18
|
-
|
19
|
-
if session[:gemini_conversation_id]
|
20
|
-
# Try to load existing conversation
|
21
|
-
begin
|
22
|
-
@current_gemini_conversation = Geminize.load_conversation(session[:gemini_conversation_id])
|
23
|
-
rescue => e
|
24
|
-
Rails.logger.error("Failed to load Gemini conversation: #{e.message}")
|
25
|
-
# Create a new conversation if loading fails
|
26
|
-
create_new_gemini_conversation
|
27
|
-
end
|
28
|
-
else
|
29
|
-
# Create a new conversation if one doesn't exist
|
30
|
-
create_new_gemini_conversation
|
31
|
-
end
|
32
|
-
|
33
|
-
@current_gemini_conversation
|
34
|
-
end
|
35
|
-
|
36
|
-
# Send a message in the current conversation
|
37
|
-
# @param message [String] The message to send
|
38
|
-
# @param model_name [String, nil] Optional model name override
|
39
|
-
# @param params [Hash] Additional parameters for the message
|
40
|
-
# @return [Geminize::Models::ChatResponse] The response
|
41
|
-
def send_gemini_message(message, model_name = nil, params = {})
|
42
|
-
response = Geminize.chat(message, current_gemini_conversation, model_name, params)
|
43
|
-
Geminize.save_conversation(current_gemini_conversation)
|
44
|
-
response
|
45
|
-
end
|
46
|
-
|
47
|
-
# Generate text using Gemini
|
48
|
-
# @param prompt [String] The prompt to send
|
49
|
-
# @param model_name [String, nil] Optional model name override
|
50
|
-
# @param params [Hash] Additional parameters for generation
|
51
|
-
# @return [Geminize::Models::ContentResponse] The response
|
52
|
-
def generate_gemini_text(prompt, model_name = nil, params = {})
|
53
|
-
Geminize.generate_text(prompt, model_name, params)
|
54
|
-
end
|
55
|
-
|
56
|
-
# Generate text with images using Gemini
|
57
|
-
# @param prompt [String] The prompt to send
|
58
|
-
# @param images [Array<Hash>] Array of image data
|
59
|
-
# @param model_name [String, nil] Optional model name override
|
60
|
-
# @param params [Hash] Additional parameters for generation
|
61
|
-
# @return [Geminize::Models::ContentResponse] The response
|
62
|
-
def generate_gemini_multimodal(prompt, images, model_name = nil, params = {})
|
63
|
-
Geminize.generate_text_multimodal(prompt, images, model_name, params)
|
64
|
-
end
|
65
|
-
|
66
|
-
# Generate embeddings for text using Gemini
|
67
|
-
# @param text [String, Array<String>] The text to embed
|
68
|
-
# @param model_name [String, nil] Optional model name override
|
69
|
-
# @param params [Hash] Additional parameters for embedding
|
70
|
-
# @return [Geminize::Models::EmbeddingResponse] The embedding response
|
71
|
-
def generate_gemini_embedding(text, model_name = nil, params = {})
|
72
|
-
Geminize.generate_embedding(text, model_name, params)
|
73
|
-
end
|
74
|
-
|
75
|
-
# Start a new conversation and store its ID in the session
|
76
|
-
# @param title [String, nil] Optional title for the conversation
|
77
|
-
# @param system_instruction [String, nil] Optional system instruction to guide model behavior
|
78
|
-
# @return [Geminize::Models::Conversation] The new conversation
|
79
|
-
def reset_gemini_conversation(title = nil, system_instruction = nil)
|
80
|
-
create_new_gemini_conversation(title, system_instruction)
|
81
|
-
end
|
82
|
-
|
83
|
-
# Set the system instruction for the current conversation
|
84
|
-
# @param system_instruction [String] The system instruction to set
|
85
|
-
# @return [Geminize::Models::Conversation] The updated conversation
|
86
|
-
def set_gemini_system_instruction(system_instruction)
|
87
|
-
current_gemini_conversation.system_instruction = system_instruction
|
88
|
-
Geminize.save_conversation(current_gemini_conversation)
|
89
|
-
current_gemini_conversation
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
# Create a new conversation and store its ID in the session
|
95
|
-
# @param title [String, nil] Optional title for the conversation
|
96
|
-
# @param system_instruction [String, nil] Optional system instruction to guide model behavior
|
97
|
-
# @return [Geminize::Models::Conversation] The new conversation
|
98
|
-
def create_new_gemini_conversation(title = nil, system_instruction = nil)
|
99
|
-
@current_gemini_conversation = Geminize.create_chat(title, system_instruction)
|
100
|
-
session[:gemini_conversation_id] = @current_gemini_conversation.id
|
101
|
-
Geminize.save_conversation(@current_gemini_conversation)
|
102
|
-
@current_gemini_conversation
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|