rubyai 0.4 → 0.5
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/CODE_OF_CONDUCT.md +74 -0
- data/CONTRIBUTING.md +3 -0
- data/Gemfile +8 -0
- data/lib/rubyai/version.rb +1 -1
- data/lib/rubyai.rb +4 -2
- data/pull_request_template.md +5 -0
- data/spec/client_spec.rb +24 -0
- data/spec/configuration_spec.rb +33 -0
- data/spec/spec_helper.rb +98 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6727865a08e4730350aa8a4d3ebed4e52a23ad2200698581871fc93dc37c8581
|
4
|
+
data.tar.gz: ce748852ad65ffd478892ed8c508516739f1dc5275fbd02ae40f1102ac39c527
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b529e268b5223abe0918572182ab722ebdf741fc86706a8a5a52cd53f879f3628945bd7a7107d63ccb916655b53fd88efff5d654e751d109244cb567fb4d3cee
|
7
|
+
data.tar.gz: 9054d961a89f41a773383f94e4722cb1d52cb3e8ac1e173a5104dbe0e22f097fd2b05e5f2f7701344b749de7feaec5ee1b7197592ef6327196309eb692a45861
|
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at alexrudall@users.noreply.github.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,3 @@
|
|
1
|
+
## Contributing
|
2
|
+
|
3
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/alexshapalov/rubyai. 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/alexshapalov/rubyai/blob/main/CODE_OF_CONDUCT.md).
|
data/Gemfile
ADDED
data/lib/rubyai/version.rb
CHANGED
data/lib/rubyai.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday/net_http_persistent'
|
3
|
+
require 'json'
|
4
|
+
|
1
5
|
require_relative "rubyai/client"
|
2
6
|
require_relative "rubyai/configuration"
|
3
7
|
require_relative "rubyai/http"
|
4
8
|
require_relative "rubyai/version"
|
5
9
|
|
6
|
-
require 'faraday'
|
7
|
-
|
8
10
|
module RubyAI
|
9
11
|
class Error < StandardError; end
|
10
12
|
end
|
@@ -0,0 +1,5 @@
|
|
1
|
+
## All Submissions:
|
2
|
+
|
3
|
+
* [ ] Have you followed the guidelines in our [Contributing document](../blob/main/CONTRIBUTING.md)?
|
4
|
+
* [ ] Have you checked to ensure there aren't other open [Pull Requests](../pulls) for the same update/change?
|
5
|
+
* [ ] Have you added an explanation of what your changes do and why you'd like us to include them?
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require_relative '../lib/rubyai/client.rb'
|
3
|
+
|
4
|
+
RSpec.describe RubyAI::Client do
|
5
|
+
let(:api_key) { 'your_api_key' }
|
6
|
+
let(:messages) { 'Hello, how are you?' }
|
7
|
+
let(:temperature) { 0.7 }
|
8
|
+
let(:model) { 'gpt-3.5-turbo' }
|
9
|
+
let(:client) { described_class.new(api_key: api_key, messages: messages, temperature: temperature, model: model) }
|
10
|
+
|
11
|
+
describe '#call' do
|
12
|
+
let(:response_body) { { 'completion' => 'This is a response from the model.' } }
|
13
|
+
let(:status) { 200 }
|
14
|
+
|
15
|
+
before do
|
16
|
+
stub_request(:post, RubyAI::Configuration::BASE_URL)
|
17
|
+
.to_return(status: status, body: response_body.to_json, headers: { 'Content-Type' => 'application/json' })
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'returns parsed JSON response when passing through client directly' do
|
21
|
+
expect(client.call).to eq(response_body)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'webmock/rspec'
|
2
|
+
require_relative '../lib/rubyai/client.rb'
|
3
|
+
|
4
|
+
RSpec.describe RubyAI::Client do
|
5
|
+
let(:api_key) { 'your_api_key' }
|
6
|
+
let(:messages) { 'Hello, how are you?' }
|
7
|
+
let(:temperature) { 0.7 }
|
8
|
+
let(:model) { 'gpt-3.5-turbo' }
|
9
|
+
|
10
|
+
before do
|
11
|
+
RubyAI.configure do |config|
|
12
|
+
config.api_key = api_key
|
13
|
+
config.messages = messages
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '#call' do
|
18
|
+
let(:response_body) { { 'choices' => [{ 'message' => { 'content' => 'This is a response from the model.' } }] } }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
before do
|
22
|
+
stub_request(:post, RubyAI::Configuration::BASE_URL)
|
23
|
+
.to_return(status: status, body: response_body.to_json, headers: { 'Content-Type' => 'application/json' })
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'returns parsed JSON response when passing through client via configuration' do
|
27
|
+
configuration = { api_key: RubyAI.configuration.api_key, messages: RubyAI.configuration.messages }
|
28
|
+
client = described_class.new(configuration)
|
29
|
+
result = client.call
|
30
|
+
expect(result.dig('choices', 0, 'message', 'content')).to eq('This is a response from the model.')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
16
|
+
RSpec.configure do |config|
|
17
|
+
# rspec-expectations config goes here. You can use an alternate
|
18
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
19
|
+
# assertions if you prefer.
|
20
|
+
config.expect_with :rspec do |expectations|
|
21
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
22
|
+
# and `failure_message` of custom matchers include text for helper methods
|
23
|
+
# defined using `chain`, e.g.:
|
24
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
25
|
+
# # => "be bigger than 2 and smaller than 4"
|
26
|
+
# ...rather than:
|
27
|
+
# # => "be bigger than 2"
|
28
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
29
|
+
end
|
30
|
+
|
31
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
32
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
33
|
+
config.mock_with :rspec do |mocks|
|
34
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
35
|
+
# a real object. This is generally recommended, and will default to
|
36
|
+
# `true` in RSpec 4.
|
37
|
+
mocks.verify_partial_doubles = true
|
38
|
+
end
|
39
|
+
|
40
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
41
|
+
# have no way to turn it off -- the option exists only for backwards
|
42
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
43
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
44
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
45
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
46
|
+
|
47
|
+
# The settings below are suggested to provide a good initial experience
|
48
|
+
# with RSpec, but feel free to customize to your heart's content.
|
49
|
+
=begin
|
50
|
+
# This allows you to limit a spec run to individual examples or groups
|
51
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
52
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
53
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
54
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
55
|
+
config.filter_run_when_matching :focus
|
56
|
+
|
57
|
+
# Allows RSpec to persist some state between runs in order to support
|
58
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
59
|
+
# you configure your source control system to ignore this file.
|
60
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
61
|
+
|
62
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
63
|
+
# recommended. For more details, see:
|
64
|
+
# https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/
|
65
|
+
config.disable_monkey_patching!
|
66
|
+
|
67
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
68
|
+
# be too noisy due to issues in dependencies.
|
69
|
+
config.warnings = true
|
70
|
+
|
71
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
72
|
+
# file, and it's useful to allow more verbose output when running an
|
73
|
+
# individual spec file.
|
74
|
+
if config.files_to_run.one?
|
75
|
+
# Use the documentation formatter for detailed output,
|
76
|
+
# unless a formatter has already been configured
|
77
|
+
# (e.g. via a command-line flag).
|
78
|
+
config.default_formatter = "doc"
|
79
|
+
end
|
80
|
+
|
81
|
+
# Print the 10 slowest examples and example groups at the
|
82
|
+
# end of the spec run, to help surface which specs are running
|
83
|
+
# particularly slow.
|
84
|
+
config.profile_examples = 10
|
85
|
+
|
86
|
+
# Run specs in random order to surface order dependencies. If you find an
|
87
|
+
# order dependency and want to debug it, you can fix the order by providing
|
88
|
+
# the seed, which is printed after each run.
|
89
|
+
# --seed 1234
|
90
|
+
config.order = :random
|
91
|
+
|
92
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
93
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
94
|
+
# test failures related to randomization by passing the same `--seed` value
|
95
|
+
# as the one that triggered the failure.
|
96
|
+
Kernel.srand config.seed
|
97
|
+
=end
|
98
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubyai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.5'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Shapalov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday-net_http_persistent
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -39,7 +53,7 @@ dependencies:
|
|
39
53
|
- !ruby/object:Gem::Version
|
40
54
|
version: '3.10'
|
41
55
|
description: RubyAI is a wrapper for the OpenAI API that allows you to interact with
|
42
|
-
GPT-
|
56
|
+
GPT-4 within Ruby/Rails applications. It provides simple methods for integrating
|
43
57
|
language model capabilities into your Ruby projects.
|
44
58
|
email:
|
45
59
|
executables: []
|
@@ -47,6 +61,9 @@ extensions: []
|
|
47
61
|
extra_rdoc_files: []
|
48
62
|
files:
|
49
63
|
- CHANGELOG.md
|
64
|
+
- CODE_OF_CONDUCT.md
|
65
|
+
- CONTRIBUTING.md
|
66
|
+
- Gemfile
|
50
67
|
- LICENSE
|
51
68
|
- README.md
|
52
69
|
- lib/rubyai.rb
|
@@ -54,6 +71,10 @@ files:
|
|
54
71
|
- lib/rubyai/configuration.rb
|
55
72
|
- lib/rubyai/http.rb
|
56
73
|
- lib/rubyai/version.rb
|
74
|
+
- pull_request_template.md
|
75
|
+
- spec/client_spec.rb
|
76
|
+
- spec/configuration_spec.rb
|
77
|
+
- spec/spec_helper.rb
|
57
78
|
homepage: https://github.com/alexshapalov/rubyai
|
58
79
|
licenses:
|
59
80
|
- MIT
|
@@ -64,12 +85,12 @@ metadata:
|
|
64
85
|
post_install_message:
|
65
86
|
rdoc_options: []
|
66
87
|
require_paths:
|
67
|
-
-
|
88
|
+
- lib
|
68
89
|
required_ruby_version: !ruby/object:Gem::Requirement
|
69
90
|
requirements:
|
70
91
|
- - ">="
|
71
92
|
- !ruby/object:Gem::Version
|
72
|
-
version: '2.
|
93
|
+
version: '2.6'
|
73
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
95
|
requirements:
|
75
96
|
- - ">="
|