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
@@ -0,0 +1,98 @@
|
|
1
|
+
# Tasks
|
2
|
+
|
3
|
+
## Current Tasks
|
4
|
+
|
5
|
+
### Documentation
|
6
|
+
|
7
|
+
- [ ] Review and improve YARD documentation
|
8
|
+
- [ ] Add more code examples
|
9
|
+
- [ ] Update README with latest features
|
10
|
+
- [ ] Create diagrams for architecture overview
|
11
|
+
|
12
|
+
### Feature Development
|
13
|
+
|
14
|
+
- [ ] Support for new Gemini models as they become available
|
15
|
+
- [ ] Add support for function calling capabilities
|
16
|
+
- [ ] Implement batch embedding generation
|
17
|
+
- [ ] Improve conversation persistence with adapter pattern for multiple storage options
|
18
|
+
- [ ] **Models API Integration**:
|
19
|
+
- [x] Enhance `model_info.rb` to support full model metadata
|
20
|
+
- [x] Update/create `Models::Model` class to match API response structure
|
21
|
+
- [x] Implement `Models::ModelList` class for handling paginated results
|
22
|
+
- [x] Add methods to `RequestBuilder` for models endpoints
|
23
|
+
- [x] Add client methods for models endpoints
|
24
|
+
- [x] Add convenience methods to main Geminize module
|
25
|
+
- [x] Implement helper methods for model capability filtering
|
26
|
+
- [x] Add comprehensive tests for models functionality
|
27
|
+
- [x] Update documentation with models API examples
|
28
|
+
|
29
|
+
### Testing
|
30
|
+
|
31
|
+
- [ ] Expand test coverage
|
32
|
+
- [ ] Add integration tests for streaming
|
33
|
+
- [ ] Update VCR cassettes with latest API responses
|
34
|
+
- [ ] Add benchmarks for performance testing
|
35
|
+
|
36
|
+
### Improvements
|
37
|
+
|
38
|
+
- [ ] Optimize streaming buffer management
|
39
|
+
- [ ] Enhance error messages with more context
|
40
|
+
- [ ] Reduce memory footprint for large responses
|
41
|
+
- [ ] Add telemetry options for tracking API usage
|
42
|
+
|
43
|
+
### Bug Fixes
|
44
|
+
|
45
|
+
- [ ] Fix potential memory leak in streaming implementation
|
46
|
+
- [ ] Address timeout handling edge cases
|
47
|
+
- [ ] Improve error handling for network failures
|
48
|
+
- [ ] Fix MIME type detection for unusual file extensions
|
49
|
+
|
50
|
+
## Completed Tasks
|
51
|
+
|
52
|
+
### Core Implementation
|
53
|
+
|
54
|
+
- [x] Basic client implementation
|
55
|
+
- [x] Text generation support
|
56
|
+
- [x] Chat conversation support
|
57
|
+
- [x] Embeddings generation
|
58
|
+
- [x] Streaming response handling
|
59
|
+
- [x] Models API Integration
|
60
|
+
|
61
|
+
### Documentation
|
62
|
+
|
63
|
+
- [x] Initial README with examples
|
64
|
+
- [x] YARD documentation for public methods
|
65
|
+
- [x] Example scripts
|
66
|
+
|
67
|
+
### Testing
|
68
|
+
|
69
|
+
- [x] Basic test suite with RSpec
|
70
|
+
- [x] VCR setup for API mocking
|
71
|
+
- [x] Unit tests for core functionality
|
72
|
+
|
73
|
+
### Error Handling
|
74
|
+
|
75
|
+
- [x] Error class hierarchy
|
76
|
+
- [x] API error mapping
|
77
|
+
- [x] Input validation
|
78
|
+
|
79
|
+
## Backlog
|
80
|
+
|
81
|
+
### Features
|
82
|
+
|
83
|
+
- [ ] Rails integration improvements
|
84
|
+
- [ ] Async API support
|
85
|
+
- [ ] Advanced vector operations
|
86
|
+
- [ ] Batch processing for multiple requests
|
87
|
+
- [ ] CLI tool for quick testing
|
88
|
+
- [ ] Models API enhancements:
|
89
|
+
- [ ] Caching model information to reduce API calls
|
90
|
+
- [ ] Smart model selection based on input requirements
|
91
|
+
- [ ] Model comparison utilities
|
92
|
+
|
93
|
+
### Optimizations
|
94
|
+
|
95
|
+
- [ ] Reduce API call overhead
|
96
|
+
- [ ] Implement request compression
|
97
|
+
- [ ] Add response caching
|
98
|
+
- [ ] Improve retry strategies
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Technical Context
|
2
|
+
|
3
|
+
## Core Architecture
|
4
|
+
|
5
|
+
The Geminize gem follows a modular architecture with clear separation of concerns:
|
6
|
+
|
7
|
+
### Main Components
|
8
|
+
|
9
|
+
- **Client**: HTTP communication with the Gemini API
|
10
|
+
- **TextGeneration**: Text generation functionality
|
11
|
+
- **Embeddings**: Vector representation generation
|
12
|
+
- **Chat**: Conversation management
|
13
|
+
- **Models**: Data structures for requests/responses
|
14
|
+
- **Middleware**: Request processing pipeline
|
15
|
+
- **Configuration**: Environment and runtime configuration
|
16
|
+
|
17
|
+
## Key Technologies
|
18
|
+
|
19
|
+
- **Ruby 3.1+**: Modern Ruby language features
|
20
|
+
- **Faraday**: HTTP client library for API communication
|
21
|
+
- **Faraday-Retry**: Retry mechanism for transient failures
|
22
|
+
- **MIME-Types**: MIME type detection for multimodal content
|
23
|
+
- **JSON**: Data serialization and parsing
|
24
|
+
|
25
|
+
## Code Organization
|
26
|
+
|
27
|
+
```
|
28
|
+
lib/geminize/
|
29
|
+
├── client.rb # HTTP client implementation
|
30
|
+
├── configuration.rb # Configuration management
|
31
|
+
├── text_generation.rb # Text generation functionality
|
32
|
+
├── chat.rb # Chat conversation handling
|
33
|
+
├── embeddings.rb # Embedding vector generation
|
34
|
+
├── conversation_service.rb # Conversation state management
|
35
|
+
├── request_builder.rb # API request construction
|
36
|
+
├── vector_utils.rb # Vector manipulation utilities
|
37
|
+
├── validators.rb # Input validation functions
|
38
|
+
├── errors.rb # Error class definitions
|
39
|
+
├── error_mapper.rb # API error mapping
|
40
|
+
├── error_parser.rb # Error response parsing
|
41
|
+
├── models/ # Data models
|
42
|
+
│ ├── content_request.rb # Text generation request
|
43
|
+
│ ├── content_response.rb # API response data structure
|
44
|
+
│ ├── embedding_request.rb # Embedding generation request
|
45
|
+
│ ├── embedding_response.rb # Vector embedding response
|
46
|
+
│ ├── conversation.rb # Conversation state
|
47
|
+
│ ├── message.rb # Chat message structure
|
48
|
+
│ └── ...
|
49
|
+
└── middleware/ # Request processing middleware
|
50
|
+
└── error_handler.rb # Error handling middleware
|
51
|
+
```
|
52
|
+
|
53
|
+
## Dependencies
|
54
|
+
|
55
|
+
- **Runtime Dependencies**:
|
56
|
+
|
57
|
+
- faraday (~> 2.0)
|
58
|
+
- faraday-retry (~> 2.0)
|
59
|
+
- mime-types (~> 3.5)
|
60
|
+
|
61
|
+
- **Development Dependencies**:
|
62
|
+
- rspec (~> 3.0)
|
63
|
+
- standard (~> 1.3)
|
64
|
+
- vcr (~> 6.0)
|
65
|
+
- webmock (~> 3.14)
|
66
|
+
- dotenv (~> 2.8)
|
67
|
+
|
68
|
+
## Configuration Approaches
|
69
|
+
|
70
|
+
- Environment variables (GEMINI_API_KEY)
|
71
|
+
- Dotenv integration (.env file loading)
|
72
|
+
- Programmatic configuration via block syntax
|
73
|
+
- Default configuration with override options
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.3.4
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,30 @@
|
|
1
|
-
## [
|
1
|
+
## [1.1.0] - 2025-05-02
|
2
|
+
|
3
|
+
### Added
|
4
|
+
|
5
|
+
- Comprehensive Models API for discovering and filtering Gemini models
|
6
|
+
- Added `list_models` and `list_all_models` methods for retrieving available models
|
7
|
+
- Added `get_model` method for fetching specific model details
|
8
|
+
- Added filtering methods to find models by capability:
|
9
|
+
- `get_content_generation_models`
|
10
|
+
- `get_embedding_models`
|
11
|
+
- `get_chat_models`
|
12
|
+
- `get_streaming_models`
|
13
|
+
- Added `get_models_by_method` to filter by specific generation methods
|
14
|
+
- Extended `ModelList` class with comprehensive filtering capabilities
|
15
|
+
- Added model capability inspection methods
|
16
|
+
- Implemented pagination support for model listing
|
17
|
+
- Added caching for model information to reduce API calls
|
18
|
+
- Added comprehensive VCR tests for Models API functionality
|
19
|
+
- Updated documentation with Models API examples
|
20
|
+
|
21
|
+
## [1.0.0] - 2025-05-02
|
22
|
+
|
23
|
+
### Removed
|
24
|
+
|
25
|
+
- Removed Rails-related integration from the gem, simplifying usage.
|
26
|
+
|
27
|
+
## [0.1.1] - 2025-05-01
|
2
28
|
|
3
29
|
### Added
|
4
30
|
|
data/README.md
CHANGED
@@ -11,7 +11,7 @@ A convenient and robust Ruby interface for the Google Gemini API, enabling easy
|
|
11
11
|
- Embeddings generation
|
12
12
|
- Support for streaming responses
|
13
13
|
- Comprehensive error handling
|
14
|
-
-
|
14
|
+
- Complete Models API for discovering and filtering available models
|
15
15
|
|
16
16
|
## Installation
|
17
17
|
|
@@ -57,11 +57,8 @@ GOOGLE_AI_API_KEY=your_api_key_here
|
|
57
57
|
|
58
58
|
# API Configuration
|
59
59
|
GOOGLE_AI_API_VERSION=v1beta
|
60
|
-
|
61
|
-
|
62
|
-
# Generation Parameters
|
63
|
-
GEMINI_TEMPERATURE=0.7
|
64
|
-
GEMINI_MAX_TOKENS=8192
|
60
|
+
GEMINI_MODEL=gemini-2.0-flash
|
61
|
+
GEMINI_EMBEDDING_MODEL=gemini-embedding-exp-03-07
|
65
62
|
```
|
66
63
|
|
67
64
|
2. Add `.env` to your `.gitignore` file to keep your API keys secure:
|
@@ -311,120 +308,59 @@ end
|
|
311
308
|
puts "\n" # Add a newline after streaming
|
312
309
|
```
|
313
310
|
|
314
|
-
|
311
|
+
Check out these example applications to see Geminize in action:
|
315
312
|
|
316
|
-
|
313
|
+
- [Configuration Example](examples/configuration.rb)
|
314
|
+
- [Embeddings Example](examples/embeddings.rb)
|
315
|
+
- [Multimodal Example](examples/multimodal.rb)
|
316
|
+
- [System Instructions Example](examples/system_instructions.rb)
|
317
|
+
- [Models API Example](examples/models_api.rb)
|
317
318
|
|
318
|
-
|
319
|
+
## Working with Models
|
319
320
|
|
320
|
-
|
321
|
+
Geminize provides a comprehensive API for querying and working with available Gemini models:
|
321
322
|
|
322
323
|
```ruby
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
2. Run the installer generator:
|
327
|
-
|
328
|
-
```bash
|
329
|
-
rails generate geminize:install
|
330
|
-
```
|
331
|
-
|
332
|
-
This creates a configuration initializer at `config/initializers/geminize.rb`
|
333
|
-
|
334
|
-
3. Add your API key to the initializer or via environment variables.
|
335
|
-
|
336
|
-
### Controller Integration
|
324
|
+
require 'geminize'
|
325
|
+
# Assumes API key is set via environment variables (e.g., in .env)
|
337
326
|
|
338
|
-
|
327
|
+
# List available models
|
328
|
+
models = Geminize.list_models
|
329
|
+
puts "Available models: #{models.size}"
|
339
330
|
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
def index
|
346
|
-
# Optionally reset the conversation
|
347
|
-
# reset_gemini_conversation("New chat session") if params[:reset]
|
348
|
-
end
|
331
|
+
# Get details about a specific model
|
332
|
+
model = Geminize.get_model("gemini-1.5-pro")
|
333
|
+
puts "Model: #{model.display_name}"
|
334
|
+
puts "Token limits: #{model.input_token_limit} input, #{model.output_token_limit} output"
|
349
335
|
|
350
|
-
|
351
|
-
|
352
|
-
|
336
|
+
# Find models by capability
|
337
|
+
embedding_models = Geminize.get_embedding_models
|
338
|
+
content_models = Geminize.get_content_generation_models
|
339
|
+
streaming_models = Geminize.get_streaming_models
|
353
340
|
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
format.json { render json: { message: @response.text } }
|
358
|
-
end
|
359
|
-
end
|
341
|
+
# Check if a model supports a specific capability
|
342
|
+
if model.supports_content_generation?
|
343
|
+
puts "This model supports content generation"
|
360
344
|
end
|
361
|
-
```
|
362
|
-
|
363
|
-
The concern provides the following methods:
|
364
|
-
|
365
|
-
- `current_gemini_conversation` - Access the current conversation (stored in session)
|
366
|
-
- `send_gemini_message(message, model_name=nil, params={})` - Send a message in the current conversation
|
367
|
-
- `generate_gemini_text(prompt, model_name=nil, params={})` - Generate text with Gemini
|
368
|
-
- `generate_gemini_multimodal(prompt, images, model_name=nil, params={})` - Generate text with images
|
369
|
-
- `generate_gemini_embedding(text, model_name=nil, params={})` - Generate embeddings
|
370
|
-
- `reset_gemini_conversation(title=nil)` - Start a new conversation
|
371
|
-
|
372
|
-
### View Integration
|
373
345
|
|
374
|
-
|
375
|
-
|
376
|
-
```ruby
|
377
|
-
# In app/helpers/application_helper.rb
|
378
|
-
module ApplicationHelper
|
379
|
-
# Include Geminize view helpers
|
380
|
-
geminize_helper
|
346
|
+
if model.supports_embedding?
|
347
|
+
puts "This model supports embeddings"
|
381
348
|
end
|
382
|
-
```
|
383
|
-
|
384
|
-
This provides the following helper methods:
|
385
|
-
|
386
|
-
- `render_gemini_conversation(conversation=nil, options={})` - Render the conversation as HTML
|
387
|
-
- `render_gemini_message(message, options={})` - Render a single message
|
388
|
-
- `gemini_chat_form(options={})` - Create a chat form
|
389
|
-
- `markdown_to_html(text, options={})` - Render Markdown as HTML (requires redcarpet gem)
|
390
|
-
- `highlight_code(html)` - Add syntax highlighting to code blocks (requires rouge gem)
|
391
349
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
<%# app/views/chat/index.html.erb %>
|
396
|
-
<div class="chat-container">
|
397
|
-
<h1>Chat with Gemini</h1>
|
398
|
-
|
399
|
-
<div class="conversation">
|
400
|
-
<%= render_gemini_conversation %>
|
401
|
-
</div>
|
402
|
-
|
403
|
-
<div class="chat-form">
|
404
|
-
<%= gemini_chat_form(placeholder: "Ask me anything...", submit_text: "Send") %>
|
405
|
-
</div>
|
406
|
-
</div>
|
350
|
+
# Find models with high context windows
|
351
|
+
high_context_models = Geminize.list_all_models.filter_by_min_input_tokens(100_000)
|
352
|
+
puts "Models with 100k+ context: #{high_context_models.map(&:id).join(', ')}"
|
407
353
|
```
|
408
354
|
|
409
|
-
|
410
|
-
|
411
|
-
Check out these example applications to see Geminize in action:
|
412
|
-
|
413
|
-
- [Configuration Example](examples/configuration.rb)
|
414
|
-
- [Embeddings Example](examples/embeddings.rb)
|
415
|
-
- [Multimodal Example](examples/multimodal.rb)
|
416
|
-
- [Rails Initializer Example](examples/rails_initializer.rb)
|
417
|
-
- [System Instructions Example](examples/system_instructions.rb)
|
418
|
-
- [Rails Chat Application](examples/rails_chat)
|
355
|
+
For more comprehensive examples, see [examples/models_api.rb](examples/models_api.rb).
|
419
356
|
|
420
357
|
## Compatibility
|
421
358
|
|
422
359
|
Ruby version: 3.1.0 or later
|
423
|
-
Rails version: 6.0 or later (for Rails integration)
|
424
360
|
|
425
361
|
## Development
|
426
362
|
|
427
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `
|
363
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
428
364
|
|
429
365
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
430
366
|
|
data/examples/README.md
CHANGED
@@ -11,10 +11,9 @@ Before running these examples, ensure you have:
|
|
11
11
|
3. **Project dependencies installed**: Run `bundle install` from the project root directory (`../`).
|
12
12
|
4. **Google Gemini API Key configured**: Create a `.env` file in the project root (`../`) by copying `.env.example` and adding your API key:
|
13
13
|
```bash
|
14
|
-
# In
|
15
|
-
|
14
|
+
# In .env
|
15
|
+
GEMINI_API_KEY=your_api_key_here
|
16
16
|
```
|
17
|
-
Alternatively, ensure the `GEMINI_API_KEY` environment variable is set.
|
18
17
|
|
19
18
|
## Running Examples
|
20
19
|
|
@@ -25,7 +24,7 @@ All examples should be run from the **project root directory** (the directory co
|
|
25
24
|
Demonstrates different ways to configure the Geminize client.
|
26
25
|
|
27
26
|
```bash
|
28
|
-
ruby examples/configuration.rb
|
27
|
+
bundle exec ruby examples/configuration.rb
|
29
28
|
```
|
30
29
|
|
31
30
|
### 2. Embeddings (`embeddings.rb`)
|
@@ -33,7 +32,7 @@ ruby examples/configuration.rb
|
|
33
32
|
Shows how to generate text embeddings and calculate cosine similarity.
|
34
33
|
|
35
34
|
```bash
|
36
|
-
ruby examples/embeddings.rb
|
35
|
+
bundle exec ruby examples/embeddings.rb
|
37
36
|
```
|
38
37
|
|
39
38
|
### 3. Multimodal (`multimodal.rb`)
|
@@ -43,33 +42,13 @@ Illustrates sending text and image inputs to the Gemini API.
|
|
43
42
|
_Note: You may need to update the image file paths within the script (`path/to/image.jpg`) to point to actual image files on your system._
|
44
43
|
|
45
44
|
```bash
|
46
|
-
ruby examples/multimodal.rb
|
45
|
+
bundle exec ruby examples/multimodal.rb
|
47
46
|
```
|
48
47
|
|
49
|
-
### 4.
|
50
|
-
|
51
|
-
Shows the configuration structure typically used in a Rails initializer (this script is meant for illustration and doesn't require a Rails app to run).
|
52
|
-
|
53
|
-
```bash
|
54
|
-
ruby examples/rails_initializer.rb
|
55
|
-
```
|
56
|
-
|
57
|
-
### 5. System Instructions (`system_instructions.rb`)
|
48
|
+
### 4. System Instructions (`system_instructions.rb`)
|
58
49
|
|
59
50
|
Demonstrates using system instructions to guide the model's behavior and personality.
|
60
51
|
|
61
52
|
```bash
|
62
|
-
ruby examples/system_instructions.rb
|
53
|
+
bundle exec ruby examples/system_instructions.rb
|
63
54
|
```
|
64
|
-
|
65
|
-
### 6. Rails Chat Application (`rails_chat/`)
|
66
|
-
|
67
|
-
This directory contains a sample Rails application demonstrating Geminize integration. It requires a separate setup:
|
68
|
-
|
69
|
-
1. Navigate into the directory: `cd examples/rails_chat`
|
70
|
-
2. Install dependencies: `bundle install`
|
71
|
-
3. Run database migrations (if applicable): `rails db:migrate`
|
72
|
-
4. Start the Rails server: `rails server`
|
73
|
-
5. Open your web browser to `http://localhost:3000`
|
74
|
-
|
75
|
-
Refer to the README within the `rails_chat/` directory (if available) for more specific instructions.
|
data/examples/embeddings.rb
CHANGED
@@ -55,7 +55,6 @@ begin
|
|
55
55
|
|
56
56
|
puts "\nGenerated #{embeddings.size} embeddings."
|
57
57
|
puts "Total tokens (approximated by summing individual calls): #{total_tokens}"
|
58
|
-
|
59
58
|
rescue => e
|
60
59
|
puts "Error: #{e.message}"
|
61
60
|
end
|
@@ -85,25 +84,24 @@ end
|
|
85
84
|
puts "\n============================================================"
|
86
85
|
puts "Example 4: Batch processing for large arrays (COMMENTED OUT)"
|
87
86
|
puts "============================================================"
|
88
|
-
|
89
|
-
begin
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
rescue => e
|
104
|
-
|
105
|
-
end
|
106
|
-
=end
|
87
|
+
# # Commenting out Example 4 due to potential model/API limitations with batching
|
88
|
+
# begin
|
89
|
+
# # Create a larger array of texts
|
90
|
+
# many_texts = Array.new(120) { |i| "This is sample text number #{i}" }
|
91
|
+
#
|
92
|
+
# # Generate embeddings with automatic batch processing
|
93
|
+
# response = Geminize.generate_embedding(
|
94
|
+
# many_texts,
|
95
|
+
# nil, # Use default model
|
96
|
+
# batch_size: 40 # Process in batches of 40 texts each
|
97
|
+
# )
|
98
|
+
#
|
99
|
+
# puts "Generated embeddings for #{response.batch_size} texts"
|
100
|
+
# puts "First text embedding dimensions: #{response.embedding_size}"
|
101
|
+
# puts "Total tokens processed: #{response.total_tokens}"
|
102
|
+
# rescue => e
|
103
|
+
# puts "Error: #{e.message}"
|
104
|
+
# end
|
107
105
|
puts "# Example 4 skipped due to potential issues with batch embedding support."
|
108
106
|
|
109
107
|
puts "\n============================================================"
|
@@ -0,0 +1,125 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "geminize"
|
6
|
+
require "pp"
|
7
|
+
|
8
|
+
# Configure the library with your API key
|
9
|
+
Geminize.configure do |config|
|
10
|
+
# Load API key from .env file or environment variables
|
11
|
+
config.api_key = ENV["GEMINI_API_KEY"]
|
12
|
+
# Use the latest API version
|
13
|
+
config.api_version = "v1beta"
|
14
|
+
end
|
15
|
+
|
16
|
+
# Helper method to display model information
|
17
|
+
def display_model(model)
|
18
|
+
puts "========================"
|
19
|
+
puts "Model: #{model.display_name} (#{model.name})"
|
20
|
+
puts "Base Model ID: #{model.base_model_id}"
|
21
|
+
puts "Version: #{model.version}"
|
22
|
+
puts "Description: #{model.description}"
|
23
|
+
puts "Input Token Limit: #{model.input_token_limit}"
|
24
|
+
puts "Output Token Limit: #{model.output_token_limit}"
|
25
|
+
puts "Temperature: #{model.temperature}"
|
26
|
+
puts "Max Temperature: #{model.max_temperature}"
|
27
|
+
puts "Top P: #{model.top_p}"
|
28
|
+
puts "Top K: #{model.top_k}"
|
29
|
+
puts "Supported Methods: #{model.supported_generation_methods.join(", ")}"
|
30
|
+
puts "Capabilities:"
|
31
|
+
puts " - Content Generation: #{model.supports_content_generation?}"
|
32
|
+
puts " - Chat: #{model.supports_message_generation?}"
|
33
|
+
puts " - Embedding: #{model.supports_embedding?}"
|
34
|
+
puts " - Streaming: #{model.supports_streaming?}"
|
35
|
+
puts "========================\n\n"
|
36
|
+
end
|
37
|
+
|
38
|
+
puts "=== MODELS API EXAMPLES ==="
|
39
|
+
|
40
|
+
# Example 1: List models (first page)
|
41
|
+
puts "\n=== Example 1: List first page of models ==="
|
42
|
+
begin
|
43
|
+
model_list = Geminize.list_models(page_size: 5)
|
44
|
+
puts "Found #{model_list.size} models on first page"
|
45
|
+
puts "Has more pages: #{model_list.has_more_pages?}"
|
46
|
+
puts "Next page token: #{model_list.next_page_token}"
|
47
|
+
puts "\nFirst model details:"
|
48
|
+
display_model(model_list.first) if model_list.first
|
49
|
+
rescue => e
|
50
|
+
puts "Error listing models: #{e.message}"
|
51
|
+
end
|
52
|
+
|
53
|
+
# Example 2: Get detailed info for a specific model
|
54
|
+
puts "\n=== Example 2: Get specific model info ==="
|
55
|
+
begin
|
56
|
+
model = Geminize.get_model("gemini-1.5-flash")
|
57
|
+
puts "Retrieved model details:"
|
58
|
+
display_model(model)
|
59
|
+
rescue => e
|
60
|
+
puts "Error getting model: #{e.message}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# Example 3: Get all models (handling pagination)
|
64
|
+
puts "\n=== Example 3: Get all models (handling pagination) ==="
|
65
|
+
begin
|
66
|
+
all_models = Geminize.list_all_models
|
67
|
+
puts "Retrieved #{all_models.size} models in total"
|
68
|
+
rescue => e
|
69
|
+
puts "Error listing all models: #{e.message}"
|
70
|
+
end
|
71
|
+
|
72
|
+
# Example 4: Filter models by capability
|
73
|
+
puts "\n=== Example 4: Filter models by capability ==="
|
74
|
+
begin
|
75
|
+
# Get models that support embedding
|
76
|
+
embedding_models = Geminize.get_embedding_models
|
77
|
+
puts "Found #{embedding_models.size} models that support embeddings"
|
78
|
+
|
79
|
+
# Get models that support content generation
|
80
|
+
content_models = Geminize.get_content_generation_models
|
81
|
+
puts "Found #{content_models.size} models that support content generation"
|
82
|
+
|
83
|
+
# Get models that support chat
|
84
|
+
chat_models = Geminize.get_chat_models
|
85
|
+
puts "Found #{chat_models.size} models that support chat"
|
86
|
+
|
87
|
+
# Get models that support streaming
|
88
|
+
streaming_models = Geminize.get_streaming_models
|
89
|
+
puts "Found #{streaming_models.size} models that support streaming"
|
90
|
+
rescue => e
|
91
|
+
puts "Error filtering models: #{e.message}"
|
92
|
+
end
|
93
|
+
|
94
|
+
# Example 5: Filter models by specific method
|
95
|
+
puts "\n=== Example 5: Filter models by specific method ==="
|
96
|
+
begin
|
97
|
+
method_models = Geminize.get_models_by_method("generateContent")
|
98
|
+
puts "Found #{method_models.size} models that support generateContent"
|
99
|
+
|
100
|
+
# Display a specific model from the filtered list
|
101
|
+
if method_models.size > 0
|
102
|
+
puts "\nExample of a model supporting generateContent:"
|
103
|
+
display_model(method_models.first)
|
104
|
+
end
|
105
|
+
rescue => e
|
106
|
+
puts "Error filtering by method: #{e.message}"
|
107
|
+
end
|
108
|
+
|
109
|
+
# Example 6: Model comparison
|
110
|
+
puts "\n=== Example 6: Compare token limits ==="
|
111
|
+
begin
|
112
|
+
all_models = Geminize.list_all_models
|
113
|
+
|
114
|
+
# Filter to models with higher token limits
|
115
|
+
high_capacity_models = all_models.filter_by_min_input_tokens(100_000)
|
116
|
+
|
117
|
+
puts "Models with 100k+ input token limits:"
|
118
|
+
high_capacity_models.each do |model|
|
119
|
+
puts " - #{model.display_name}: #{model.input_token_limit} input tokens"
|
120
|
+
end
|
121
|
+
rescue => e
|
122
|
+
puts "Error comparing models: #{e.message}"
|
123
|
+
end
|
124
|
+
|
125
|
+
puts "\n=== Examples Complete ==="
|