geminize 1.1.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1b3672d83fd6ff1d0a803808ee2c6d71681053229a84b3f33e0ea8b64b78dc74
4
- data.tar.gz: 79eca877306a66edcf9dd6bfa3afc3dd1b1222c6127d4391cdc077944557a3bf
3
+ metadata.gz: 251a4ad929a96e4773c21c159849ec415c8ee32269e3a1cda100effeda96d1ed
4
+ data.tar.gz: 74b958a848f75a0cf700c3751a2fb596c5a22a4a65ea9b927ead0149fef255e7
5
5
  SHA512:
6
- metadata.gz: 81c4a2324a026449c00e983a2ad0f7e4e89e5d77564a62b6e7d430303eeeb129f32002f0c9a41055b4001044ec6272386ebba920e3e0565b8ac8c61f7bbc2d5d
7
- data.tar.gz: 7aeb4afe504891c0849f83b04d3afc7b50fa45c1b60d6ae5ebcaea681b403e13c1bc86613694713162fff8ab220b0f447fedf808f0611fb0dbfb7476a2243148
6
+ metadata.gz: a1ec3f597e8f30eedf8fe12304497896ba98e7e35137d751a64f0d3430a4723db6d63997b8852e0794e44029d014408d070613a117ae0089290d0c8e852cb2bd
7
+ data.tar.gz: cc0de3e6fa6949894ee531092ba02c0f07a4d828540fd1bf4f0b3d8c037f7e761212e4e4cc02dc35fedd2eea0ac8446c17c1f1ff601d64b5b5bbfa847b6702a4
@@ -9,6 +9,10 @@
9
9
  - Multimodal content handling (text + images)
10
10
  - Embeddings generation
11
11
  - Streaming responses
12
+ - Function calling capabilities
13
+ - JSON mode for structured responses
14
+ - Safety settings for content moderation
15
+ - Code execution capabilities
12
16
 
13
17
  ### Key Implementation Details
14
18
 
@@ -18,6 +22,32 @@
18
22
  - System instructions for guiding model behavior
19
23
  - Generation parameters (temperature, top_k, top_p)
20
24
  - Support for stop sequences
25
+ - Safety settings for content moderation
26
+
27
+ #### Function Calling
28
+
29
+ - Tool integration with Gemini API
30
+ - Function declaration and response models
31
+ - Support for multiple function definitions
32
+ - Tool execution modes (AUTO, MANUAL, NONE)
33
+ - Function result processing
34
+ - String-based function call detection
35
+
36
+ #### Code Execution
37
+
38
+ - Python code generation and execution support
39
+ - Code execution result handling
40
+ - Support for code libraries like matplotlib, numpy, etc.
41
+ - Tool-based code execution integration
42
+ - Executable code response parsing
43
+ - Code output result parsing
44
+
45
+ #### JSON Mode
46
+
47
+ - Structured data response handling
48
+ - Automatic JSON parsing
49
+ - JSON schema integration
50
+ - Response validation
21
51
 
22
52
  #### Multimodal Support
23
53
 
@@ -69,10 +99,14 @@
69
99
  - Streaming response optimizations
70
100
  - Comprehensive documentation
71
101
  - Error handling refinements
102
+ - Models API integration
103
+ - Function calling support
104
+ - Code execution capabilities
72
105
 
73
106
  ### Upcoming Features
74
107
 
75
- - Support for newer Gemini models
108
+ - Additional content types (audio, PDF)
109
+ - Caching support
76
110
  - Advanced parameter tuning
77
111
  - Additional vector operations
78
112
  - Improved conversation persistence
@@ -2,7 +2,7 @@
2
2
 
3
3
  ## Current Status
4
4
 
5
- Geminize is a functional Ruby gem providing a complete interface to the Google Gemini API. The current implementation includes all core features with a focus on stability, documentation, and ease of use.
5
+ Geminize is a functional Ruby gem providing a complete interface to the Google Gemini API. The current implementation includes all core features with a focus on stability, documentation, and ease of use. The gem now also includes function calling, JSON mode, safety settings, and code execution features.
6
6
 
7
7
  ## Development Progress
8
8
 
@@ -15,6 +15,11 @@ Geminize is a functional Ruby gem providing a complete interface to the Google G
15
15
  - **Streaming Responses**: ✅ Complete
