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 +4 -4
- data/CHANGELOG.md +11 -10
- data/LICENSE.txt +21 -21
- data/README.md +92 -43
- data/lib/genai/chat.rb +206 -233
- data/lib/genai/config.rb +9 -9
- data/lib/genai/model.rb +155 -321
- data/lib/genai/version.rb +2 -2
- data/lib/genai.rb +32 -32
- metadata +11 -54
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8418d629d5c593b1900b31e44637a6b3fa494411d77e52a4c1dbd7004d36b2ff
|
|
4
|
+
data.tar.gz: 1a1913a35895c991249dd5c4e5048ca376a7605c46f8f650ef15f11b92b9e54f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac01403695c45ebced2ec88afaa18ddbd2ad2e22d2a022a3d688907491650dd3d43793fcfb9e517ecc9471cb928d9bd54a3ee4e96bc1fe3c27e9513a2f2c4b8c
|
|
7
|
+
data.tar.gz: 7fc52345aea27e0d0350b38fe4f71a294eedcef76096b9d558c832ef6cd5f5a2d476748bd30eded89ae68a3fad44fd0be3a761fb64401a5f7332edd668ef86e6
|
data/CHANGELOG.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
## [Release]
|
|
2
|
-
|
|
3
|
-
## [0.0
|
|
4
|
-
|
|
5
|
-
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
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
|
|
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
|
-
|
|
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
|
|
10
|
+
gem "genai-rb"
|
|
12
11
|
```
|
|
13
12
|
|
|
14
|
-
|
|
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
|
-
##
|
|
25
|
+
## Setup
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
Set your API key:
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
```bash
|
|
30
|
+
export OPENAI_API_KEY="api_key"
|
|
31
|
+
```
|
|
31
32
|
|
|
32
|
-
|
|
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
|
|
42
|
+
export OPENAI_BASE_URL="https://api.example.com/v1"
|
|
36
43
|
```
|
|
37
44
|
|
|
38
|
-
|
|
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
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
74
|
+
The default model is `gpt-5.5`.
|
|
53
75
|
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
Run the included example:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
ruby example.rb
|
|
56
80
|
```
|
|
57
81
|
|
|
58
|
-
|
|
82
|
+
Edit the variables at the top of `example.rb` to change providers:
|
|
59
83
|
|
|
60
84
|
```ruby
|
|
61
|
-
|
|
85
|
+
api_key = "your_api_key"
|
|
86
|
+
base_url = "https://api.openai.com/v1"
|
|
87
|
+
model = "gpt-5.5"
|
|
62
88
|
```
|
|
63
89
|
|
|
64
|
-
|
|
90
|
+
For Gemini's OpenAI-compatible endpoint:
|
|
65
91
|
|
|
66
92
|
```ruby
|
|
67
|
-
|
|
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
|
-
|
|
98
|
+
## Choosing A Model
|
|
71
99
|
|
|
72
100
|
```ruby
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
contents: "
|
|
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
|
-
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
Pass OpenAI chat completion options with `config`:
|
|
81
112
|
|
|
82
113
|
```ruby
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
142
|
+
```ruby
|
|
143
|
+
chat = client.chats.create(model: "gpt-5.5")
|
|
92
144
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
##
|
|
149
|
+
## Supported APIs
|
|
102
150
|
|
|
103
|
-
|
|
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).
|