geminize 0.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 (61) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.standard.yml +3 -0
  4. data/.yardopts +14 -0
  5. data/CHANGELOG.md +24 -0
  6. data/CODE_OF_CONDUCT.md +132 -0
  7. data/CONTRIBUTING.md +109 -0
  8. data/LICENSE.txt +21 -0
  9. data/README.md +423 -0
  10. data/Rakefile +10 -0
  11. data/examples/README.md +75 -0
  12. data/examples/configuration.rb +58 -0
  13. data/examples/embeddings.rb +195 -0
  14. data/examples/multimodal.rb +126 -0
  15. data/examples/rails_chat/README.md +69 -0
  16. data/examples/rails_chat/app/controllers/chat_controller.rb +26 -0
  17. data/examples/rails_chat/app/views/chat/index.html.erb +112 -0
  18. data/examples/rails_chat/config/routes.rb +8 -0
  19. data/examples/rails_initializer.rb +46 -0
  20. data/examples/system_instructions.rb +101 -0
  21. data/lib/geminize/chat.rb +98 -0
  22. data/lib/geminize/client.rb +318 -0
  23. data/lib/geminize/configuration.rb +98 -0
  24. data/lib/geminize/conversation_repository.rb +161 -0
  25. data/lib/geminize/conversation_service.rb +126 -0
  26. data/lib/geminize/embeddings.rb +145 -0
  27. data/lib/geminize/error_mapper.rb +96 -0
  28. data/lib/geminize/error_parser.rb +120 -0
  29. data/lib/geminize/errors.rb +185 -0
  30. data/lib/geminize/middleware/error_handler.rb +72 -0
  31. data/lib/geminize/model_info.rb +91 -0
  32. data/lib/geminize/models/chat_request.rb +186 -0
  33. data/lib/geminize/models/chat_response.rb +118 -0
  34. data/lib/geminize/models/content_request.rb +530 -0
  35. data/lib/geminize/models/content_response.rb +99 -0
  36. data/lib/geminize/models/conversation.rb +156 -0
  37. data/lib/geminize/models/embedding_request.rb +222 -0
  38. data/lib/geminize/models/embedding_response.rb +1064 -0
  39. data/lib/geminize/models/memory.rb +88 -0
  40. data/lib/geminize/models/message.rb +140 -0
  41. data/lib/geminize/models/model.rb +171 -0
  42. data/lib/geminize/models/model_list.rb +124 -0
  43. data/lib/geminize/models/stream_response.rb +99 -0
  44. data/lib/geminize/rails/app/controllers/concerns/geminize/controller.rb +105 -0
  45. data/lib/geminize/rails/app/helpers/geminize_helper.rb +125 -0
  46. data/lib/geminize/rails/controller_additions.rb +41 -0
  47. data/lib/geminize/rails/engine.rb +29 -0
  48. data/lib/geminize/rails/helper_additions.rb +37 -0
  49. data/lib/geminize/rails.rb +50 -0
  50. data/lib/geminize/railtie.rb +33 -0
  51. data/lib/geminize/request_builder.rb +57 -0
  52. data/lib/geminize/text_generation.rb +285 -0
  53. data/lib/geminize/validators.rb +150 -0
  54. data/lib/geminize/vector_utils.rb +164 -0
  55. data/lib/geminize/version.rb +5 -0
  56. data/lib/geminize.rb +527 -0
  57. data/lib/generators/geminize/install_generator.rb +22 -0
  58. data/lib/generators/geminize/templates/README +31 -0
  59. data/lib/generators/geminize/templates/initializer.rb +38 -0
  60. data/sig/geminize.rbs +4 -0
  61. metadata +218 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a9b29587f96d7535a7db3ad010684fd9fa7e7a765d83d71a1cd645bdf323af69
