ai-chat 0.0.8 → 0.1.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.
data/.reek.yml DELETED
@@ -1,7 +0,0 @@
1
- exclude_paths:
2
- - tmp
3
- - vendor
4
-
5
- detectors:
6
- LongParameterList:
7
- enabled: false
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.3.6
data/CHANGELOG.md DELETED
@@ -1,28 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.0.7] - 2025-04-25
4
-
5
- - Added support for reasoning effort parameter (`reasoning_effort`) with the OpenAI Responses API
6
- - Support for reasoning models like o3, o4-mini
7
- - Updated documentation with examples
8
-
9
- ## [0.0.6] - 2025-04-25
10
-
11
- - Fixed minor bugs
12
- - Improved error handling
13
-
14
- ## [0.0.5] - 2025-04-25
15
-
16
- - Updated to use OpenAI's Responses API instead of Chat Completions API
17
- - Fixed image processing to work with the new API format
18
- - Improved error handling and response parsing
19
-
20
- ## [0.0.1] - 2025-02-27
21
-
22
- - Initial release
23
-
24
- ## [0.0.2] - 2025-02-28
25
-
26
- - All dependencies have been removed
27
- - Supports Ruby 2.0.0
28
- - Updates gem author
data/CODE_OF_CONDUCT.md DELETED
@@ -1,84 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
-
7
- We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
-
9
- ## Our Standards
10
-
11
- Examples of behavior that contributes to a positive environment for our community include:
12
-
13
- * Demonstrating empathy and kindness toward other people
14
- * Being respectful of differing opinions, viewpoints, and experiences
15
- * Giving and gracefully accepting constructive feedback
16
- * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
- * Focusing on what is best not just for us as individuals, but for the overall community
18
-
19
- Examples of unacceptable behavior include:
20
-
21
- * The use of sexualized language or imagery, and sexual attention or
22
- advances of any kind
23
- * Trolling, insulting or derogatory comments, and personal or political attacks
24
- * Public or private harassment
25
- * Publishing others' private information, such as a physical or email
26
- address, without their explicit permission
27
- * Other conduct which could reasonably be considered inappropriate in a
28
- professional setting
29
-
30
- ## Enforcement Responsibilities
31
-
32
- Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
-
34
- Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
-
36
- ## Scope
37
-
38
- This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
-
40
- ## Enforcement
41
-
42
- Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jelani@firstdraft.com. All complaints will be reviewed and investigated promptly and fairly.
43
-
44
- All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
-
46
- ## Enforcement Guidelines
47
-
48
- Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
-
50
- ### 1. Correction
51
-
52
- **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
-
54
- **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
-
56
- ### 2. Warning
57
-
58
- **Community Impact**: A violation through a single incident or series of actions.
59
-
60
- **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
-
62
- ### 3. Temporary Ban
63
-
64
- **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
-
66
- **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
-
68
- ### 4. Permanent Ban
69
-
70
- **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
-
72
- **Consequence**: A permanent ban from any sort of public interaction within the community.
73
-
74
- ## Attribution
75
-
76
- This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
- available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
-
79
- Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
-
81
- [homepage]: https://www.contributor-covenant.org
82
-
83
- For answers to common questions about this code of conduct, see the FAQ at
84
- https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source "https://rubygems.org"
4
-
5
- # Specify your gem's dependencies in draft_chat.gemspec
6
- gemspec
data/Rakefile DELETED
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
- require "standard/rake"
6
-
7
- RSpec::Core::RakeTask.new(:spec)
8
-
9
- desc "Run standardrb and rspec tests"
10
- task default: [:standard, :spec]
data/ai_chat.gemspec DELETED
@@ -1,48 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative "lib/ai/chat/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "ai-chat"
7
- spec.version = AI::Chat::VERSION
8
- spec.authors = ["Raghu Betina", "Jelani Woods"]
9
- spec.email = ["raghu@firstdraft.com", "jelani@firstdraft.com"]
10
-
11
- spec.summary = "This gem provides a class called `AI::Chat` that is intended to make it as easy as possible to use OpenAI's Responses API."
12
- spec.description = "This gem provides a class called `AI::Chat` that is intended to make it as easy as possible to use OpenAI's Responses API. Supports Structured Output and Image Processing."
13
- spec.homepage = "https://github.com/firstdraft/ai-chat"
14
- spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.0.0"
16
-
17
- # spec.metadata["allowed_push_host"] = "TODO: Set to your gem server 'https://example.com'"
18
-
19
- spec.metadata["homepage_uri"] = spec.homepage
20
- spec.metadata["source_code_uri"] = "https://github.com/firstdraft/ai-chat"
21
- spec.metadata["changelog_uri"] = "https://github.com/firstdraft/ai-chat/blob/main/CHANGELOG.md"
22
-
23
- # Specify which files should be added to the gem when it is released.
24
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path(__dir__)) do
26
- `git ls-files -z`.split("\x0").reject do |f|
27
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(git|travis|circleci)|appveyor)})
28
- end
29
- end
30
- spec.bindir = "exe"
31
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
32
- spec.require_paths = ["lib"]
33
-
34
- # Register dependencies of the gem
35
- spec.add_runtime_dependency "mime-types", "~> 3.0"
36
- spec.add_runtime_dependency "base64", "~> 0.1" # Works for all Ruby versions
37
-
38
- # Development dependencies
39
- spec.add_development_dependency "rake", "~> 13.0"
40
- spec.add_development_dependency "rspec", "~> 3.12"
41
- spec.add_development_dependency "factory_bot", "~> 6.2"
42
- spec.add_development_dependency "webmock", "~> 3.18"
43
- spec.add_development_dependency "vcr", "~> 6.1"
44
- spec.add_development_dependency "standard", "~> 1.32"
45
-
46
- # For more information and examples about making a new gem, check out our
47
- # guide at: https://bundler.io/guides/creating_gem.html
48
- end
@@ -1,7 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module AI
4
- class Chat
5
- VERSION = "0.0.8"
6
- end
7
- end
data/test_program/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem "dotenv"
4
- gem "ai-chat", path: ".."
@@ -1,157 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "dotenv/load"
5
- require "ai-chat"
6
-
7
- puts "Testing AI::Chat gem with examples from README"
8
- puts "=============================================="
9
-
10
- # Simplest usage example
11
- puts "\nSimplest Usage Test:"
12
- puts "-------------------"
13
- x = AI::Chat.new
14
-
15
- # Add system-level instructions
16
- x.system("You are a helpful assistant that speaks like Shakespeare.")
17
-
18
- # Add a user message to the chat
19
- x.user("Hi there!")
20
-
21
- # Get the next message from the model
22
- begin
23
- response = x.assistant!
24
- puts "Assistant response: #{response}"
25
- rescue => e
26
- puts "Error: #{e.message}"
27
- puts "API response: #{e.backtrace.first(3).join("\n")}"
28
- end
29
-
30
- # Follow-up question
31
- x.user("What's the best pizza in Chicago?")
32
- response = x.assistant!
33
- puts "Assistant response: #{response}"
34
-
35
- # Configuration example
36
- puts "\nConfiguration Test:"
37
- puts "-------------------"
38
- # Using a different model
39
- y = AI::Chat.new
40
- y.model = "gpt-4o-mini" # Using a model that should be available
41
- y.system("You are a helpful assistant.")
42
- y.user("Write a haiku about programming.")
43
- response = y.assistant!
44
- puts "Response with model #{y.model}: #{response}"
45
-
46
- # Structured Output example
47
- puts "\nStructured Output Test:"
48
- puts "-----------------------"
49
- z = AI::Chat.new
50
-
51
- z.system("You are an expert nutritionist. The user will describe a meal. Estimate the calories, carbs, fat, and protein.")
52
-
53
- z.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}}'
54
-
55
- z.user("1 slice of pizza")
56
- response = z.assistant!
57
- puts "Nutrition values: #{response.inspect}"
58
-
59
- # Test with a single image
60
- puts "\nSingle Image Support Test:"
61
- puts "------------------------"
62
- begin
63
- img_path = File.expand_path("../../spec/fixtures/test1.jpg", __FILE__)
64
- if File.exist?(img_path)
65
- i = AI::Chat.new
66
- i.user("What's in this image?", image: img_path)
67
- response = i.assistant!
68
- puts "Image description: #{response}"
69
- else
70
- puts "Test image not found at #{img_path}"
71
- end
72
- rescue => e
73
- puts "Single image test error: #{e.message}"
74
- end
75
-
76
- # Test with multiple images
77
- puts "\nMultiple Images Support Test:"
78
- puts "--------------------------"
79
- begin
80
- img_path1 = File.expand_path("../../spec/fixtures/test1.jpg", __FILE__)
81
- img_path2 = File.expand_path("../../spec/fixtures/test2.jpg", __FILE__)
82
- img_path3 = File.expand_path("../../spec/fixtures/test3.jpg", __FILE__)
83
-
84
- if File.exist?(img_path1) && File.exist?(img_path2) && File.exist?(img_path3)
85
- i = AI::Chat.new
86
- i.user("Compare these images and tell me what you see.", images: [img_path1, img_path2, img_path3])
87
- response = i.assistant!
88
- puts "Multiple images description: #{response}"
89
- else
90
- puts "One or more test images not found"
91
- end
92
- rescue => e
93
- puts "Multiple images test error: #{e.message}"
94
- end
95
-
96
- # Get messages example
97
- puts "\nMessages Test:"
98
- puts "--------------"
99
- m = AI::Chat.new
100
- m.system("You are a helpful assistant.")
101
- m.user("Hello world!")
102
- m.assistant!
103
- puts "Messages: #{m.messages.inspect}"
104
-
105
- # Manual assistant message example
106
- puts "\nManual Assistant Message Test:"
107
- puts "-----------------------------"
108
- a = AI::Chat.new
109
- a.system("You are a helpful assistant.")
110
- a.assistant("Greetings! How can I assist you today?")
111
- a.user("Tell me a joke.")
112
- response = a.assistant!
113
- puts "Assistant response after manual message: #{response}"
114
-
115
- # Reasoning Effort Test
116
- puts "\nReasoning Effort Test:"
117
- puts "---------------------"
118
- begin
119
- r = AI::Chat.new
120
- r.model = "o4-mini" # Use a reasoning model
121
- r.reasoning_effort = "medium"
122
- r.user("Write a short bash script that counts the number of unique words in a text file.")
123
- response = r.assistant!
124
- puts "Response with reasoning effort 'medium': #{response}"
125
- rescue => e
126
- puts "Reasoning effort test error: #{e.message}"
127
- end
128
-
129
- # Reasoning Effort Validation Test
130
- puts "\nReasoning Effort Validation Test:"
131
- puts "-------------------------------"
132
- begin
133
- r = AI::Chat.new
134
- puts "Setting valid reasoning effort string 'low'..."
135
- r.reasoning_effort = "low"
136
- puts "Success: reasoning_effort = #{r.reasoning_effort}"
137
-
138
- puts "Setting valid reasoning effort symbol :medium..."
139
- r.reasoning_effort = :medium
140
- puts "Success: reasoning_effort = #{r.reasoning_effort}"
141
-
142
- puts "Setting valid reasoning effort string 'high'..."
143
- r.reasoning_effort = "high"
144
- puts "Success: reasoning_effort = #{r.reasoning_effort}"
145
-
146
- puts "Setting nil reasoning effort..."
147
- r.reasoning_effort = nil
148
- puts "Success: reasoning_effort = #{r.reasoning_effort}"
149
-
150
- puts "Setting invalid reasoning effort 'extreme'..."
151
- r.reasoning_effort = "extreme"
152
- puts "This line should not be reached"
153
- rescue ArgumentError => e
154
- puts "Expected error caught: #{e.message}"
155
- end
156
-
157
- puts "\nTests completed!"