geminize 1.0.0 → 1.2.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 (66) 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 +102 -0
  38. data/.memory_bank/progress.md +93 -0
  39. data/.memory_bank/projectbrief.md +45 -0
  40. data/.memory_bank/systemPatterns.md +90 -0
  41. data/.memory_bank/tasks.md +142 -0
  42. data/.memory_bank/techContext.md +73 -0
  43. data/.tool-versions +1 -0
  44. data/CHANGELOG.md +42 -0
  45. data/README.md +223 -5
  46. data/examples/function_calling.rb +218 -0
  47. data/examples/models_api.rb +125 -0
  48. data/examples/safety_settings.rb +82 -0
  49. data/lib/geminize/configuration.rb +4 -4
  50. data/lib/geminize/model_info.rb +87 -8
  51. data/lib/geminize/models/content_request_extensions.rb +219 -0
  52. data/lib/geminize/models/content_request_safety.rb +123 -0
  53. data/lib/geminize/models/content_response_extensions.rb +120 -0
  54. data/lib/geminize/models/function_declaration.rb +112 -0
  55. data/lib/geminize/models/function_response.rb +70 -0
  56. data/lib/geminize/models/model.rb +101 -109
  57. data/lib/geminize/models/model_list.rb +70 -28
  58. data/lib/geminize/models/safety_setting.rb +102 -0
  59. data/lib/geminize/models/tool.rb +47 -0
  60. data/lib/geminize/models/tool_config.rb +52 -0
  61. data/lib/geminize/module_extensions.rb +228 -0
  62. data/lib/geminize/module_safety.rb +135 -0
  63. data/lib/geminize/request_builder.rb +29 -0
  64. data/lib/geminize/version.rb +1 -1
  65. data/lib/geminize.rb +83 -14
  66. metadata +57 -2
