ruby-gemini-api 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.
data/lib/gemini.rb ADDED
@@ -0,0 +1,81 @@
1
+ require "faraday"
2
+ require "faraday/multipart"
3
+ require "json"
4
+ require 'dotenv/load'
5
+
6
+ require_relative "gemini/version"
7
+ require_relative "gemini/http_headers"
8
+ require_relative "gemini/http"
9
+ require_relative "gemini/client"
10
+ require_relative "gemini/models"
11
+ require_relative "gemini/threads"
12
+ require_relative "gemini/messages"
13
+ require_relative "gemini/runs"
14
+ require_relative "gemini/embeddings"
15
+ require_relative "gemini/audio"
16
+ require_relative "gemini/files"
17
+ require_relative "gemini/images"
18
+ require_relative "gemini/response"
19
+ require_relative "gemini/documents"
20
+ require_relative "gemini/cached_content"
21
+ module Gemini
22
+ class Error < StandardError; end
23
+ class ConfigurationError < Error; end
24
+ class AuthenticationError < Error; end
25
+ class APIError < Error; end
26
+ class RateLimitError < Error; end
27
+ class InvalidRequestError < Error; end
28
+
29
+ class MiddlewareErrors < Faraday::Middleware
30
+ def call(env)
31
+ @app.call(env)
32
+ rescue Faraday::Error => e
33
+ raise e unless e.response.is_a?(Hash)
34
+ Gemini.log_message("Gemini HTTP Error", e.response[:body], :error)
35
+ raise e
36
+ end
37
+ end
38
+
39
+ class Configuration
40
+ attr_accessor :api_key,
41
+ :uri_base,
42
+ :log_errors,
43
+ :request_timeout,
44
+ :extra_headers
45
+
46
+ DEFAULT_URI_BASE = "https://generativelanguage.googleapis.com/v1beta".freeze
47
+ DEFAULT_REQUEST_TIMEOUT = 120
48
+ DEFAULT_LOG_ERRORS = false
49
+
50
+ def initialize
51
+ @api_key = nil
52
+ @log_errors = DEFAULT_LOG_ERRORS
53
+ @uri_base = DEFAULT_URI_BASE
54
+ @request_timeout = DEFAULT_REQUEST_TIMEOUT
55
+ @extra_headers = {}
56
+ end
57
+ end
58
+
59
+ class << self
60
+ attr_writer :configuration
61
+
62
+ def configuration
63
+ @configuration ||= Gemini::Configuration.new
64
+ end
65
+
66
+ def configure
67
+ yield(configuration)
68
+ end
69
+
70
+ def log_message(prefix, message, level = :warn)
71
+ return unless configuration.log_errors
72
+
73
+ color = level == :error ? "\033[31m" : "\033[33m"
74
+ logger = Logger.new($stdout)
75
+ logger.formatter = proc do |_severity, _datetime, _progname, msg|
76
+ "#{color}#{prefix} (spotted in ruby-gemini #{VERSION}): #{msg}\n\033[0m"
77
+ end
78
+ logger.send(level, message)
79
+ end
80
+ end
81
+ end
@@ -0,0 +1 @@
1
+ require_relative "../gemini"
metadata ADDED
@@ -0,0 +1,193 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby-gemini-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - rira100000000
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday-multipart
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: json
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '13.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '13.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: dotenv
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '2.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '2.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 6.3.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 6.3.1
139
+ description: A simple Ruby wrapper for interacting with Google Gemini API
140
+ email:
141
+ - 101010hayakawa@gmail.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - CHANGELOG.md
147
+ - LICENSE.txt
148
+ - README.md
149
+ - lib/gemini.rb
150
+ - lib/gemini/audio.rb
151
+ - lib/gemini/cached_content.rb
152
+ - lib/gemini/client.rb
153
+ - lib/gemini/documents.rb
154
+ - lib/gemini/embeddings.rb
155
+ - lib/gemini/files.rb
156
+ - lib/gemini/http.rb
157
+ - lib/gemini/http_headers.rb
158
+ - lib/gemini/images.rb
159
+ - lib/gemini/messages.rb
160
+ - lib/gemini/models.rb
161
+ - lib/gemini/response.rb
162
+ - lib/gemini/runs.rb
163
+ - lib/gemini/threads.rb
164
+ - lib/gemini/version.rb
165
+ - lib/ruby/gemini.rb
166
+ homepage: https://github.com/rira100000000/ruby-gemini
167
+ licenses:
168
+ - MIT
169
+ metadata:
170
+ homepage_uri: https://github.com/rira100000000/ruby-gemini
171
+ source_code_uri: https://github.com/rira100000000/ruby-gemini
172
+ changelog_uri: https://github.com/rira100000000/ruby-gemini/blob/main/CHANGELOG.md
173
+ rubygems_mfa_required: 'true'
174
+ post_install_message:
175
+ rdoc_options: []
176
+ require_paths:
177
+ - lib
178
+ required_ruby_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: 3.0.0
183
+ required_rubygems_version: !ruby/object:Gem::Requirement
184
+ requirements:
185
+ - - ">="
186
+ - !ruby/object:Gem::Version
187
+ version: '0'
188
+ requirements: []
189
+ rubygems_version: 3.5.11
190
+ signing_key:
191
+ specification_version: 4
192
+ summary: Ruby client for Google's Gemini API
193
+ test_files: []