16
16
  - **Error Handling**: ✅ Complete
17
17
  - **Configuration System**: ✅ Complete
18
+ - **Models API**: ✅ Complete
19
+ - **Function Calling**: ✅ Complete
20
+ - **JSON Mode**: ✅ Complete
21
+ - **Safety Settings**: ✅ Complete
22
+ - **Code Execution**: ✅ Complete
18
23
 
19
24
  ### Documentation
20
25
 
@@ -26,7 +31,7 @@ Geminize is a functional Ruby gem providing a complete interface to the Google G
26
31
  ### Testing
27
32
 
28
33
  - **Unit Tests**: ✅ Complete
29
- - **Integration Tests**: 🟡 Partially Complete (70%)
34
+ - **Integration Tests**: 🟡 Partially Complete (85%)
30
35
  - **Performance Tests**: ❌ Not Started
31
36
 
32
37
  ### Deployment
@@ -50,27 +55,35 @@ Geminize is a functional Ruby gem providing a complete interface to the Google G
50
55
  - Additional embedding task types
51
56
  - Improved documentation
52
57
 
53
- ### v1.0.0 (Planned for 2025-05-02)
58
+ ### v1.0.0 (2025-05-02)
54
59
 
55
60
  - Removed Rails-specific integration
56
61
  - Simplified usage
57
62
  - API stabilization
58
63
 
59
- ## Upcoming Milestones
64
+ ### v1.1.0 (2025-05-02)
65
+
66
+ - Support for Gemini Models API
67
+ - Model discovery and filtering functionality
68
+ - Pagination support
69
+ - Improved documentation
60
70
 
61
- ### v1.1.0 (Planned)
71
+ ### v1.2.0 (2025-05-02)
62
72
 
63
- - Support for latest Gemini models
64
- - Advanced vector operations
65
- - Improved streaming performance
66
- - Enhanced documentation
73
+ - Added function calling capabilities
74
+ - Added JSON mode for structured responses
75
+ - Added safety settings for content moderation
76
+ - Comprehensive test suite for new features
77
+ - Updated documentation
78
+
79
+ ## Upcoming Milestones
67
80
 
68
- ### v1.2.0 (Planned)
81
+ ### v1.3.0 (Planned)
69
82
 
70
- - Batch processing capabilities
83
+ - Added code execution support
84
+ - Additional content types (audio, PDF)
85
+ - Caching mechanisms
71
86
  - Improved conversation persistence
72
- - Additional configuration options
73
- - Memory optimizations
74
87
 
75
88
  ### v2.0.0 (Planned)
76
89
 
@@ -78,3 +91,4 @@ Geminize is a functional Ruby gem providing a complete interface to the Google G
78
91
  - Advanced function calling support
79
92
  - Performance improvements
80
93
  - Additional middleware options
94
+ - Async API support
@@ -11,6 +11,10 @@ Geminize is a Ruby gem providing a convenient and robust interface to Google's G
11
11
  - **Conversation Management**: Maintain conversation context for chat applications
12
12
  - **Embeddings Generation**: Generate and manipulate vector representations for text
13
13
  - **Streaming Responses**: Support for efficient streaming output
14
+ - **Models API**: Discover and filter available Gemini models
15
+ - **Function Calling**: Enable AI models to call functions defined by developers
16
+ - **JSON Mode**: Generate structured JSON responses for data-oriented applications
17
+ - **Safety Settings**: Control content generation with configurable safety thresholds
14
18
  - **Error Handling**: Comprehensive error handling and validation
15
19
 
16
20
  ## Technical Foundation
@@ -19,6 +23,8 @@ Geminize is a Ruby gem providing a convenient and robust interface to Google's G
19
23
  - Faraday for HTTP client functionality
20
24
  - Support for environment-based or programmatic configuration
21
25
  - Comprehensive API for both simple and advanced use cases
26
+ - VCR-based testing for API interactions
27
+ - Modular design with extensible components
22
28
 
23
29
  ## Project Goals
24
30
 
@@ -27,3 +33,13 @@ Geminize is a Ruby gem providing a convenient and robust interface to Google's G
27
33
  - Maintain clean, well-documented, and idiomatic Ruby code