@@ -0,0 +1,90 @@
1
+ # System Patterns
2
+
3
+ ## Design Patterns
4
+
5
+ ### Singleton Pattern
6
+
7
+ - Used for the `Configuration` class to ensure a single global configuration instance.
8
+ - Implemented using Ruby's `Singleton` module.
9
+
10
+ ### Builder Pattern
11
+
12
+ - Employed in `RequestBuilder` to construct API requests.
13
+ - Separates request construction from execution.
14
+
15
+ ### Factory Methods
16
+
17
+ - Used throughout the codebase to instantiate model objects from API responses.
18
+ - Example: `Models::ContentResponse.from_hash(response_data)`
19
+
20
+ ### Repository Pattern
21
+
22
+ - Implemented in `ConversationRepository` for conversation persistence.
23
+ - Abstracts storage details from the conversation service.
24
+
25
+ ### Adapter Pattern
26
+
27
+ - Used to adapt various image sources (files, URLs, raw bytes) to a common format.
28
+
29
+ ### Strategy Pattern
30
+
31
+ - Applied in streaming responses with different processing modes (raw, incremental, delta).
32
+ - Allows clients to choose how streaming data is processed.
33
+
34
+ ## Core Architectural Principles
35
+
36
+ ### Separation of Concerns
37
+
38
+ - Each class has a single, well-defined responsibility.
39
+ - Examples: `Client` handles HTTP, `TextGeneration` handles generation logic.
40
+
41
+ ### Immutable Objects
42
+
43
+ - Response objects are designed to be immutable.
44
+ - Request objects are built incrementally but not modified after submission.
45
+
46
+ ### Comprehensive Validation
47
+
48
+ - Input validation happens before API calls.
49
+ - Extensive parameter checking and error handling.
50
+
51
+ ### Error Handling
52
+
53
+ - Structured hierarchy of error classes.
54
+ - Detailed error messages with relevant context.
55
+ - Translation of API errors to gem-specific errors.
56
+
57
+ ### Configuration Flexibility
58
+
59
+ - Multiple configuration approaches (env vars, block config).
60
+ - Sensible defaults with override capabilities.
61
+
62
+ ### Developer Experience
63
+
64
+ - Method signatures follow Ruby idioms.
65
+ - Clear documentation with usage examples.
66
+ - Consistent return values and error handling.
67
+
68
+ ## Code Organization
69
+
70
+ ### Module Structure
71
+
72
+ - Everything contained within the `Geminize` namespace.
73
+ - Logical grouping of related functionality.
74
+
75
+ ### Dependency Management
76
+
77
+ - Minimal external dependencies.
78
+ - Clear version requirements.
79
+
80
+ ### Testing Approach
81
+
82
+ - RSpec for unit and integration tests.
83
+ - VCR for recording and replaying HTTP interactions.
84
+ - Comprehensive test coverage.
85
+
86
+ ### Documentation
87
+
88
+ - YARD documentation for all public methods.
89
+ - Usage examples throughout codebase.
90
+ - Clear README with quickstart and detailed examples.
@@ -0,0 +1,142 @@
1
+ # Tasks
2
+
3
+ ## Current Tasks
4
+
5
+ ### Documentation
6
+
7
+ - [ ] Review and improve YARD documentation
8
+ - [ ] Add more code examples
9
+ - [x] 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
+ - [ ] Implement Gemini API missing features:
16
+ - [x] **Function Calling Support**
17
+ - [x] Create model classes for function calling structures
18
+ - [x] Update ContentRequest to support tools and functions
19
+ - [x] Update request builder and response handling
20
+ - [x] Add module-level convenience methods
21
+ - [x] Add comprehensive VCR tests for function calling
22
+ - [x] **JSON Mode Support**
23
+ - [x] Add MIME type support for JSON responses
24
+ - [x] Implement helper methods for JSON generation
25
+ - [x] Add validation for JSON response structures
26
+ - [x] Add tests for JSON mode functionality
27
+ - [x] **Safety Settings**
28
+ - [x] Create SafetySetting model
29
+ - [x] Add safety configuration to requests
30
+ - [x] Implement module-level safety methods
31
+ - [x] Add tests for safety settings
32
+ - [ ] **Code Execution Support**
33
+ - [ ] Create code execution model classes
34
+ - [ ] Implement code execution tools in requests
35
+ - [ ] Update response handling for code execution
36
+ - [ ] **Additional Content Types**
37
+ - [ ] Audio content support
38
+ - [ ] Document/PDF content support
39
+ - [ ] Video content support
40
+ - [ ] **Caching Support**
41
+ - [ ] Add caching to content requests
42
+ - [ ] Implement cached content handling
43
+ - [ ] Add module-level caching methods
44
+ - [x] Add support for function calling capabilities
45
+ - [ ] Implement batch embedding generation
46
+ - [ ] Improve conversation persistence with adapter pattern for multiple storage options
47
+
48
+ ### Testing
49
+
50
+ - [ ] Expand test coverage
51
+ - [ ] Add integration tests for streaming
52
+ - [x] Update VCR cassettes with latest API responses
53
+ - [ ] Add benchmarks for performance testing
54
+ - [x] Create test fixtures for new Gemini API features
55
+ - [x] Add VCR cassettes for function calling responses
56
+
57
+ ### Improvements
58
+
59
+ - [ ] Optimize streaming buffer management
60
+ - [ ] Enhance error messages with more context
61
+ - [ ] Reduce memory footprint for large responses
62
+ - [ ] Add telemetry options for tracking API usage
63
+
64
+ ### Bug Fixes
65
+
66
+ - [ ] Fix potential memory leak in streaming implementation
67
+ - [ ] Address timeout handling edge cases
68
+ - [ ] Improve error handling for network failures
69
+ - [ ] Fix MIME type detection for unusual file extensions
70
+
71
+ ## Completed Tasks
72
+
73
+ ### Core Implementation
74
+
75
+ - [x] Basic client implementation
76
+ - [x] Text generation support
77
+ - [x] Chat conversation support
78
+ - [x] Embeddings generation
79
+ - [x] Streaming response handling
80
+ - [x] Models API Integration
81
+ - [x] Enhance `model_info.rb` to support full model metadata
82
+ - [x] Update/create `Models::Model` class to match API response structure
83
+ - [x] Implement `Models::ModelList` class for handling paginated results
84
+ - [x] Add methods to `RequestBuilder` for models endpoints
85
+ - [x] Add client methods for models endpoints
86
+ - [x] Add convenience methods to main Geminize module
87
+ - [x] Implement helper methods for model capability filtering
88
+ - [x] Add comprehensive tests for models functionality
89
+ - [x] Update documentation with models API examples
90
+ - [x] Function Calling Support
91
+ - [x] Create function declaration, tool, and response models
92
+ - [x] Implement request and response extensions
93
+ - [x] Add module-level methods for function calling
94
+ - [x] Add VCR tests for real API interactions
95
+ - [x] JSON Mode Support
96
+ - [x] Add MIME type support and JSON response parsing
97
+ - [x] Add structured data generation features
98
+ - [x] Safety Settings Support
99
+ - [x] Implement safety categories and thresholds
100
+ - [x] Add safety-focused generation methods
101
+
102
+ ### Documentation
103
+
104
+ - [x] Initial README with examples
105
+ - [x] YARD documentation for public methods
106
+ - [x] Example scripts
107
+ - [x] Update README with function calling, JSON mode, and safety settings
108
+
109
+ ### Testing
110
+
111
+ - [x] Basic test suite with RSpec
112
+ - [x] VCR setup for API mocking
113
+ - [x] Unit tests for core functionality
114
+ - [x] Integration tests for function calling
115
+ - [x] Tests for JSON mode and safety settings
116
+
117
+ ### Error Handling
118
+
119
+ - [x] Error class hierarchy
120
+ - [x] API error mapping
121
+ - [x] Input validation
122
+
123
+ ## Backlog
124
+
125
+ ### Features
126
+
127
+ - [ ] Rails integration improvements
128
+ - [ ] Async API support
129
+ - [ ] Advanced vector operations
130
+ - [ ] Batch processing for multiple requests
131
+ - [ ] CLI tool for quick testing
132
+ - [ ] Models API enhancements:
133
+ - [ ] Caching model information to reduce API calls
134
+ - [ ] Smart model selection based on input requirements
135
+ - [ ] Model comparison utilities
136
+
137
+ ### Optimizations
138
+
139
+ - [ ] Reduce API call overhead
140
+ - [ ] Implement request compression
141
+ - [ ] Add response caching
142
+ - [ ] 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,45 @@
1
+ ## [1.2.0] - 2025-05-02
2
+
3
+ ### Added
4
+
5
+ - Function calling capabilities for working with the Gemini API's tool features
6
+ - Added `generate_with_functions` method to create content with function definitions
7
+ - Added `process_function_call` method to handle function responses
8
+ - Added support for multiple function declarations in a single request
9
+ - Added configurable tool execution modes (AUTO, MANUAL, NONE)
10
+ - Implemented comprehensive test suite for function calling features
11
+ - Added tool-related model classes (Tool, ToolConfig, FunctionDeclaration, FunctionResponse)
12
+ - JSON mode for structured data responses
13
+ - Added `generate_json` method for receiving JSON-formatted responses
14
+ - Implemented automatic parsing of JSON responses
15
+ - Added type-checking and validation for JSON mode configuration
16
+ - Safety settings for controlled content generation
17
+ - Added `generate_with_safety_settings` method for customizing safety settings
18
+ - Added `generate_text_safe` for maximum content safety
19
+ - Added `generate_text_permissive` for minimum content filtering
20
+ - Added comprehensive safety categories and threshold levels
21
+ - Implemented validation for safety setting configurations
22
+
23
+ ## [1.1.0] - 2025-05-02
24
+
25
+ ### Added
26
+
27
+ - Comprehensive Models API for discovering and filtering Gemini models
28
+ - Added `list_models` and `list_all_models` methods for retrieving available models
29
+ - Added `get_model` method for fetching specific model details
30
+ - Added filtering methods to find models by capability:
31
+ - `get_content_generation_models`
32
+ - `get_embedding_models`
33
+ - `get_chat_models`
34
+ - `get_streaming_models`
35
+ - Added `get_models_by_method` to filter by specific generation methods
36
+ - Extended `ModelList` class with comprehensive filtering capabilities
37
+ - Added model capability inspection methods
38
+ - Implemented pagination support for model listing
39
+ - Added caching for model information to reduce API calls
40
+ - Added comprehensive VCR tests for Models API functionality
41
+ - Updated documentation with Models API examples
42
+
1
43
  ## [1.0.0] - 2025-05-02
