genai-rb 0.0.2 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1aec54cd52a2625f22438e6d5baa1418f71e923ace70ffca6d29e67f3aedc99b
4
- data.tar.gz: c5dcdba349bc3930b2d353e43e07e88f2a384db499bafa133722e8d77e376d73
3
+ metadata.gz: 8418d629d5c593b1900b31e44637a6b3fa494411d77e52a4c1dbd7004d36b2ff
4
+ data.tar.gz: 1a1913a35895c991249dd5c4e5048ca376a7605c46f8f650ef15f11b92b9e54f
5
5
  SHA512:
6
- metadata.gz: 8df382a222223835262b53fa5175b569610b10042c113c2b0e40184aef851db017b51afb450911cb461d9d4b47ec5c01346ffceb4d751f36d83e9b55c6f123b1
7
- data.tar.gz: d3d6a35dbbf0896c424e4a29aa9d8bbd25bb11632fb388c71449efcf0cde702a653149b2b38509f54d4d5442d920a184401f5ebf07cb58a9e607b72f4bee545c
6
+ metadata.gz: ac01403695c45ebced2ec88afaa18ddbd2ad2e22d2a022a3d688907491650dd3d43793fcfb9e517ecc9471cb928d9bd54a3ee4e96bc1fe3c27e9513a2f2c4b8c
7
+ data.tar.gz: 7fc52345aea27e0d0350b38fe4f71a294eedcef76096b9d558c832ef6cd5f5a2d476748bd30eded89ae68a3fad44fd0be3a761fb64401a5f7332edd668ef86e6
data/CHANGELOG.md CHANGED
@@ -1,10 +1,11 @@
1
- ## [Release]
2
-
3
- ## [0.0.2] - 2025-08-16 (Me gustas tu)
4
-
5
- - Fix typos
6
- - Add support for Korean Unicode decoding
7
-
8
- ## [0.0.1] - 2025-08-15 (Glass Bead)
9
-
10
- - Initial release
1
+ ## [Release]
2
+
3
+ ## [0.1.0] - 2025-08-16 (Glass Bead)
4
+
5
+ - Initial release
6
+
7
+ ## [0.2.0] - 2026-07-31 (Me gustas tu)
8
+
9
+ - Switch from Gemini-only requests to OpenAI-compatible chat completions.
10
+ - Use `OPENAI_API_KEY` and optional `OPENAI_BASE_URL`.
11
+ - Update examples and documentation for OpenAI-compatible providers.
data/LICENSE.txt CHANGED
@@ -1,21 +1,21 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2025 Siruu580
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.
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-2026 qweruby
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.
data/README.md CHANGED
@@ -1,107 +1,156 @@
1
-
2
1
  # Genai
3
2
 
4
- An unofficial Ruby package for Google Gemini. Easily generate text and images, analyze web content, and integrate Google Search—all with a simple Ruby API.
3
+ OpenAI-compatible chat completions for Ruby.
5
4
 
6
5
  ## Installation
7
6
 
8
- Add to your Gemfile:
7
+ Add the gem to your Gemfile:
9
8
 
10
9
  ```ruby
11
- gem 'genai-rb'
10
+ gem "genai-rb"
12
11
  ```
13
12
 
14
- Then run:
13
+ Install dependencies:
15
14
 
16
15
  ```bash
17
16
  bundle install
18
17
  ```
19
18
 
20
- Or install directly:
19
+ Or install it directly:
21
20
 
22
21
  ```bash
23
22
  gem install genai-rb
24
23
  ```
25
24
 
26
- ## Usage
25
+ ## Setup
27
26
 
28
- ### Setup
27
+ Set your API key:
29
28
 