28
34
  - Support both simple use cases and advanced configurations
29
35
  - Enable seamless integration with various Ruby applications
36
+ - Stay current with the latest Gemini API features and models
37
+
38
+ ## Current Version
39
+
40
+ Version 1.2.0 implements all core features including the latest additions:
41
+
42
+ - Function calling capabilities
43
+ - JSON mode for structured responses
44
+ - Safety settings for content moderation
45
+ - Comprehensive Models API
@@ -6,32 +6,55 @@
6
6
 
7
7
  - [ ] Review and improve YARD documentation
8
8
  - [ ] Add more code examples
9
- - [ ] Update README with latest features
9
+ - [x] Update README with latest features
10
10
  - [ ] Create diagrams for architecture overview
11
11
 
12
12
  ### Feature Development
13
13
 
14
14
  - [ ] Support for new Gemini models as they become available
15
- - [ ] Add support for function calling capabilities
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
+ - [x] **Code Execution Support**
33
+ - [x] Create code execution model classes
34
+ - [x] Implement code execution tools in requests
35
+ - [x] Update response handling for code execution
36
+ - [x] Add module-level code execution methods
37
+ - [x] Create example script for code execution
38
+ - [ ] **Additional Content Types**
39
+ - [ ] Audio content support
40
+ - [ ] Document/PDF content support
41
+ - [ ] Video content support
42
+ - [ ] **Caching Support**
43
+ - [ ] Add caching to content requests
44
+ - [ ] Implement cached content handling
45
+ - [ ] Add module-level caching methods
46
+ - [x] Add support for function calling capabilities
16
47
  - [ ] Implement batch embedding generation
17
48
  - [ ] 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
49
 
29
50
  ### Testing
30
51
 
31
52
  - [ ] Expand test coverage
32
53
  - [ ] Add integration tests for streaming
33
- - [ ] Update VCR cassettes with latest API responses
54
+ - [x] Update VCR cassettes with latest API responses
34
55
  - [ ] Add benchmarks for performance testing
56
+ - [x] Create test fixtures for new Gemini API features
57
+ - [x] Add VCR cassettes for function calling responses
35
58
 
36
59
  ### Improvements
37
60
 
@@ -57,18 +80,41 @@
57
80
  - [x] Embeddings generation
58
81
  - [x] Streaming response handling
59
82
  - [x] Models API Integration
83
+ - [x] Enhance `model_info.rb` to support full model metadata
84
+ - [x] Update/create `Models::Model` class to match API response structure
85
+ - [x] Implement `Models::ModelList` class for handling paginated results
86
+ - [x] Add methods to `RequestBuilder` for models endpoints
87
+ - [x] Add client methods for models endpoints
88
+ - [x] Add convenience methods to main Geminize module
89
+ - [x] Implement helper methods for model capability filtering
90
+ - [x] Add comprehensive tests for models functionality
91
+ - [x] Update documentation with models API examples
92
+ - [x] Function Calling Support
93
+ - [x] Create function declaration, tool, and response models
94
+ - [x] Implement request and response extensions
95
+ - [x] Add module-level methods for function calling
96
+ - [x] Add VCR tests for real API interactions
97
+ - [x] JSON Mode Support
98
+ - [x] Add MIME type support and JSON response parsing
99
+ - [x] Add structured data generation features
100
+ - [x] Safety Settings Support
101
+ - [x] Implement safety categories and thresholds
102
+ - [x] Add safety-focused generation methods
60
103
 
61
104
  ### Documentation
62
105
 
63
106
  - [x] Initial README with examples
64
107
  - [x] YARD documentation for public methods
65
108
  - [x] Example scripts
109
+ - [x] Update README with function calling, JSON mode, and safety settings
66
110
 
67
111
  ### Testing
68
112
 
69
113
  - [x] Basic test suite with RSpec
70
114
  - [x] VCR setup for API mocking
71
115
  - [x] Unit tests for core functionality
116
+ - [x] Integration tests for function calling
117
+ - [x] Tests for JSON mode and safety settings
72
118
 
73
119
  ### Error Handling
74
120
 