4
+ data.tar.gz: 90adc36f2b5acbdb6e45904ebbd7847d1a895a614d4aee6ace5af028d8812045
5
+ SHA512:
6
+ metadata.gz: 0b303213d67decca74c5f14c1a94625275febe0fc50d1ca24dc5a12fd65cd148077ef50e6ca27f1e720e05e88101f76047088db2707b71f2318036b7351335f9
7
+ data.tar.gz: 981b130896dd8a0f8824602d0adb51fe60b8cfcab9124b3e7322795b6cfc9c8140031a6ca144e042c478182e78d2f3f00a9e35daa3c763a2f6d794171f4773ed
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.1
data/.yardopts ADDED
@@ -0,0 +1,14 @@
1
+ --markup markdown
2
+ --markup-provider redcarpet
3
+ --title "Geminize Documentation"
4
+ --protected
5
+ --no-private
6
+ --exclude /spec/
7
+ --exclude /bin/
8
+ --hide-void-return
9
+ --embed-mixins
10
+ --readme README.md
11
+ lib/**/*.rb
12
+ -
13
+ LICENSE.txt
14
+ CHANGELOG.md
data/CHANGELOG.md ADDED
@@ -0,0 +1,24 @@
1
+ ## [Unreleased]
2
+
3
+ ### Added
4
+
5
+ - Rails integration for easy use in Rails applications
6
+ - Rails engine for seamless integration
7
+ - Generator for creating configuration initializers
8
+ - Controller concerns for Gemini operations
9
+ - View helpers for rendering conversations and chat interfaces
10
+ - Comprehensive documentation and examples
11
+ - Multimodal support for sending mixed content including text and images to the Gemini API
12
+ - New `generate_text_multimodal` method at module level for simplified multimodal requests
13
+ - Methods for adding images to content requests from files, URLs, or raw bytes
14
+ - Support for common image formats (JPEG, PNG, GIF, WEBP) with proper MIME type detection
15
+ - Comprehensive validation for image formats, sizes, and content
16
+ - New example file demonstrating multimodal usage
17
+ - Extended embedding support with all Google AI task types:
18
+ - Added `TASK_TYPE_UNSPECIFIED`, `QUESTION_ANSWERING`, `FACT_VERIFICATION`, and `CODE_RETRIEVAL_QUERY` task types
19
+ - Updated examples and documentation to demonstrate all task types
20
+ - Added tests for all new task types
21
+
22
+ ## [0.1.0] - 2025-04-21
23
+
24
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,109 @@
1
+ # Contributing to Geminize
2
+
3
+ First of all, thank you for considering contributing to Geminize! It's people like you that make Geminize better for everyone.
4
+
5
+ ## Code of Conduct
6
+
7
+ This project and everyone participating in it is governed by the [Geminize Code of Conduct](CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to [nhatlongnguyen1992@gmail.com](mailto:nhatlongnguyen1992@gmail.com).
8
+
9
+ ## How Can I Contribute?
10
+
11
+ ### Reporting Bugs
12
+
13
+ This section guides you through submitting a bug report. Following these guidelines helps maintainers understand your report, reproduce the behavior, and fix the issue.
14
+
15
+ - **Use a clear and descriptive title** for the issue to identify the problem.
16
+ - **Describe the exact steps which reproduce the problem** in as many details as possible.
17
+ - **Provide specific examples to demonstrate the steps** such as code snippets or links to your implementation.
18
+ - **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior.
19
+ - **Explain which behavior you expected to see instead and why.**
20
+ - **Include screenshots or animated GIFs** which show you following the described steps and clearly demonstrate the problem.
21
+ - **If the problem is related to performance or memory usage**, include a profiling report if possible.
22
+ - **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened.
23
+
24
+ ### Suggesting Enhancements
25
+
26
+ This section guides you through submitting an enhancement suggestion, including completely new features and minor improvements to existing functionality.
27
+
28
+ - **Use a clear and descriptive title** for the issue to identify the suggestion.
29
+ - **Provide a step-by-step description of the suggested enhancement** in as many details as possible.
30
+ - **Provide specific examples to demonstrate the steps** if applicable.
31
+ - **Describe the current behavior** and **explain which behavior you expected to see instead** and why.
32
+ - **Explain why this enhancement would be useful** to most Geminize users.
33
+
34
+ ### Pull Requests
35
+
36
+ - Fill in the required template
37
+ - Do not include issue numbers in the PR title
38
+ - Include screenshots and animated GIFs in your pull request whenever possible
39
+ - Follow the Ruby style guide (see below)
40
+ - Include tests for new functionality
41
+ - Document new code
42
+
43
+ ## Development Environment Setup
44
+
45
+ 1. Fork the repo
46
+ 2. Clone your fork: `git clone https://github.com/your-username/geminize.git`
47
+ 3. Change to the project directory: `cd geminize`
48
+ 4. Install dependencies: `bundle install`
49
+ 5. Run the tests: `bundle exec rake spec`
50
+
51
+ ## Ruby Style Guide
52
+
53
+ We use [StandardRB](https://github.com/standardrb/standard) for code styling. Before submitting a PR, please run:
54
+
55
+ ```bash
56
+ bundle exec standardrb --fix
57
+ ```
58
+
59
+ ## Testing
60
+
61
+ We use RSpec for testing. Please ensure all your code is tested:
62
+
63
+ ```bash
64
+ bundle exec rspec
65
+ ```
66
+
67
+ For comprehensive testing with VCR cassettes (which record API calls), ensure to set up a valid `GEMINI_API_KEY` in your environment or in a `.env` file.
68
+
69
+ ## Documentation
70
+
71
+ We use YARD for documentation. Please document all public methods and classes using YARD syntax:
72
+
73
+ ```ruby
74
+ # This method does something useful
75
+ #
76
+ # @param name [String] The name to use
77
+ # @param options [Hash] Additional options
78
+ # @option options [Boolean] :recursive Whether to recursively process
79
+ # @return [Array<String>] A list of processed results
80
+ def some_method(name, options = {})
81
+ # ...
82
+ end
83
+ ```
84
+
85
+ ## Versioning
86
+
87
+ We follow [Semantic Versioning](https://semver.org/). In short:
88
+
89
+ - MAJOR version for incompatible API changes
90
+ - MINOR version for added functionality in a backwards-compatible manner
91
+ - PATCH version for backwards-compatible bug fixes
92
+
93
+ ## Releasing
94
+
95
+ Only maintainers can create releases. The process is:
96
+
97
+ 1. Update version in `lib/geminize/version.rb`
98
+ 2. Update `CHANGELOG.md` with changes since last release
99
+ 3. Commit: `git commit -am "Prepare for release vX.Y.Z"`
100
+ 4. Create tag: `git tag -a vX.Y.Z -m "Version X.Y.Z"`
101
+ 5. Push: `git push && git push --tags`
102
+ 6. Create a new release on GitHub
103
+ 7. Build and push the gem: `bundle exec rake release`
104
+
105
+ ## Questions or Need Help?
106
+
107
+ Feel free to reach out via the GitHub Discussions on this project or by email.
108
+
109
+ Again, thank you for your interest in contributing to Geminize!
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Nhat Long Nguyen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.