2
44
 
3
45
  ### Removed
data/README.md CHANGED
@@ -10,7 +10,11 @@ A convenient and robust Ruby interface for the Google Gemini API, enabling easy
10
10
  - Multimodal inputs (text + images)
11
11
  - Embeddings generation
12
12
  - Support for streaming responses
13
+ - Function calling capabilities for tool integration
14
+ - JSON mode for structured data responses
15
+ - Safety settings for content moderation
13
16
  - Comprehensive error handling
17
+ - Complete Models API for discovering and filtering available models
14
18
 
15
19
  ## Installation
16
20
 
@@ -56,11 +60,8 @@ GOOGLE_AI_API_KEY=your_api_key_here
56
60
 
57
61
  # API Configuration
58
62
  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
63
+ GEMINI_MODEL=gemini-2.0-flash
64
+ GEMINI_EMBEDDING_MODEL=gemini-embedding-exp-03-07
64
65
  ```
65
66
 
66
67
  2. Add `.env` to your `.gitignore` file to keep your API keys secure:
@@ -275,6 +276,184 @@ end
275
276
 
276
277
  See the `examples/embeddings.rb` file for more comprehensive examples of working with embeddings.
277
278
 
279
+ ## Function Calling
280
+
281
+ Geminize provides support for Gemini's function calling capabilities, allowing the AI model to call functions defined by you:
282
+
283
+ ```ruby
284
+ require 'geminize'
285
+ # Assumes API key is configured via .env
286
+
287
+ # Define functions that the model can call
288
+ weather_functions = [
289
+ {
290
+ name: "get_weather",
291
+ description: "Get the current weather for a location",
292
+ parameters: {
293
+ type: "object",
294
+ properties: {
295
+ location: {
296
+ type: "string",
297
+ description: "The city and state, e.g. New York, NY"
298
+ },
299
+ unit: {
300
+ type: "string",
301
+ enum: ["celsius", "fahrenheit"],
302
+ description: "The unit of temperature"
303
+ }
304
+ },
305
+ required: ["location"]
306
+ }
307
+ }
308
+ ]
309
+
310
+ # Generate a response that may include a function call
311
+ response = Geminize.generate_with_functions(
312
+ "What's the weather in San Francisco?",
313
+ weather_functions,
314
+ "gemini-1.5-pro", # Make sure you use a model that supports function calling
315
+ {
316
+ temperature: 0.2,
317
+ system_instruction: "Use the provided function to get weather information."
318
+ }
319
+ )
320
+
321
+ # Check if the response contains a function call
322
+ if response.has_function_call?
323
+ function_call = response.function_call
324
+ puts "Function called: #{function_call.name}"
325
+ puts "Arguments: #{function_call.response.inspect}"
326
+
327
+ # Process the function call with your implementation
328
+ final_response = Geminize.process_function_call(response) do |name, args|
329
+ if name == "get_weather"
330
+ location = args["location"]
331
+ # Call your actual weather API here
332
+ # For this example, we'll just return mock data
333
+ {
334
+ temperature: 72,
335
+ conditions: "partly cloudy",
336
+ humidity: 65,
337
+ location: location
338
+ }
339
+ end
340
+ end
341
+
342
+ # Display the final response
343
+ puts "Final response: #{final_response.text}"
344
+ else
345
+ puts "No function call in response: #{response.text}"
346
+ end
347
+ ```
348
+
349
+ ### Function Call Options
350
+
351
+ You can customize function calling behavior:
352
+
353
+ ```ruby
354
+ # Set the tool execution mode:
355
+ # - "AUTO": Model decides when to call functions
356
+ # - "MANUAL": Functions are only used when explicitly requested
357
+ # - "NONE": Functions are ignored
358
+ response = Geminize.generate_with_functions(
359
+ prompt,
360
+ functions,
361
+ model_name,
362
+ { tool_execution_mode: "MANUAL" }
363
+ )
364
+
365
+ # Control retry behavior
366
+ response = Geminize.generate_with_functions(
367
+ prompt,
368
+ functions,
369
+ model_name,
370
+ with_retries: false # Disable automatic retries on failure
371
+ )
372
+ ```
373
+
374
+ ## JSON Mode
375
+
376
+ Generate structured JSON responses from the model:
377
+
378
+ ```ruby
379
+ require 'geminize'
380
+ # Assumes API key is configured via .env
381
+
382
+ # Request JSON-formatted data
383
+ response = Geminize.generate_json(
384
+ "List the three largest planets in our solar system with their diameters in km",
385
+ "gemini-1.5-pro", # Use a model that supports JSON mode
386
+ { temperature: 0.2 }
387
+ )
388
+
389
+ # Access the parsed JSON data
390
+ if response.has_json_response?
391
+ planets = response.json_response
392
+ puts "Received structured data:"
393
+ planets.each do |planet|
394
+ puts "#{planet['name']}: #{planet['diameter']} km"
395
+ end
396
+ else
397
+ puts "No valid JSON in response: #{response.text}"
398
+ end
399
+ ```
400
+
401
+ The JSON mode is ideal for getting structured data that you can programmatically process in your application.
402
+
403
+ ## Safety Settings
404
+
405
+ Control content generation with safety settings:
406
+
407
+ ```ruby
408
+ require 'geminize'
409
+ # Assumes API key is configured via .env
410
+
411
+ # Generate content with custom safety settings
412
+ safety_settings = [
413
+ { category: "HARM_CATEGORY_DANGEROUS_CONTENT", threshold: "BLOCK_MEDIUM_AND_ABOVE" },
414
+ { category: "HARM_CATEGORY_HATE_SPEECH", threshold: "BLOCK_LOW_AND_ABOVE" }
415
+ ]
416
+
417
+ response = Geminize.generate_with_safety_settings(
418
+ "Explain the concept of nuclear fission",
419
+ safety_settings,
420
+ "gemini-1.5-pro",
421
+ { temperature: 0.7 }
422
+ )
423
+
424
+ puts response.text
425
+
426
+ # For maximum safety (blocks most potentially harmful content)
427
+ safe_response = Geminize.generate_text_safe(
428
+ "Tell me about controversial political topics",
429
+ "gemini-1.5-pro"
430
+ )
431
+
432
+ puts "Safe response: #{safe_response.text}"
433
+
434
+ # For minimum filtering (blocks only the most harmful content)
435
+ permissive_response = Geminize.generate_text_permissive(
436
+ "Describe a controversial historical event",
437
+ "gemini-1.5-pro"
438
+ )
439
+
440
+ puts "Permissive response: #{permissive_response.text}"
441
+ ```
442
+
443
+ Available safety categories:
444
+
445
+ - `HARM_CATEGORY_HATE_SPEECH`
446
+ - `HARM_CATEGORY_DANGEROUS_CONTENT`
447
+ - `HARM_CATEGORY_HARASSMENT`
448
+ - `HARM_CATEGORY_SEXUALLY_EXPLICIT`
449
+
450
+ Available threshold levels (from most to least restrictive):
451
+
452
+ - `BLOCK_LOW_AND_ABOVE`
453
+ - `BLOCK_MEDIUM_AND_ABOVE`
454
+ - `BLOCK_ONLY_HIGH`
455
+ - `BLOCK_NONE`
456
+
278
457
  ## Streaming Responses
279
458
 
280
459
  Get real-time, token-by-token responses:
@@ -316,6 +495,45 @@ Check out these example applications to see Geminize in action:
316
495
  - [Embeddings Example](examples/embeddings.rb)
317
496
  - [Multimodal Example](examples/multimodal.rb)
318
497
  - [System Instructions Example](examples/system_instructions.rb)
498
+ - [Models API Example](examples/models_api.rb)
499
+
500
+ ## Working with Models
501
+
502
+ Geminize provides a comprehensive API for querying and working with available Gemini models:
503
+
504
+ ```ruby
505
+ require 'geminize'
506
+ # Assumes API key is set via environment variables (e.g., in .env)
507
+
508
+ # List available models
509
+ models = Geminize.list_models
510
+ puts "Available models: #{models.size}"
511
+
512
+ # Get details about a specific model
513
+ model = Geminize.get_model("gemini-1.5-pro")
514
+ puts "Model: #{model.display_name}"
515
+ puts "Token limits: #{model.input_token_limit} input, #{model.output_token_limit} output"
516
+
517
+ # Find models by capability
518
+ embedding_models = Geminize.get_embedding_models
519
+ content_models = Geminize.get_content_generation_models
520
+ streaming_models = Geminize.get_streaming_models
521
+
522
+ # Check if a model supports a specific capability
523
+ if model.supports_content_generation?
524
+ puts "This model supports content generation"
525
+ end
526
+
527
+ if model.supports_embedding?
528
+ puts "This model supports embeddings"
529
+ end
530
+
531
+ # Find models with high context windows
532
+ high_context_models = Geminize.list_all_models.filter_by_min_input_tokens(100_000)
533
+ puts "Models with 100k+ context: #{high_context_models.map(&:id).join(', ')}"
534
+ ```
535
+
536
+ For more comprehensive examples, see [examples/models_api.rb](examples/models_api.rb).
319
537
 
320
538
  ## Compatibility
321
539