ai-chat 0.0.1 → 0.0.3
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 -0
- data/LICENSE.txt +21 -0
- data/README.md +145 -0
- data/lib/ai/chat/version.rb +7 -0
- data/lib/ai/chat.rb +203 -12
- data/lib/ai-chat.rb +11 -0
- metadata +97 -24
- data/LICENSE.adoc +0 -134
- data/README.adoc +0 -89
- data/ai-chat.gemspec +0 -31
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 96adef3af8e7871b999d82885b74b35ed59da4fa91c90640fe8089fd63d87ca5
|
4
|
+
data.tar.gz: 1becad90a613aff2c57b91b8d90700f6c7e48faf621ae0ffdc9a3f3e49870227
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3f703478eaf415e5b0e3976d86c9f8e773756b9a0a292f6f73a41da4d479b013366726da5335ba40b105981cc558d04f10b44d2d9f78dc513b10da039507a7c
|
7
|
+
data.tar.gz: 903e3772c07a351f2435d990bb1bbb02f6223d982e76025afc5e97477f64cc9d356eca153d31e5a39031c4f21f381d3aab6c8e53da48a8d29f31843fa195a801
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Jelani Woods
|
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
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# AI::Chat
|
2
|
+
|
3
|
+
This gem provides a class called `AI::Chat` that is intended to make it as easy as possible to use OpenAI's Chat Completions endpoint.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "ai-chat"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then, at a command prompt:
|
14
|
+
|
15
|
+
```
|
16
|
+
bundle install
|
17
|
+
```
|
18
|
+
|
19
|
+
Or, install it directly with:
|
20
|
+
|
21
|
+
```
|
22
|
+
gem install ai-chat
|
23
|
+
```
|
24
|
+
|
25
|
+
## Configuration
|
26
|
+
|
27
|
+
- By default, the gem checks for an environment variable called `AI_TOKEN`, then falls back to `OPENAI_TOKEN` if available. You can also provide your token directly when instantiating a chat:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
x = AI::Chat.new(api_token: "your-token-goes-here")
|
31
|
+
```
|
32
|
+
- By default, the gem uses the `gpt-4o` model. If you want something else, you can set it:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
x.model = "o3-mini"
|
36
|
+
```
|
37
|
+
|
38
|
+
## Simplest usage
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
x = AI::Chat.new
|
42
|
+
x.system("You are a helpful assistant that speaks like Shakespeare.")
|
43
|
+
x.user("Hi there!")
|
44
|
+
x.assistant!
|
45
|
+
# => "Greetings, good sir or madam! How dost thou fare on this fine day? Pray, tell me how I may be of service to thee."
|
46
|
+
|
47
|
+
x.user("What's the best pizza in Chicago?")
|
48
|
+
x.assistant!
|
49
|
+
# => "Ah, the fair and bustling city of Chicago, renowned for its deep-dish delight that hath captured hearts and stomachs aplenty. Amongst the many offerings of this great city, 'tis often said that Lou Malnati's and Giordano's art the titans of the deep-dish realm. Lou Malnati's crust is praised for its buttery crispness, whilst Giordano's doth boast a stuffed creation that is nigh unto legendary. Yet, I encourage thee to embark upon thine own quest and savor the offerings of these famed establishments, for in the tasting lies the truth of which thy palate prefers. Enjoy the gastronomic adventure, my friend."
|
50
|
+
```
|
51
|
+
|
52
|
+
## Structured Output
|
53
|
+
|
54
|
+
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)):
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
x = AI::Chat.new
|
58
|
+
x.system("You are an expert nutritionist. The user will describe a meal. Estimate the calories, carbs, fat, and protein.")
|
59
|
+
x.schema = '{"name": "nutrition_values","strict": true,"schema": {"type": "object","properties": { "fat": { "type": "number", "description": "The amount of fat in grams." }, "protein": { "type": "number", "description": "The amount of protein in grams." }, "carbs": { "type": "number", "description": "The amount of carbohydrates in grams." }, "total_calories": { "type": "number", "description": "The total calories calculated based on fat, protein, and carbohydrates." }},"required": [ "fat", "protein", "carbs", "total_calories"],"additionalProperties": false}}'
|
60
|
+
x.user("1 slice of pizza")
|
61
|
+
x.assistant!
|
62
|
+
# => {"fat"=>15, "protein"=>5, "carbs"=>50, "total_calories"=>350}
|
63
|
+
```
|
64
|
+
|
65
|
+
## Include images
|
66
|
+
|
67
|
+
You can include images in your chat messages using the `user` method with the `image` or `images` parameter:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# Send a single image
|
71
|
+
x.user("What's in this image?", image: "path/to/local/image.jpg")
|
72
|
+
|
73
|
+
# Send multiple images
|
74
|
+
x.user("What are these images showing?", images: ["path/to/image1.jpg", "https://example.com/image2.jpg"])
|
75
|
+
```
|
76
|
+
|
77
|
+
The gem supports three types of image inputs:
|
78
|
+
|
79
|
+
- URLs: Pass an image URL starting with `http://` or `https://`.
|
80
|
+
- File paths: Pass a string with a path to a local image file.
|
81
|
+
- File-like objects: Pass an object that responds to `read` (like `File.open("image.jpg")` or a Rails uploaded file).
|
82
|
+
|
83
|
+
You can send multiple images, and place them between bits of text, in a single user message:
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
z = AI::Chat.new
|
87
|
+
z.user(
|
88
|
+
[
|
89
|
+
{"image" => "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Eubalaena_glacialis_with_calf.jpg/215px-Eubalaena_glacialis_with_calf.jpg"},
|
90
|
+
{"text" => "What is in the above image? What is in the below image?"},
|
91
|
+
{"image" => "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Elephant_Diversity.jpg/305px-Elephant_Diversity.jpg"},
|
92
|
+
{"text" => "What are the differences between the images?"}
|
93
|
+
]
|
94
|
+
)
|
95
|
+
z.assistant!
|
96
|
+
```
|
97
|
+
|
98
|
+
Both string and symbol keys are supported for the hash items:
|
99
|
+
|
100
|
+
```ruby
|
101
|
+
z = AI::Chat.new
|
102
|
+
z.user(
|
103
|
+
[
|
104
|
+
{image: "https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Eubalaena_glacialis_with_calf.jpg/215px-Eubalaena_glacialis_with_calf.jpg"},
|
105
|
+
{text: "What is in the above image? What is in the below image?"},
|
106
|
+
{image: "https://upload.wikimedia.org/wikipedia/commons/thumb/1/1a/Elephant_Diversity.jpg/305px-Elephant_Diversity.jpg"},
|
107
|
+
{text: "What are the differences between the images?"}
|
108
|
+
]
|
109
|
+
)
|
110
|
+
z.assistant!
|
111
|
+
```
|
112
|
+
|
113
|
+
## Set assistant messages manually
|
114
|
+
|
115
|
+
You can manually add assistant messages:
|
116
|
+
|
117
|
+
```rb
|
118
|
+
x.assistant("Greetings, good sir or madam! How dost thou fare on this fine day? Pray, tell me how I may be of service to thee.")
|
119
|
+
```
|
120
|
+
|
121
|
+
Useful if you are reconstructing a chat that has already happened.
|
122
|
+
|
123
|
+
## Getting and setting messages directly
|
124
|
+
|
125
|
+
- You can call `.messages` to get an array containing the conversation so far.
|
126
|
+
- TODO: Setting `.messages` will replace the conversation with the provided array.
|
127
|
+
|
128
|
+
## TODOs
|
129
|
+
|
130
|
+
- Add a `reasoning_effort` parameter.
|
131
|
+
- Add the ability to set all messages at once, ideally with an ActiveRecord Relation.
|
132
|
+
- Add a way to access the whole API response body (rather than just the message content).
|
133
|
+
- Add specs.
|
134
|
+
|
135
|
+
## Contributing
|
136
|
+
|
137
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/firstdraft/ai-chat. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/firstdraft/ai-chat/blob/main/CODE_OF_CONDUCT.md).
|
138
|
+
|
139
|
+
## License
|
140
|
+
|
141
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
142
|
+
|
143
|
+
## Code of Conduct
|
144
|
+
|
145
|
+
Everyone interacting in the AI Chat project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/firstdraft/ai-chat/blob/main/CODE_OF_CONDUCT.md).
|
data/lib/ai/chat.rb
CHANGED
@@ -1,19 +1,210 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
# All dependencies are now required in the main ai-chat.rb file
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
loader.setup
|
9
|
-
end
|
5
|
+
module AI
|
6
|
+
class Chat
|
7
|
+
attr_accessor :messages, :schema, :model
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
9
|
+
def initialize(api_token: nil)
|
10
|
+
@api_token = api_token || ENV.fetch("AI_TOKEN", ENV.fetch("OPENAI_TOKEN", nil))
|
11
|
+
@messages = []
|
12
|
+
@model = "gpt-4o"
|
13
|
+
end
|
14
|
+
|
15
|
+
def system(content)
|
16
|
+
messages.push({role: "system", content: content})
|
17
|
+
end
|
18
|
+
|
19
|
+
def user(content, image: nil, images: nil)
|
20
|
+
if content.is_a?(Array)
|
21
|
+
processed_content = content.map do |item|
|
22
|
+
if item.key?("image") || item.key?(:image)
|
23
|
+
image_value = item.fetch("image") { item.fetch(:image) }
|
24
|
+
{
|
25
|
+
type: "image_url",
|
26
|
+
image_url: {
|
27
|
+
url: process_image(image_value)
|
28
|
+
}
|
29
|
+
}
|
30
|
+
elsif item.key?("text") || item.key?(:text)
|
31
|
+
text_value = item.fetch("text") { item.fetch(:text) }
|
32
|
+
{
|
33
|
+
type: "text",
|
34
|
+
text: text_value
|
35
|
+
}
|
36
|
+
else
|
37
|
+
item
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
messages.push(
|
42
|
+
{
|
43
|
+
role: "user",
|
44
|
+
content: processed_content
|
45
|
+
}
|
46
|
+
)
|
47
|
+
elsif image.nil? && images.nil?
|
48
|
+
messages.push(
|
49
|
+
{
|
50
|
+
role: "user",
|
51
|
+
content: content
|
52
|
+
}
|
53
|
+
)
|
54
|
+
else
|
55
|
+
text_and_images_array = [
|
56
|
+
{
|
57
|
+
type: "text",
|
58
|
+
text: content
|
59
|
+
}
|
60
|
+
]
|
61
|
+
|
62
|
+
if images && !images.empty?
|
63
|
+
images_array = images.map do |image|
|
64
|
+
{
|
65
|
+
type: "image_url",
|
66
|
+
image_url: {
|
67
|
+
url: process_image(image)
|
68
|
+
}
|
69
|
+
}
|
70
|
+
end
|
71
|
+
|
72
|
+
text_and_images_array += images_array
|
73
|
+
else
|
74
|
+
text_and_images_array.push(
|
75
|
+
{
|
76
|
+
type: "image_url",
|
77
|
+
image_url: {
|
78
|
+
url: process_image(image)
|
79
|
+
}
|
80
|
+
}
|
81
|
+
)
|
82
|
+
end
|
83
|
+
|
84
|
+
messages.push(
|
85
|
+
{
|
86
|
+
role: "user",
|
87
|
+
content: text_and_images_array
|
88
|
+
}
|
89
|
+
)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def assistant(content)
|
94
|
+
messages.push({role: "assistant", content: content})
|
95
|
+
end
|
96
|
+
|
97
|
+
def assistant!
|
98
|
+
request_headers_hash = {
|
99
|
+
"Authorization" => "Bearer #{@api_token}",
|
100
|
+
"content-type" => "application/json"
|
101
|
+
}
|
102
|
+
|
103
|
+
response_format = if schema.nil?
|
104
|
+
{
|
105
|
+
"type" => "text"
|
106
|
+
}
|
107
|
+
else
|
108
|
+
{
|
109
|
+
"type" => "json_schema",
|
110
|
+
"json_schema" => JSON.parse(schema)
|
111
|
+
}
|
112
|
+
end
|
113
|
+
|
114
|
+
request_body_hash = {
|
115
|
+
"model" => model,
|
116
|
+
"response_format" => response_format,
|
117
|
+
"messages" => messages
|
118
|
+
}
|
119
|
+
|
120
|
+
request_body_json = JSON.generate(request_body_hash)
|
121
|
+
|
122
|
+
uri = URI("https://api.openai.com/v1/chat/completions")
|
123
|
+
raw_response = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
124
|
+
request = Net::HTTP::Post.new(uri, request_headers_hash)
|
125
|
+
request.body = request_body_json
|
126
|
+
http.request(request)
|
127
|
+
end
|
128
|
+
|
129
|
+
parsed_response = JSON.parse(raw_response.body)
|
130
|
+
|
131
|
+
content = parsed_response.fetch("choices").at(0).fetch("message").fetch("content")
|
132
|
+
|
133
|
+
messages.push({role: "assistant", content: content})
|
134
|
+
|
135
|
+
schema.nil? ? content : JSON.parse(content)
|
136
|
+
end
|
137
|
+
|
138
|
+
def inspect
|
139
|
+
"#<#{self.class.name} @messages=#{messages.inspect} @model=#{@model.inspect} @schema=#{@schema.inspect}>"
|
140
|
+
end
|
141
|
+
|
142
|
+
private
|
143
|
+
|
144
|
+
# Custom exception class for input classification errors.
|
145
|
+
class InputClassificationError < StandardError; end
|
146
|
+
|
147
|
+
def classify_obj(obj)
|
148
|
+
if obj.is_a?(String)
|
149
|
+
# Attempt to parse as a URL.
|
150
|
+
begin
|
151
|
+
uri = URI.parse(obj)
|
152
|
+
if uri.is_a?(URI::HTTP) || uri.is_a?(URI::HTTPS)
|
153
|
+
return :url
|
154
|
+
end
|
155
|
+
rescue URI::InvalidURIError
|
156
|
+
# Not a valid URL; continue to check if it's a file path.
|
157
|
+
end
|
158
|
+
|
159
|
+
# Check if the string represents a local file path (must exist on disk).
|
160
|
+
if File.exist?(obj)
|
161
|
+
:file_path
|
162
|
+
else
|
163
|
+
raise InputClassificationError,
|
164
|
+
"String provided is neither a valid URL (must start with http:// or https://) nor an existing file path on disk. Received value: #{obj.inspect}"
|
165
|
+
end
|
166
|
+
elsif obj.respond_to?(:read)
|
167
|
+
# For non-String objects, check if it behaves like a file.
|
168
|
+
:file_like
|
169
|
+
else
|
170
|
+
raise InputClassificationError,
|
171
|
+
"Object provided is neither a String nor file-like (missing :read method). Received value: #{obj.inspect}"
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def process_image(obj)
|
176
|
+
case classify_obj(obj)
|
177
|
+
when :url
|
178
|
+
obj
|
179
|
+
when :file_path
|
180
|
+
file_path = obj
|
181
|
+
|
182
|
+
mime_type = MIME::Types.type_for(file_path).first.to_s
|
183
|
+
|
184
|
+
image_data = File.binread(file_path)
|
185
|
+
|
186
|
+
base64_string = Base64.strict_encode64(image_data)
|
187
|
+
|
188
|
+
"data:#{mime_type};base64,#{base64_string}"
|
189
|
+
when :file_like
|
190
|
+
filename = if obj.respond_to?(:path)
|
191
|
+
obj.path
|
192
|
+
elsif obj.respond_to?(:original_filename)
|
193
|
+
obj.original_filename
|
194
|
+
else
|
195
|
+
"unknown"
|
196
|
+
end
|
197
|
+
|
198
|
+
mime_type = MIME::Types.type_for(filename).first.to_s
|
199
|
+
mime_type = "image/jpeg" if mime_type.empty?
|
200
|
+
|
201
|
+
image_data = obj.read
|
202
|
+
obj.rewind if obj.respond_to?(:rewind)
|
203
|
+
|
204
|
+
base64_string = Base64.strict_encode64(image_data)
|
17
205
|
|
206
|
+
"data:#{mime_type};base64,#{base64_string}"
|
207
|
+
end
|
208
|
+
end
|
18
209
|
end
|
19
210
|
end
|
data/lib/ai-chat.rb
ADDED
metadata
CHANGED
@@ -1,71 +1,144 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai-chat
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Raghu Betina
|
8
|
-
|
8
|
+
- Jelani Woods
|
9
|
+
bindir: exe
|
9
10
|
cert_chain: []
|
10
|
-
date: 2025-
|
11
|
+
date: 2025-04-25 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
|
-
name:
|
14
|
+
name: mime-types
|
14
15
|
requirement: !ruby/object:Gem::Requirement
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
|
-
version: '
|
19
|
+
version: '3.0'
|
19
20
|
type: :runtime
|
20
21
|
prerelease: false
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
22
23
|
requirements:
|
23
24
|
- - "~>"
|
24
25
|
- !ruby/object:Gem::Version
|
25
|
-
version: '
|
26
|
+
version: '3.0'
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
|
-
name:
|
28
|
+
name: rake
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
29
30
|
requirements:
|
30
31
|
- - "~>"
|
31
32
|
- !ruby/object:Gem::Version
|
32
|
-
version: '
|
33
|
-
type: :
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.12'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.12'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: factory_bot
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '6.2'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '6.2'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.18'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.18'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '6.1'
|
90
|
+
type: :development
|
34
91
|
prerelease: false
|
35
92
|
version_requirements: !ruby/object:Gem::Requirement
|
36
93
|
requirements:
|
37
94
|
- - "~>"
|
38
95
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
96
|
+
version: '6.1'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: standard
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '1.32'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '1.32'
|
111
|
+
description: This gem provides a class called `AI::Chat` that is intended to make
|
112
|
+
it as easy as possible to use OpenAI's Chat Completions endpoint. Supports Structured
|
113
|
+
Output.
|
40
114
|
email:
|
41
115
|
- raghu@firstdraft.com
|
116
|
+
- jelani@firstdraft.com
|
42
117
|
executables: []
|
43
118
|
extensions: []
|
44
|
-
extra_rdoc_files:
|
45
|
-
- README.adoc
|
46
|
-
- LICENSE.adoc
|
119
|
+
extra_rdoc_files: []
|
47
120
|
files:
|
48
|
-
-
|
49
|
-
-
|
50
|
-
-
|
121
|
+
- CHANGELOG.md
|
122
|
+
- LICENSE.txt
|
123
|
+
- README.md
|
124
|
+
- lib/ai-chat.rb
|
51
125
|
- lib/ai/chat.rb
|
126
|
+
- lib/ai/chat/version.rb
|
52
127
|
homepage: https://github.com/firstdraft/ai-chat
|
53
128
|
licenses:
|
54
|
-
-
|
129
|
+
- MIT
|
55
130
|
metadata:
|
56
|
-
bug_tracker_uri: https://github.com/firstdraft/ai-chat/issues
|
57
|
-
changelog_uri: https://github.com/firstdraft/ai-chat/releases
|
58
131
|
homepage_uri: https://github.com/firstdraft/ai-chat
|
59
|
-
label: AI::Chat
|
60
132
|
source_code_uri: https://github.com/firstdraft/ai-chat
|
133
|
+
changelog_uri: https://github.com/firstdraft/ai-chat/blob/main/CHANGELOG.md
|
61
134
|
rdoc_options: []
|
62
135
|
require_paths:
|
63
136
|
- lib
|
64
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
138
|
requirements:
|
66
|
-
- - "
|
139
|
+
- - ">="
|
67
140
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
141
|
+
version: 2.0.0
|
69
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
70
143
|
requirements:
|
71
144
|
- - ">="
|
@@ -74,6 +147,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
147
|
requirements: []
|
75
148
|
rubygems_version: 3.6.5
|
76
149
|
specification_version: 4
|
77
|
-
summary:
|
78
|
-
|
150
|
+
summary: This gem provides a class called `AI::Chat` that is intended to make it as
|
151
|
+
easy as possible to use OpenAI's Chat Completions endpoint.
|
79
152
|
test_files: []
|
data/LICENSE.adoc
DELETED
@@ -1,134 +0,0 @@
|
|
1
|
-
= Hippocratic License
|
2
|
-
|
3
|
-
Version: 2.1.0.
|
4
|
-
|
5
|
-
Purpose. The purpose of this License is for the Licensor named above to
|
6
|
-
permit the Licensee (as defined below) broad permission, if consistent
|
7
|
-
with Human Rights Laws and Human Rights Principles (as each is defined
|
8
|
-
below), to use and work with the Software (as defined below) within the
|
9
|
-
full scope of Licensor’s copyright and patent rights, if any, in the
|
10
|
-
Software, while ensuring attribution and protecting the Licensor from
|
11
|
-
liability.
|
12
|
-
|
13
|
-
Permission and Conditions. The Licensor grants permission by this
|
14
|
-
license ("License"), free of charge, to the extent of Licensor’s
|
15
|
-
rights under applicable copyright and patent law, to any person or
|
16
|
-
entity (the "Licensee") obtaining a copy of this software and
|
17
|
-
associated documentation files (the "Software"), to do everything with
|
18
|
-
the Software that would otherwise infringe (i) the Licensor’s copyright
|
19
|
-
in the Software or (ii) any patent claims to the Software that the
|
20
|
-
Licensor can license or becomes able to license, subject to all of the
|
21
|
-
following terms and conditions:
|
22
|
-
|
23
|
-
* Acceptance. This License is automatically offered to every person and
|
24
|
-
entity subject to its terms and conditions. Licensee accepts this
|
25
|
-
License and agrees to its terms and conditions by taking any action with
|
26
|
-
the Software that, absent this License, would infringe any intellectual
|
27
|
-
property right held by Licensor.
|
28
|
-
* Notice. Licensee must ensure that everyone who gets a copy of any part
|
29
|
-
of this Software from Licensee, with or without changes, also receives
|
30
|
-
the License and the above copyright notice (and if included by the
|
31
|
-
Licensor, patent, trademark and attribution notice). Licensee must cause
|
32
|
-
any modified versions of the Software to carry prominent notices stating
|
33
|
-
that Licensee changed the Software. For clarity, although Licensee is
|
34
|
-
free to create modifications of the Software and distribute only the
|
35
|
-
modified portion created by Licensee with additional or different terms,
|
36
|
-
the portion of the Software not modified must be distributed pursuant to
|
37
|
-
this License. If anyone notifies Licensee in writing that Licensee has
|
38
|
-
not complied with this Notice section, Licensee can keep this License by
|
39
|
-
taking all practical steps to comply within 30 days after the notice. If
|
40
|
-
Licensee does not do so, Licensee’s License (and all rights licensed
|
41
|
-
hereunder) shall end immediately.
|
42
|
-
* Compliance with Human Rights Principles and Human Rights Laws.
|
43
|
-
[arabic]
|
44
|
-
. Human Rights Principles.
|
45
|
-
[loweralpha]
|
46
|
-
.. Licensee is advised to consult the articles of the United Nations
|
47
|
-
Universal Declaration of Human Rights and the United Nations Global
|
48
|
-
Compact that define recognized principles of international human rights
|
49
|
-
(the "Human Rights Principles"). Licensee shall use the Software in a
|
50
|
-
manner consistent with Human Rights Principles.
|
51
|
-
.. Unless the Licensor and Licensee agree otherwise, any dispute,
|
52
|
-
controversy, or claim arising out of or relating to (i) Section 1(a)
|
53
|
-
regarding Human Rights Principles, including the breach of Section 1(a),
|
54
|
-
termination of this License for breach of the Human Rights Principles,
|
55
|
-
or invalidity of Section 1(a) or (ii) a determination of whether any Law
|
56
|
-
is consistent or in conflict with Human Rights Principles pursuant to
|
57
|
-
Section 2, below, shall be settled by arbitration in accordance with the
|
58
|
-
Hague Rules on Business and Human Rights Arbitration (the "Rules");
|
59
|
-
provided, however, that Licensee may elect not to participate in such
|
60
|
-
arbitration, in which event this License (and all rights licensed
|
61
|
-
hereunder) shall end immediately. The number of arbitrators shall be one
|
62
|
-
unless the Rules require otherwise.
|
63
|
-
+
|
64
|
-
Unless both the Licensor and Licensee agree to the contrary: (1) All
|
65
|
-
documents and information concerning the arbitration shall be public and
|
66
|
-
may be disclosed by any party; (2) The repository referred to under
|
67
|
-
Article 43 of the Rules shall make available to the public in a timely
|
68
|
-
manner all documents concerning the arbitration which are communicated
|
69
|
-
to it, including all submissions of the parties, all evidence admitted
|
70
|
-
into the record of the proceedings, all transcripts or other recordings
|
71
|
-
of hearings and all orders, decisions and awards of the arbitral
|
72
|
-
tribunal, subject only to the arbitral tribunal’s powers to take such
|
73
|
-
measures as may be necessary to safeguard the integrity of the arbitral
|
74
|
-
process pursuant to Articles 18, 33, 41 and 42 of the Rules; and (3)
|
75
|
-
Article 26(6) of the Rules shall not apply.
|
76
|
-
. Human Rights Laws. The Software shall not be used by any person or
|
77
|
-
entity for any systems, activities, or other uses that violate any Human
|
78
|
-
Rights Laws. "Human Rights Laws" means any applicable laws,
|
79
|
-
regulations, or rules (collectively, "Laws") that protect human,
|
80
|
-
civil, labor, privacy, political, environmental, security, economic, due
|
81
|
-
process, or similar rights; provided, however, that such Laws are
|
82
|
-
consistent and not in conflict with Human Rights Principles (a dispute
|
83
|
-
over the consistency or a conflict between Laws and Human Rights
|
84
|
-
Principles shall be determined by arbitration as stated above). Where
|
85
|
-
the Human Rights Laws of more than one jurisdiction are applicable or in
|
86
|
-
conflict with respect to the use of the Software, the Human Rights Laws
|
87
|
-
that are most protective of the individuals or groups harmed shall
|
88
|
-
apply.
|
89
|
-
. Indemnity. Licensee shall hold harmless and indemnify Licensor (and
|
90
|
-
any other contributor) against all losses, damages, liabilities,
|
91
|
-
deficiencies, claims, actions, judgments, settlements, interest, awards,
|
92
|
-
penalties, fines, costs, or expenses of whatever kind, including
|
93
|
-
Licensor’s reasonable attorneys’ fees, arising out of or relating to
|
94
|
-
Licensee’s use of the Software in violation of Human Rights Laws or
|
95
|
-
Human Rights Principles.
|
96
|
-
* Failure to Comply. Any failure of Licensee to act according to the
|
97
|
-
terms and conditions of this License is both a breach of the License and
|
98
|
-
an infringement of the intellectual property rights of the Licensor
|
99
|
-
(subject to exceptions under Laws, e.g., fair use). In the event of a
|
100
|
-
breach or infringement, the terms and conditions of this License may be
|
101
|
-
enforced by Licensor under the Laws of any jurisdiction to which
|
102
|
-
Licensee is subject. Licensee also agrees that the Licensor may enforce
|
103
|
-
the terms and conditions of this License against Licensee through
|
104
|
-
specific performance (or similar remedy under Laws) to the extent
|
105
|
-
permitted by Laws. For clarity, except in the event of a breach of this
|
106
|
-
License, infringement, or as otherwise stated in this License, Licensor
|
107
|
-
may not terminate this License with Licensee.
|
108
|
-
* Enforceability and Interpretation. If any term or provision of this
|
109
|
-
License is determined to be invalid, illegal, or unenforceable by a
|
110
|
-
court of competent jurisdiction, then such invalidity, illegality, or
|
111
|
-
unenforceability shall not affect any other term or provision of this
|
112
|
-
License or invalidate or render unenforceable such term or provision in
|
113
|
-
any other jurisdiction; provided, however, subject to a court
|
114
|
-
modification pursuant to the immediately following sentence, if any term
|
115
|
-
or provision of this License pertaining to Human Rights Laws or Human
|
116
|
-
Rights Principles is deemed invalid, illegal, or unenforceable against
|
117
|
-
Licensee by a court of competent jurisdiction, all rights in the
|
118
|
-
Software granted to Licensee shall be deemed null and void as between
|
119
|
-
Licensor and Licensee. Upon a determination that any term or provision
|
120
|
-
is invalid, illegal, or unenforceable, to the extent permitted by Laws,
|
121
|
-
the court may modify this License to affect the original purpose that
|
122
|
-
the Software be used in compliance with Human Rights Principles and
|
123
|
-
Human Rights Laws as closely as possible. The language in this License
|
124
|
-
shall be interpreted as to its fair meaning and not strictly for or
|
125
|
-
against any party.
|
126
|
-
* Disclaimer. TO THE FULL EXTENT ALLOWED BY LAW, THIS SOFTWARE COMES
|
127
|
-
"AS IS," WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED, AND LICENSOR AND
|
128
|
-
ANY OTHER CONTRIBUTOR SHALL NOT BE LIABLE TO ANYONE FOR ANY DAMAGES OR
|
129
|
-
OTHER LIABILITY ARISING FROM, OUT OF, OR IN CONNECTION WITH THE SOFTWARE
|
130
|
-
OR THIS LICENSE, UNDER ANY KIND OF LEGAL CLAIM.
|
131
|
-
|
132
|
-
This Hippocratic License is an link:https://ethicalsource.dev[Ethical Source license] and is offered
|
133
|
-
for use by licensors and licensees at their own risk, on an "AS IS" basis, and with no warranties
|
134
|
-
express or implied, to the maximum extent permitted by Laws.
|
data/README.adoc
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
:toc: macro
|
2
|
-
:toclevels: 5
|
3
|
-
:figure-caption!:
|
4
|
-
|
5
|
-
= Ai Chat
|
6
|
-
|
7
|
-
toc::[]
|
8
|
-
|
9
|
-
== Features
|
10
|
-
|
11
|
-
== Requirements
|
12
|
-
|
13
|
-
. link:https://www.ruby-lang.org[Ruby].
|
14
|
-
|
15
|
-
== Setup
|
16
|
-
|
17
|
-
To install _with_ security, run:
|
18
|
-
|
19
|
-
[source,bash]
|
20
|
-
----
|
21
|
-
# 💡 Skip this line if you already have the public certificate installed.
|
22
|
-
gem cert --add <(curl --compressed --location https://undefined.io/gems.pem)
|
23
|
-
gem install ai-chat --trust-policy HighSecurity
|
24
|
-
----
|
25
|
-
|
26
|
-
To install _without_ security, run:
|
27
|
-
|
28
|
-
[source,bash]
|
29
|
-
----
|
30
|
-
gem install ai-chat
|
31
|
-
----
|
32
|
-
|
33
|
-
You can also add the gem directly to your project:
|
34
|
-
|
35
|
-
[source,bash]
|
36
|
-
----
|
37
|
-
bundle add ai-chat
|
38
|
-
----
|
39
|
-
|
40
|
-
Once the gem is installed, you only need to require it:
|
41
|
-
|
42
|
-
[source,ruby]
|
43
|
-
----
|
44
|
-
require "ai/chat"
|
45
|
-
----
|
46
|
-
|
47
|
-
== Usage
|
48
|
-
|
49
|
-
== Development
|
50
|
-
|
51
|
-
To contribute, run:
|
52
|
-
|
53
|
-
[source,bash]
|
54
|
-
----
|
55
|
-
git clone https://github.com/undefined/ai-chat
|
56
|
-
cd ai-chat
|
57
|
-
bin/setup
|
58
|
-
----
|
59
|
-
|
60
|
-
You can also use the IRB console for direct access to all objects:
|
61
|
-
|
62
|
-
[source,bash]
|
63
|
-
----
|
64
|
-
bin/console
|
65
|
-
----
|
66
|
-
|
67
|
-
== Tests
|
68
|
-
|
69
|
-
To test, run:
|
70
|
-
|
71
|
-
[source,bash]
|
72
|
-
----
|
73
|
-
bin/rake
|
74
|
-
----
|
75
|
-
|
76
|
-
== link:https://undefined.io/policies/license[License]
|
77
|
-
|
78
|
-
== link:https://undefined.io/policies/security[Security]
|
79
|
-
|
80
|
-
== link:https://undefined.io/policies/code_of_conduct[Code of Conduct]
|
81
|
-
|
82
|
-
== link:https://undefined.io/policies/contributions[Contributions]
|
83
|
-
|
84
|
-
== link:https://undefined.io/projects/ai-chat/versions[Versions]
|
85
|
-
|
86
|
-
== Credits
|
87
|
-
|
88
|
-
* Built with link:https://alchemists.io/projects/gemsmith[Gemsmith].
|
89
|
-
* Engineered by link:https://undefined.io/team/undefined[Raghu Betina].
|
data/ai-chat.gemspec
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
Gem::Specification.new do |spec|
|
4
|
-
spec.name = "ai-chat"
|
5
|
-
spec.version = "0.0.1"
|
6
|
-
spec.authors = ["Raghu Betina"]
|
7
|
-
spec.email = ["raghu@firstdraft.com"]
|
8
|
-
spec.homepage = "https://github.com/firstdraft/ai-chat"
|
9
|
-
spec.summary = "A library that makes it as easy as possible to use Chat Completion endpoints in your Ruby application."
|
10
|
-
spec.license = "Hippocratic-2.1"
|
11
|
-
|
12
|
-
spec.metadata = {
|
13
|
-
"bug_tracker_uri" => "https://github.com/firstdraft/ai-chat/issues",
|
14
|
-
"changelog_uri" => "https://github.com/firstdraft/ai-chat/releases",
|
15
|
-
"homepage_uri" => "https://github.com/firstdraft/ai-chat",
|
16
|
-
# "funding_uri" => "https://github.com/sponsors/undefined",
|
17
|
-
"label" => "AI::Chat",
|
18
|
-
# "rubygems_mfa_required" => "true",
|
19
|
-
"source_code_uri" => "https://github.com/firstdraft/ai-chat"
|
20
|
-
}
|
21
|
-
|
22
|
-
# spec.signing_key = Gem.default_key_path
|
23
|
-
# spec.cert_chain = [Gem.default_cert_path]
|
24
|
-
|
25
|
-
spec.required_ruby_version = "~> 3.3"
|
26
|
-
spec.add_dependency "refinements", "~> 12.10"
|
27
|
-
spec.add_dependency "zeitwerk", "~> 2.7"
|
28
|
-
|
29
|
-
spec.extra_rdoc_files = Dir["README*", "LICENSE*"]
|
30
|
-
spec.files = Dir["*.gemspec", "lib/**/*"]
|
31
|
-
end
|