genai-rb 0.1.0 → 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 +7 -1
- data/LICENSE.txt +1 -1
- data/README.md +156 -107
- data/lib/genai/chat.rb +206 -203
- data/lib/genai/config.rb +9 -9
- data/lib/genai/model.rb +229 -395
- data/lib/genai/version.rb +1 -1
- 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
|
@@ -2,4 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
## [0.1.0] - 2025-08-16 (Glass Bead)
|
|
4
4
|
|
|
5
|
-
- Initial release
|
|
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
data/README.md
CHANGED
|
@@ -1,107 +1,156 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
```ruby
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
# Genai
|
|
2
|
+
|
|
3
|
+
OpenAI-compatible chat completions for Ruby.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Add the gem to your Gemfile:
|
|
8
|
+
|
|
9
|
+
```ruby
|
|
10
|
+
gem "genai-rb"
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Install dependencies:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bundle install
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Or install it directly:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
gem install genai-rb
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Setup
|
|
26
|
+
|
|
27
|
+
Set your API key:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
export OPENAI_API_KEY="api_key"
|
|
31
|
+
```
|
|
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:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
export OPENAI_BASE_URL="https://api.example.com/v1"
|
|
43
|
+
```
|
|
44
|
+
|
|
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:
|
|
53
|
+
|
|
54
|
+
```ruby
|
|
55
|
+
require "genai"
|
|
56
|
+
|
|
57
|
+
client = Genai.new(
|
|
58
|
+
api_key: "api_key",
|
|
59
|
+
base_url: "https://api.openai.com/v1"
|
|
60
|
+
)
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Quick Start
|
|
64
|
+
|
|
65
|
+
```ruby
|
|
66
|
+
require "genai"
|
|
67
|
+
|
|
68
|
+
client = Genai.new
|
|
69
|
+
|
|
70
|
+
response = client.generate_content(contents: "Hello, how are you?")
|
|
71
|
+
puts response
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
The default model is `gpt-5.5`.
|
|
75
|
+
|
|
76
|
+
Run the included example:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
ruby example.rb
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Edit the variables at the top of `example.rb` to change providers:
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
api_key = "your_api_key"
|
|
86
|
+
base_url = "https://api.openai.com/v1"
|
|
87
|
+
model = "gpt-5.5"
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
For Gemini's OpenAI-compatible endpoint:
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
api_key = "your_gemini_api_key"
|
|
94
|
+
base_url = "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
95
|
+
model = "gemini-2.5-flash"
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
## Choosing A Model
|
|
99
|
+
|
|
100
|
+
```ruby
|
|
101
|
+
response = client.generate_content(
|
|
102
|
+
model: "gpt-5.5",
|
|
103
|
+
contents: "Explain quantum computing."
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
puts response
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Configuration
|
|
110
|
+
|
|
111
|
+
Pass OpenAI chat completion options with `config`:
|
|
112
|
+
|
|
113
|
+
```ruby
|
|
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
|
+
)
|
|
121
|
+
```
|
|
122
|
+
|
|
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:
|
|
128
|
+
|
|
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
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
chat = client.chats.create(model: "gpt-5.5")
|
|
144
|
+
|
|
145
|
+
puts chat.send_message("a = 231018")
|
|
146
|
+
puts chat.send_message("What is a?")
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Supported APIs
|
|
150
|
+
|
|
151
|
+
- OpenAI Chat Completions API
|
|
152
|
+
- OpenAI-compatible `/v1/chat/completions` providers
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
Open source under the [MIT License](https://opensource.org/licenses/MIT).
|