You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+34-34Lines changed: 34 additions & 34 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
-
# OpenAI Chat
1
+
# AI Chat
2
2
3
-
This gem provides a class called `OpenAI::Chat` that is intended to make it as easy as possible to use OpenAI's cutting-edge generative AI models.
3
+
This gem provides a class called `AI::Chat` that is intended to make it as easy as possible to use OpenAI's cutting-edge generative AI models.
4
4
5
5
## Installation
6
6
@@ -9,7 +9,7 @@ This gem provides a class called `OpenAI::Chat` that is intended to make it as e
9
9
Add this line to your application's Gemfile:
10
10
11
11
```ruby
12
-
gem "openai-chat", "< 1.0.0"
12
+
gem "ai-chat", "< 1.0.0"
13
13
```
14
14
15
15
And then, at a command prompt:
@@ -23,18 +23,18 @@ bundle install
23
23
Or, install it directly with:
24
24
25
25
```
26
-
gem install openai-chat
26
+
gem install ai-chat
27
27
```
28
28
29
29
## Simplest usage
30
30
31
31
In your Ruby program:
32
32
33
33
```ruby
34
-
require"openai/chat"
34
+
require"ai-chat"
35
35
36
-
# Create an instance of OpenAI::Chat
37
-
a =OpenAI::Chat.new
36
+
# Create an instance of AI::Chat
37
+
a =AI::Chat.new
38
38
39
39
# Build up your conversation by adding messages
40
40
a.add("If the Ruby community had an official motto, what might it be?")
@@ -50,7 +50,7 @@ a.generate! # => "Matz is nice and so we are nice" (or similar)
50
50
pp a.messages
51
51
# => [
52
52
# {:role=>"user", :content=>"If the Ruby community had an official motto, what might it be?"},
53
-
# {:role=>"assistant", :content=>"Matz is nice and so we are nice", :response => #<OpenAI::Chat::Response id=resp_abc... model=gpt-4.1-nano tokens=12>}
53
+
# {:role=>"assistant", :content=>"Matz is nice and so we are nice", :response => #<AI::Chat::Response id=resp_abc... model=gpt-4.1-nano tokens=12>}
54
54
# ]
55
55
56
56
# Continue the conversation
@@ -70,7 +70,7 @@ That's it! You're building something like this:
70
70
[
71
71
{:role => "system", :content => "You are a helpful assistant"},
72
72
{:role => "user", :content => "Hello!"},
73
-
{:role => "assistant", :content => "Hi there! How can I help you today?", :response => #<OpenAI::Chat::Response id=resp_abc... model=gpt-4.1-nano tokens=12>}
73
+
{:role => "assistant", :content => "Hi there! How can I help you today?", :response => #<AI::Chat::Response id=resp_abc... model=gpt-4.1-nano tokens=12>}
74
74
]
75
75
```
76
76
@@ -79,9 +79,9 @@ That last bit, under `:response`, is an object that represents the JSON that the
79
79
## Adding Different Types of Messages
80
80
81
81
```ruby
82
-
require"openai/chat"
82
+
require"ai-chat"
83
83
84
-
b =OpenAI::Chat.new
84
+
b =AI::Chat.new
85
85
86
86
# Add system instructions
87
87
b.add("You are a helpful assistant that talks like Shakespeare.", role:"system")
@@ -105,7 +105,7 @@ b.generate! # => "Methinks 'tis 'Ruby doth bring joy to all who craft with care'
105
105
Instead of always specifying the role, you can use these shortcuts:
106
106
107
107
```ruby
108
-
c =OpenAI::Chat.new
108
+
c =AI::Chat.new
109
109
110
110
# These are equivalent:
111
111
c.add("You are helpful", role:"system")
@@ -130,7 +130,7 @@ We use the `add` method (and its shortcuts) to build up an array because:
d.user("What should I do next?") # Add a new question
136
136
d.generate! # Generate a response
@@ -143,7 +143,7 @@ d.generate! # Generate a response
143
143
By default, the gem uses OpenAI's `gpt-4.1-nano` model. If you want to use a different model, you can set it:
144
144
145
145
```ruby
146
-
e =OpenAI::Chat.new
146
+
e =AI::Chat.new
147
147
e.model ="o4-mini"
148
148
```
149
149
@@ -167,21 +167,21 @@ The gem by default looks for an environment variable called `OPENAI_API_KEY` and
167
167
You can specify a different environment variable name:
168
168
169
169
```ruby
170
-
f =OpenAI::Chat.new(api_key_env_var:"MY_OPENAI_TOKEN")
170
+
f =AI::Chat.new(api_key_env_var:"MY_OPENAI_TOKEN")
171
171
```
172
172
173
173
Or, you can pass an API key in directly:
174
174
175
175
```ruby
176
-
g =OpenAI::Chat.new(api_key:"your-api-key-goes-here")
176
+
g =AI::Chat.new(api_key:"your-api-key-goes-here")
177
177
```
178
178
179
179
## Inspecting Your Conversation
180
180
181
181
You can call `.messages` to get an array containing the conversation so far:
182
182
183
183
```ruby
184
-
h =OpenAI::Chat.new
184
+
h =AI::Chat.new
185
185
h.system("You are a helpful cooking assistant")
186
186
h.user("How do I boil an egg?")
187
187
h.generate!
@@ -208,7 +208,7 @@ h.last
208
208
Get back Structured Output by setting the `schema` attribute (I suggest using [OpenAI's handy tool for generating the JSON Schema](https://platform.openai.com/docs/guides/structured-outputs)):
209
209
210
210
```ruby
211
-
i =OpenAI::Chat.new
211
+
i =AI::Chat.new
212
212
213
213
i.system("You are an expert nutritionist. The user will describe a meal. Estimate the calories, carbs, fat, and protein.")
214
214
@@ -253,7 +253,7 @@ The keys can be `String`s or `Symbol`s.
253
253
You can include images in your chat messages using the `user` method with the `image` or `images` parameter:
254
254
255
255
```ruby
256
-
j =OpenAI::Chat.new
256
+
j =AI::Chat.new
257
257
258
258
# Send a single image
259
259
j.user("What's in this image?", image:"path/to/local/image.jpg")
@@ -282,7 +282,7 @@ The gem supports three types of image inputs:
282
282
To give the model access to real-time information from the internet, you can enable the `web_search` feature. This uses OpenAI's built-in `web_search_preview` tool.
283
283
284
284
```ruby
285
-
m =OpenAI::Chat.new
285
+
m =AI::Chat.new
286
286
m.web_search =true
287
287
m.user("What are the latest developments in the Ruby language?")
288
288
m.generate! # This may use web search to find current information
@@ -296,7 +296,7 @@ You can manually add assistant messages without making API calls, which is usefu
296
296
297
297
```ruby
298
298
# Create a new chat instance
299
-
k =OpenAI::Chat.new
299
+
k =AI::Chat.new
300
300
301
301
# Add previous messages
302
302
k.system("You are a helpful assistant who provides information about planets.")
@@ -316,14 +316,14 @@ response = k.generate!
316
316
puts response
317
317
```
318
318
319
-
With this, you can loop through any conversation's history (perhaps after retrieving it from your database), recreate an `OpenAI::Chat`, and then continue it.
319
+
With this, you can loop through any conversation's history (perhaps after retrieving it from your database), recreate an `AI::Chat`, and then continue it.
320
320
321
321
## Reasoning Models
322
322
323
323
When using reasoning models like `o3` or `o4-mini`, you can specify a reasoning effort level to control how much reasoning the model does before producing its final response:
324
324
325
325
```ruby
326
-
l =OpenAI::Chat.new
326
+
l =AI::Chat.new
327
327
l.model ="o3-mini"
328
328
l.reasoning_effort ="medium"# Can be "low", "medium", or "high"
329
329
@@ -343,7 +343,7 @@ Setting to `nil` disables the reasoning parameter.
343
343
When you call `generate!` or `generate!`, the gem stores additional information about the API response:
0 commit comments