geminize 1.0.0 → 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.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. data/.cursor/mcp.json +3 -0
  3. data/.cursor/rules/isolation_rules/Core/command-execution.mdc +235 -0
  4. data/.cursor/rules/isolation_rules/Core/complexity-decision-tree.mdc +187 -0
  5. data/.cursor/rules/isolation_rules/Core/creative-phase-enforcement.mdc +145 -0
  6. data/.cursor/rules/isolation_rules/Core/creative-phase-metrics.mdc +195 -0
  7. data/.cursor/rules/isolation_rules/Core/file-verification.mdc +198 -0
  8. data/.cursor/rules/isolation_rules/Core/platform-awareness.mdc +71 -0
  9. data/.cursor/rules/isolation_rules/Level3/planning-comprehensive.mdc +159 -0
  10. data/.cursor/rules/isolation_rules/Level3/task-tracking-intermediate.mdc +135 -0
  11. data/.cursor/rules/isolation_rules/Phases/CreativePhase/creative-phase-architecture.mdc +187 -0
  12. data/.cursor/rules/isolation_rules/main.mdc +123 -0
  13. data/.cursor/rules/isolation_rules/visual-maps/archive-mode-map.mdc +277 -0
  14. data/.cursor/rules/isolation_rules/visual-maps/creative-mode-map.mdc +224 -0
  15. data/.cursor/rules/isolation_rules/visual-maps/implement-mode-map.mdc +321 -0
  16. data/.cursor/rules/isolation_rules/visual-maps/plan-mode-map.mdc +269 -0
  17. data/.cursor/rules/isolation_rules/visual-maps/qa-mode-map.mdc +495 -0
  18. data/.cursor/rules/isolation_rules/visual-maps/reflect-mode-map.mdc +234 -0
  19. data/.cursor/rules/isolation_rules/visual-maps/van-mode-map.mdc +902 -0
  20. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-complexity-determination.mdc +60 -0
  21. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-file-verification.mdc +49 -0
  22. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-mode-map.mdc +49 -0
  23. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-platform-detection.mdc +50 -0
  24. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/build-test.mdc +117 -0
  25. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/config-check.mdc +103 -0
  26. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/dependency-check.mdc +147 -0
  27. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/environment-check.mdc +104 -0
  28. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-checks/file-verification.mdc +1 -0
  29. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-main.mdc +142 -0
  30. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/common-fixes.mdc +92 -0
  31. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/mode-transitions.mdc +101 -0
  32. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/reports.mdc +149 -0
  33. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-guide.mdc +66 -0
  34. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-utils/rule-calling-help.mdc +19 -0
  35. data/.cursor/rules/isolation_rules/visual-maps/van_mode_split/van-qa-validation.md.old +363 -0
  36. data/.env.example +7 -0
  37. data/.memory_bank/activeContext.md +78 -0
  38. data/.memory_bank/progress.md +80 -0
  39. data/.memory_bank/projectbrief.md +29 -0
  40. data/.memory_bank/systemPatterns.md +90 -0
  41. data/.memory_bank/tasks.md +98 -0
  42. data/.memory_bank/techContext.md +73 -0
  43. data/.tool-versions +1 -0
  44. data/CHANGELOG.md +20 -0
  45. data/README.md +42 -5
  46. data/examples/models_api.rb +125 -0
  47. data/lib/geminize/configuration.rb +4 -4
  48. data/lib/geminize/model_info.rb +87 -8
  49. data/lib/geminize/models/model.rb +101 -109
  50. data/lib/geminize/models/model_list.rb +70 -28
  51. data/lib/geminize/request_builder.rb +29 -0
  52. data/lib/geminize/version.rb +1 -1
  53. data/lib/geminize.rb +71 -14
  54. metadata +45 -2
@@ -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,3 +1,23 @@
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
+
1
21
  ## [1.0.0] - 2025-05-02
2
22
 
3
23
  ### Removed
data/README.md CHANGED
@@ -11,6 +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
+ - Complete Models API for discovering and filtering available models
14
15
 
15
16
  ## Installation
16
17
 
@@ -56,11 +57,8 @@ GOOGLE_AI_API_KEY=your_api_key_here
56
57
 
57
58
  # API Configuration
58
59
  GOOGLE_AI_API_VERSION=v1beta