data/CHANGELOG.md CHANGED
@@ -1,3 +1,39 @@
1
+ ## [1.3.0] - 2024-05-02
2
+
3
+ ### Added
4
+
5
+ - Code execution capabilities for generating and running Python code
6
+ - Added `generate_with_code_execution` method to create and execute Python code
7
+ - Implemented `ExecutableCode` model for representing generated code
8
+ - Added `CodeExecutionResult` model for capturing execution output and status
9
+ - Added support for visualizations and data analysis with matplotlib and other libraries
10
+ - Extended tool system to support code execution tools
11
+ - Updated content request/response handling for code execution
12
+ - Added comprehensive test suite with VCR tests for code execution
13
+ - Added examples demonstrating code execution functionality
14
+
15
+ ## [1.2.0] - 2025-05-02
16
+
17
+ ### Added
18
+
19
+ - Function calling capabilities for working with the Gemini API's tool features
20
+ - Added `generate_with_functions` method to create content with function definitions
21
+ - Added `process_function_call` method to handle function responses
22
+ - Added support for multiple function declarations in a single request
23
+ - Added configurable tool execution modes (AUTO, MANUAL, NONE)
24
+ - Implemented comprehensive test suite for function calling features
25
+ - Added tool-related model classes (Tool, ToolConfig, FunctionDeclaration, FunctionResponse)
26
+ - JSON mode for structured data responses
27
+ - Added `generate_json` method for receiving JSON-formatted responses
28
+ - Implemented automatic parsing of JSON responses
29
+ - Added type-checking and validation for JSON mode configuration
30
+ - Safety settings for controlled content generation
31
+ - Added `generate_with_safety_settings` method for customizing safety settings
32
+ - Added `generate_text_safe` for maximum content safety
33
+ - Added `generate_text_permissive` for minimum content filtering
34
+ - Added comprehensive safety categories and threshold levels
35
+ - Implemented validation for safety setting configurations
36
+
1
37
  ## [1.1.0] - 2025-05-02
2
38
 
3
39
  ### Added
data/README.md CHANGED
@@ -10,6 +10,9 @@ 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
14
17
  - Complete Models API for discovering and filtering available models
15
18
 
@@ -273,6 +276,226 @@ end
273
276
 
274
277
  See the `examples/embeddings.rb` file for more comprehensive examples of working with embeddings.
275
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
+
457
+ ## Code Execution
458
+
459
+ Generate and run Python code to solve problems or analyze data:
460
+
461
+ ```ruby
462
+ require 'geminize'
463
+ # Assumes API key is configured via .env
464
+
465
+ # Ask Gemini to solve a problem with code
466
+ response = Geminize.generate_with_code_execution(
467
+ "Calculate the sum of the first 10 prime numbers",
468
+ "gemini-2.0-flash", # Use a model that supports code execution
469
+ { temperature: 0.2 }
470
+ )
471
+
472
+ # Display the response text
473
+ puts "Gemini's explanation:"
474
+ puts response.text
475
+
476
+ # Access the generated code
477
+ if response.has_executable_code?
478
+ puts "\nGenerated Python code:"
479
+ puts response.executable_code.code
480
+ end
481
+
482
+ # Access the code execution result
483
+ if response.has_code_execution_result?
484
+ puts "\nExecution result:"
485
+ puts "Outcome: #{response.code_execution_result.outcome}"
486
+ puts "Output: #{response.code_execution_result.output}"
487
+ end
488
+ ```
489
+
490
+ Code execution is perfect for:
491
+
492
+ - Solving mathematical problems
493
+ - Data analysis and visualization
494
+ - Algorithm implementation
495
+ - Demonstrating programming concepts
496
+
497
+ The model generates Python code, executes it in a secure environment, and returns both the code and its execution results.
498
+
276
499
  ## Streaming Responses
277
500
 
278
501
  Get real-time, token-by-token responses:
@@ -315,6 +538,8 @@ Check out these example applications to see Geminize in action:
315
538
  - [Multimodal Example](examples/multimodal.rb)
316
539
  - [System Instructions Example](examples/system_instructions.rb)
317
540
  - [Models API Example](examples/models_api.rb)
541
+ - [Function Calling Example](examples/function_calling.rb)
542
+ - [Code Execution Example](examples/code_execution.rb)
318
543
 
319
544
  ## Working with Models
320
545