30
- Get your Gemini API key from [Google AI Studio](https://makersuite.google.com/app/apikey).
29
+ ```bash
30
+ export OPENAI_API_KEY="api_key"
31
+ ```
31
32
 
32
- Set your API key:
33
+ By default, requests go to:
34
+
35
+ ```text
36
+ https://api.openai.com/v1
37
+ ```
38
+
39
+ For another OpenAI-compatible provider, set `OPENAI_BASE_URL` with `/v1` included:
33
40
 
34
41
  ```bash
35
- export GEMINI_API_KEY="api_key"
42
+ export OPENAI_BASE_URL="https://api.example.com/v1"
36
43
  ```
37
44
 
38
- Or pass it directly:
45
+ For Gemini's OpenAI-compatible endpoint:
46
+
47
+ ```bash
48
+ export OPENAI_API_KEY="gemini_api_key"
49
+ export OPENAI_BASE_URL="https://generativelanguage.googleapis.com/v1beta/openai"
50
+ ```
51
+
52
+ You can also pass values in Ruby:
39
53
 
40
54
  ```ruby
41
- require 'genai'
42
- client = Genai.new(api_key: "api_key")
55
+ require "genai"
56
+
57
+ client = Genai.new(
58
+ api_key: "api_key",
59
+ base_url: "https://api.openai.com/v1"
60
+ )
43
61
  ```
44
62
 
45
- ### Text Generation
63
+ ## Quick Start
46
64
 
47
65
  ```ruby
66
+ require "genai"
67
+
68
+ client = Genai.new
69
+
48
70
  response = client.generate_content(contents: "Hello, how are you?")
49
71
  puts response
50
72
  ```
51
73
 
52
- ### Use a Specific Model
74
+ The default model is `gpt-5.5`.
53
75
 
54
- ```ruby
55
- response = client.generate_content(model_id: "gemini-2.5-flash", contents: "Explain quantum computing.")
76
+ Run the included example:
77
+
78
+ ```bash
79
+ ruby example.rb
56
80
  ```
57
81
 
58
- ### URL Context
82
+ Edit the variables at the top of `example.rb` to change providers:
59
83
 
60
84
  ```ruby
61
- response = client.generate_content(contents: "Summarize: https://example.com/article", tools: [:url_context])
85
+ api_key = "your_api_key"
86
+ base_url = "https://api.openai.com/v1"
87
+ model = "gpt-5.5"
62
88
  ```
63
89
 
64
- ### Google Search Integration
90
+ For Gemini's OpenAI-compatible endpoint:
65
91
 
66
92
  ```ruby
67
- response = client.generate_content(contents: "Latest AI news?", tools: [:google_search, :url_context])
93
+ api_key = "your_gemini_api_key"
94
+ base_url = "https://generativelanguage.googleapis.com/v1beta/openai"
95
+ model = "gemini-2.5-flash"
68
96
  ```
69
97
 
70
- ### Advanced Configuration
98
+ ## Choosing A Model
71
99
 
72
100
  ```ruby
73
- client = Genai.new(api_key: "api_key", timeout: 120, max_retries: 5)
74
- response = client.model("gemini-2.0-flash").generate_content(
75
- contents: "Write a creative story about a robot learning to paint",
76
- config: { temperature: 0.8, max_output_tokens: 1000 }
101
+ response = client.generate_content(
102
+ model: "gpt-5.5",
103
+ contents: "Explain quantum computing."
77
104
  )
105
+
106
+ puts response
78
107
  ```
79
108
 
80
- ### Model Instances
109
+ ## Configuration
110
+
111
+ Pass OpenAI chat completion options with `config`:
81
112
 
82
113
  ```ruby
83
- model = client.model("gemini-2.5-flash")
84
- response = model.generate_content(contents: "Explain the benefits of renewable energy")
114
+ response = client.generate_content(
115
+ contents: "Write a short story about a robot learning to paint.",
116
+ config: {
117
+ temperature: 0.8,
118
+ max_tokens: 1000
119
+ }
120
+ )
85
121
  ```
86
122
 
87
- ## Supported Models
123
+ `max_output_tokens` is accepted as an alias for `max_tokens`.
124
+
125
+ ## Messages
126
+
127
+ Use OpenAI-style messages when you need system or multi-turn context:
88
128
 
89
- - All Gemini models
129
+ ```ruby
130
+ response = client.generate_content(
131
+ contents: [
132
+ { role: "system", content: "Answer briefly." },
133
+ { role: "user", content: "0.1 + 0.2 == 0.3? Explain." }
134
+ ]
135
+ )
136
+
137
+ puts response
138
+ ```
139
+
140
+ ## Chat Sessions
90
141
 
91
- ## Features
142
+ ```ruby
143
+ chat = client.chats.create(model: "gpt-5.5")
92
144
 
93
- - Text and image generation
94
- - URL context analysis
95
- - Google Search integration
96
- - Multiple model support
97
- - Customizable generation config
98
- - Robust error handling and retry logic
99
- - Simple, intuitive Ruby API
145
+ puts chat.send_message("a = 231018")
146
+ puts chat.send_message("What is a?")
147
+ ```
100
148
 
101
- ## Contributing
149
+ ## Supported APIs
102
150
 
103
- Pull requests are always welcome.
151
+ - OpenAI Chat Completions API
152
+ - OpenAI-compatible `/v1/chat/completions` providers
104
153
 
105
154
  ## License
106
155
 
107
- Open source under the [MIT License](https://opensource.org/licenses/MIT).
156
+ Open source under the [MIT License](https://opensource.org/licenses/MIT).