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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ba4f68bb9f9fb0a8aedbe47bc8e81f2859f7418f049a6d9610b7f32982a09e0f
4
- data.tar.gz: '08bb6995fb0b749cdadde7a6be83373c53db9033ec03b8d8bc5228cf7f74ed4a'
3
+ metadata.gz: 8418d629d5c593b1900b31e44637a6b3fa494411d77e52a4c1dbd7004d36b2ff
4
+ data.tar.gz: 1a1913a35895c991249dd5c4e5048ca376a7605c46f8f650ef15f11b92b9e54f
5
5
  SHA512:
6
- metadata.gz: 6fb0326f7a91add9c63a3fc1876b0360345bb6176763b708fca4a7c1a9408a77c0d422ad658fce4127458a876cb8727a67eccbb4c71f1ebe60704eacd519cf84
7
- data.tar.gz: 4ebf4cfc65b6d21be25ced6dc666795b4110e9d4adc3d2538e32760bbf69e8af61cdb441fd692e98969aef51993a05c3da04f7f7be209334f15903fc9995e940
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Siruu580
3
+ Copyright (c) 2025-2026 qweruby
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,107 +1,156 @@
1
-
2
- # Genai
3
-
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.
5
-
6
- ## Installation
7
-
8
- Add to your Gemfile:
9
-
10
- ```ruby
11
- gem 'genai-rb'
12
- ```
13
-
14
- Then run:
15
-
16
- ```bash
17
- bundle install
18
- ```
19
-
20
- Or install directly:
21
-
22
- ```bash
23
- gem install genai-rb
24
- ```
25
-
26
- ## Usage
27
-
28
- ### Setup
29
-
30
- Get your Gemini API key from [Google AI Studio](https://makersuite.google.com/app/apikey).
31
-
32
- Set your API key:
33
-
34
- ```bash
35
- export GEMINI_API_KEY="api_key"
36
- ```
37
-
38
- Or pass it directly:
39
-
40
- ```ruby
41
- require 'genai'
42
- client = Genai.new(api_key: "api_key")
43
- ```
44
-
45
- ### Text Generation
46
-
47
- ```ruby
48
- response = client.generate_content(contents: "Hello, how are you?")
49
- puts response
50
- ```
51
-
52
- ### Use a Specific Model
53
-
54
- ```ruby
55
- response = client.generate_content(model_id: "gemini-2.5-flash", contents: "Explain quantum computing.")
56
- ```
57
-
58
- ### URL Context
59
-
60
- ```ruby
61
- response = client.generate_content(contents: "Summarize: https://example.com/article", tools: [:url_context])
62
- ```
63
-
64
- ### Google Search Integration
65
-
66
- ```ruby
67
- response = client.generate_content(contents: "Latest AI news?", tools: [:google_search, :url_context])
68
- ```
69
-
70
- ### Advanced Configuration
71
-
72
- ```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 }
77
- )
78
- ```
79
-
80
- ### Model Instances
81
-
82
- ```ruby
83
- model = client.model("gemini-2.5-flash")
84
- response = model.generate_content(contents: "Explain the benefits of renewable energy")
85
- ```
86
-
87
- ## Supported Models
88
-
89
- - All Gemini models
90
-
91
- ## Features
92
-
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
100
-
101
- ## Contributing
102
-
103
- Pull requests are always welcome.
104
-
105
- ## License
106
-
107
- Open source under the [MIT License](https://opensource.org/licenses/MIT).
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).