59
- GEMINI_DEFAULT_MODEL=gemini-1.5-pro-latest
60
-
61
- # Generation Parameters
62
- GEMINI_TEMPERATURE=0.7
63
- GEMINI_MAX_TOKENS=8192
60
+ GEMINI_MODEL=gemini-2.0-flash
61
+ GEMINI_EMBEDDING_MODEL=gemini-embedding-exp-03-07
64
62
  ```
65
63
 
66
64
  2. Add `.env` to your `.gitignore` file to keep your API keys secure:
@@ -316,6 +314,45 @@ Check out these example applications to see Geminize in action:
316
314
  - [Embeddings Example](examples/embeddings.rb)
317
315
  - [Multimodal Example](examples/multimodal.rb)
318
316
  - [System Instructions Example](examples/system_instructions.rb)
317
+ - [Models API Example](examples/models_api.rb)
318
+
319
+ ## Working with Models
320
+
321
+ Geminize provides a comprehensive API for querying and working with available Gemini models:
322
+
323
+ ```ruby
324
+ require 'geminize'
325
+ # Assumes API key is set via environment variables (e.g., in .env)
326
+
327
+ # List available models
328
+ models = Geminize.list_models
329
+ puts "Available models: #{models.size}"
330
+
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"
335
+
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
340
+
341
+ # Check if a model supports a specific capability
342
+ if model.supports_content_generation?
343
+ puts "This model supports content generation"
344
+ end
345
+
346
+ if model.supports_embedding?
347
+ puts "This model supports embeddings"
348
+ end
349
+
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(', ')}"
353
+ ```
354
+
355
+ For more comprehensive examples, see [examples/models_api.rb](examples/models_api.rb).
319
356
 
320
357
  ## Compatibility
321
358
 
@@ -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 ==="
@@ -17,7 +17,7 @@ module Geminize
17
17
  DEFAULT_MODEL = "gemini-2.0-flash"
18
18
 
19
19
  # Default embedding model
20
- DEFAULT_EMBEDDING_MODEL = "embedding-001"
20
+ DEFAULT_EMBEDDING_MODEL = "gemini-embedding-exp-03-07"
21
21
 
22
22
  # Default timeout values (in seconds)
23
23
  DEFAULT_TIMEOUT = 30
@@ -69,9 +69,9 @@ module Geminize
69
69
  # @return [void]
70
70
  def reset!
71
71
  @api_key = ENV["GEMINI_API_KEY"]
72
- @api_version = DEFAULT_API_VERSION
73
- @default_model = DEFAULT_MODEL
74
- @default_embedding_model = DEFAULT_EMBEDDING_MODEL
72
+ @api_version = ENV["GEMINI_API_VERSION"] || DEFAULT_API_VERSION
73
+ @default_model = ENV["GEMINI_MODEL"] || DEFAULT_MODEL
74
+ @default_embedding_model = ENV["GEMINI_EMBEDDING_MODEL"] || DEFAULT_EMBEDDING_MODEL
75
75
  @timeout = DEFAULT_TIMEOUT
76
76
  @open_timeout = DEFAULT_OPEN_TIMEOUT
77
77
  @streaming_timeout = DEFAULT_STREAMING_TIMEOUT
@@ -9,6 +9,9 @@ module Geminize
9
9
  # @return [Geminize::Client] The HTTP client
10
10
  attr_reader :client
11
11
 
12
+ # Default page size for listing models
13
+ DEFAULT_PAGE_SIZE = 50
14
+
12
15
  # Initialize a new ModelInfo instance
13
16
  # @param client [Geminize::Client, nil] The HTTP client to use
14
17
  # @param options [Hash] Additional options for the client
@@ -20,19 +23,26 @@ module Geminize
20
23
  end
21
24
 
22
25
  # List available models from the Gemini API
26
+ # @param page_size [Integer, nil] Number of models to return per page (max 1000)
27
+ # @param page_token [String, nil] Token for retrieving a specific page
23
28
  # @param force_refresh [Boolean] Force a refresh from the API instead of using cache
24
29
  # @return [Geminize::Models::ModelList] List of available models
25
30
  # @raise [Geminize::GeminizeError] If the request fails
26
- def list_models(force_refresh: false)
27
- cache_key = "models_list"
31
+ def list_models(page_size: nil, page_token: nil, force_refresh: false)
32
+ cache_key = "models_list_#{page_size}_#{page_token}"
28
33
 
29
34
  # Check if we have a valid cached result
30
35
  if !force_refresh && @cache[cache_key] && @cache_expiry[cache_key] > Time.now
31
36
  return @cache[cache_key]
32
37
  end
33
38
 
39
+ # Prepare query parameters
40
+ params = {}
41
+ params[:pageSize] = page_size if page_size
42
+ params[:pageToken] = page_token
43
+
34
44
  # Make the API request
35
- response = client.get("models")
45
+ response = client.get("models", params)
36
46
 
37
47
  # Create a ModelList from the response
38
48
  model_list = Models::ModelList.from_api_data(response)
@@ -44,13 +54,62 @@ module Geminize
44
54
  model_list
45
55
  end
46
56
 
57
+ # Get all available models, handling pagination automatically
58
+ # @param force_refresh [Boolean] Force a refresh from the API instead of using cache
59
+ # @return [Geminize::Models::ModelList] Complete list of all available models
60
+ # @raise [Geminize::GeminizeError] If any request fails
61
+ def list_all_models(force_refresh: false)
62
+ cache_key = "all_models_list"
63
+
64
+ # Check if we have a valid cached result
65
+ if !force_refresh && @cache[cache_key] && @cache_expiry[cache_key] > Time.now
66
+ return @cache[cache_key]
67
+ end
68
+
69
+ all_models = []
70
+ page_token = nil
71
+
72
+ # Fetch first page
73
+ model_list = list_models(
74
+ page_size: DEFAULT_PAGE_SIZE,
75
+ page_token: page_token,
76
+ force_refresh: force_refresh
77
+ )
78
+ all_models.concat(model_list.models)
79
+
80
+ # Fetch additional pages if available
81
+ while model_list.has_more_pages?
82
+ page_token = model_list.next_page_token
83
+ model_list = list_models(
84
+ page_size: DEFAULT_PAGE_SIZE,
85
+ page_token: page_token,
86
+ force_refresh: force_refresh
87
+ )
88
+ all_models.concat(model_list.models)
89
+ end
90
+
91
+ # Create a consolidated model list
92
+ result = Models::ModelList.new(all_models)
93
+
94
+ # Cache the result
95
+ @cache[cache_key] = result
96
+ @cache_expiry[cache_key] = Time.now + @cache_ttl
97
+
98
+ result
99
+ end
100
+
47
101
  # Get information about a specific model
48
- # @param model_id [String] The model ID to retrieve
102
+ # @param model_name [String] The model name to retrieve (models/{model})
49
103
  # @param force_refresh [Boolean] Force a refresh from the API instead of using cache
50
104
  # @return [Geminize::Models::Model] The model information
51
105
  # @raise [Geminize::GeminizeError] If the request fails or model is not found
52
- def get_model(model_id, force_refresh: false)
53
- cache_key = "model_#{model_id}"
106
+ def get_model(model_name, force_refresh: false)
107
+ # Handle both formats: "models/gemini-1.5-pro" or just "gemini-1.5-pro"
108
+ unless model_name.start_with?("models/")
109
+ model_name = "models/#{model_name}"
110
+ end
111
+
112
+ cache_key = "model_#{model_name}"
54
113
 
55
114
  # Check if we have a valid cached result
56
115
  if !force_refresh && @cache[cache_key] && @cache_expiry[cache_key] > Time.now
@@ -59,7 +118,7 @@ module Geminize
59
118
 
60
119
  # Make the API request
61
120
  begin
62
- response = client.get("models/#{model_id}")
121
+ response = client.get(model_name)
63
122
 
64
123
  # Create a Model from the response
65
124
  model = Models::Model.from_api_data(response)
@@ -71,10 +130,30 @@ module Geminize
71
130
  model
72
131
  rescue Geminize::NotFoundError => e
73
132
  # Re-raise with a more descriptive message
74
- raise Geminize::NotFoundError.new("Model '#{model_id}' not found", e.code, e.http_status)
133
+ raise Geminize::NotFoundError.new("Model '#{model_name}' not found", e.code, e.http_status)
75
134
  end
76
135
  end
77
136
 
137
+ # Get models that support a specific generation method
138
+ # @param method [String] The generation method (e.g., "generateContent", "embedContent")
139
+ # @param force_refresh [Boolean] Force a refresh from the API instead of using cache
140
+ # @return [Geminize::Models::ModelList] List of models that support the method
141
+ # @raise [Geminize::GeminizeError] If the request fails
142
+ def get_models_by_method(method, force_refresh: false)
143
+ all_models = list_all_models(force_refresh: force_refresh)
144
+ all_models.filter_by_method(method)
145
+ end
146
+
147
+ # Get models by base model ID
148
+ # @param base_model_id [String] The base model ID to filter by
149
+ # @param force_refresh [Boolean] Force a refresh from the API instead of using cache
150
+ # @return [Geminize::Models::ModelList] List of models with the specified base model ID
151
+ # @raise [Geminize::GeminizeError] If the request fails
152
+ def get_models_by_base_id(base_model_id, force_refresh: false)
153
+ all_models = list_all_models(force_refresh: force_refresh)
154
+ all_models.filter_by_base_model_id(base_model_id)
155
+ end
156
+
78
157
  # Clear all cached model information
79
158
  # @return [void]
80
159
  def clear_cache