rubyai 0.3.1 → 0.4

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: 387f6d1b2686f5605793b342f64de039e2510d2678f33568216e80db7ea48582
4
- data.tar.gz: 3224788966e4af7d6ed44987616561bfde72f649cde944a0dab594c64f50c88a
3
+ metadata.gz: 4b9da34a736ede8391653fcbd4cb79915f7bca92453e643a9cba365805170053
4
+ data.tar.gz: db62c0c8fd350117bdfd4f612ab884a741d7253932e649ce8b66e5c61418d09b
5
5
  SHA512:
6
- metadata.gz: 84c4e0354f8aa8c30322c088dae333104068ea23aff9530a7ff222b30f4d5c14b563da13ddee527ce989512d8b2296f8239ad384d9cd7df38295348eb3a1961e
7
- data.tar.gz: 506a3f86bf010e48d2b4e8c7567d948664a5bda8eb9e7f743bab11d5b324850802161a8967d10575d7872da7ef0437ef2ac5cdf663b80d988cc1e60043dfcf76
6
+ metadata.gz: 056ecb00899c57c51bbf65c8846cf6dc089025963e5693edc2b6722a6ff0c7e0338fb71034490c8254de8df169e9bd70d66daea3ef95d0a6b99fdc95520152aa
7
+ data.tar.gz: f4ee20d2aa5fa24b9071108b37d81d40fca9e055531f20a4297c8dab80da47cc37e62da2365c8870d2210b2cb850178db15a42f3ea018afde814bf3e8eb12fbe
data/CHANGELOG.md ADDED
@@ -0,0 +1,60 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+
9
+ ## [0.3.2] - 2024-11-21
10
+
11
+ ### Added
12
+
13
+ - Update Gemspec and dependencies
14
+
15
+ ## [0.3] - 2024-11-21
16
+
17
+ ### Added
18
+
19
+ - gpt-4-turbo
20
+ - gpt-4o-mini
21
+ - o1-mini
22
+ - o1-preview
23
+
24
+ - Remove outdated GPT 3.5 models
25
+
26
+ ## [0.2] - 2024-04-20
27
+
28
+ ### Added
29
+
30
+ - New version
31
+
32
+ ## [0.1.0] - 2024-01-21
33
+
34
+ ### Added
35
+
36
+ - Github Action
37
+ - Faraday gem
38
+
39
+ ## [0.0.3] - 2024-02-22
40
+
41
+ ### Added
42
+
43
+ - Rubocop gem
44
+
45
+ ## [0.0.2] - 2024-02-23
46
+
47
+ ### Added
48
+
49
+ - Models GPT-4
50
+
51
+ ## [0.0.1] - 2023-03-20
52
+
53
+ ### Added
54
+
55
+ - Initialise repository.
56
+ - Add RubyAI::Client to connect to OpenAI API using user credentials.
57
+
58
+
59
+
60
+
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Alex Shapalov
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,107 @@
1
+ # RubyAI - OpenAI integration Ruby gem
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rubyai.svg)](https://badge.fury.io/rb/rubyai)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexshapalov/rubyai/blob/main/LICENSE)
5
+
6
+ ## Use the [OpenAI API 🤖 ](https://openai.com/blog/openai-api/) with Ruby! ❤️
7
+
8
+ Generate text with ChatGPT (Generative Pre-trained Transformer)
9
+
10
+
11
+ # Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem "rubyai"
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle install
22
+
23
+
24
+ Or install with:
25
+
26
+ $ gem install rubyai
27
+
28
+ and require with:
29
+
30
+ ```ruby
31
+ require "rubyai"
32
+ ```
33
+
34
+ # Usage
35
+
36
+ - Get your API key from [https://beta.openai.com/account/api-keys](https://beta.openai.com/account/api-keys)
37
+
38
+ - If you belong to multiple organizations, you can get your Organization ID from [https://beta.openai.com/account/org-settings](https://beta.openai.com/account/org-settings)
39
+
40
+ ### Quickstart
41
+
42
+ For a quick test you can pass your token directly to a new client:
43
+
44
+ ```ruby
45
+ result = RubyAI::Client.new(access_token, messages).call
46
+ ```
47
+
48
+ ### ChatGPT
49
+
50
+ ChatGPT is a conversational-style text generation model.
51
+ You can use it to [generate a response](https://platform.openai.com/docs/api-reference/chat/create) to a sequence of [messages](https://platform.openai.com/docs/guides/chat/introduction):
52
+
53
+ ```ruby
54
+ api_key = "YOUR API KEY"
55
+ messages = "Who is the best chess player in history?"
56
+
57
+ result = RubyAI::Client.new(api_key, messages, model: "gpt-4").call
58
+ puts result.dig("choices", 0, "message", "content")
59
+
60
+ # => As an AI language model, I do not have personal opinions, but according to historical records, Garry Kasparov is often considered as one of the best chess players in history. Other notable players include Magnus Carlsen, Bobby Fischer, and Jose Capablanca.
61
+ ```
62
+
63
+ You can also pass client variables using the configuration file.
64
+ Create configruation file like on example:
65
+ ```ruby
66
+ configuration = RubyAI::Configuration.new("YOUR API KEY", "Who is the best chess player in history?")
67
+ client = RubyAI::Client.new(configuration)
68
+ result = client.call
69
+ puts result.dig("choices", 0, "message", "content")
70
+ ```
71
+
72
+ Also (mostly) if you are using Rails you can use configure method:
73
+ ```ruby
74
+ RubyAI.configure do |config|
75
+ config.api_key = "YOUR API KEY"
76
+ config.messages = "Who is the best chess player in history?"
77
+ config.model = "gpt-4o-mini"
78
+ end
79
+ ```
80
+
81
+ ## Models
82
+
83
+ We support all popular GPT models:
84
+
85
+ gpt-4-turbo: A powerful variant of GPT-4 optimized for efficiency and speed, perfect for high-demand tasks.
86
+
87
+ gpt-4o-mini: A streamlined version of GPT-4, designed to provide a balance between performance and resource efficiency.
88
+
89
+ o1-mini: A compact, yet effective model that is well-suited for lightweight tasks.
90
+
91
+ o1-preview: A preview version of the o1 model, offering insights into upcoming advancements and features.
92
+
93
+
94
+ ## Development
95
+
96
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
97
+
98
+ To install this gem onto your local machine, run `bundle exec rake install`.
99
+
100
+
101
+ ## Contributing
102
+
103
+ 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.
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,27 @@
1
+ module RubyAI
2
+ class Client
3
+ attr_reader :configuration
4
+
5
+ def initialize(config_hash = {})
6
+ @configuration = Configuration.new(config_hash)
7
+ end
8
+
9
+ def call
10
+ response = connection.post do |req|
11
+ req.url Configuration::BASE_URL
12
+ req.headers.merge!(HTTP.build_headers(configuration.api_key))
13
+ req.body = HTTP.build_body(configuration.messages, configuration.model, configuration.temperature).to_json
14
+ end
15
+
16
+ JSON.parse(response.body)
17
+ end
18
+
19
+ private
20
+
21
+ def connection
22
+ @connection ||= Faraday.new do |faraday|
23
+ faraday.adapter Faraday.default_adapter
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ module RubyAI
2
+ class Configuration
3
+ BASE_URL = "https://api.openai.com/v1/chat/completions"
4
+
5
+ MODELS = {
6
+ "gpt-4" => "gpt-4",
7
+ "gpt-4-32k" => "gpt-4-32k",
8
+ "gpt-4-turbo" => "gpt-4-turbo",
9
+ "gpt-4o-mini" => "gpt-4o-mini",
10
+ "o1-mini" => "o1-mini",
11
+ "o1-preview" => "o1-preview",
12
+ "text-davinci-003" => "text-davinci-003"
13
+ }
14
+
15
+ DEFAULT_MODEL = "gpt-3.5-turbo"
16
+
17
+ attr_accessor :api_key, :model, :messages, :temperature
18
+
19
+ def initialize(config = {})
20
+ @api_key = config[:api_key]
21
+ @model = config.fetch(:model, DEFAULT_MODEL)
22
+ @messages = config.fetch(:messages, nil)
23
+ @temperature = config.fetch(:temperature, 0.7)
24
+ end
25
+ end
26
+
27
+ def self.configuration
28
+ @configuration ||= Configuration.new
29
+ end
30
+
31
+ def self.configure
32
+ yield(configuration)
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module RubyAI
2
+ module HTTP
3
+ extend self
4
+
5
+ def build_body(messages, model, temperature)
6
+ {
7
+ 'model': Configuration::MODELS[model],
8
+ 'messages': [{ "role": "user", "content": messages }],
9
+ 'temperature': temperature
10
+ }
11
+ end
12
+
13
+ def build_headers(api_key)
14
+ {
15
+ 'Content-Type': 'application/json',
16
+ 'Authorization': "Bearer #{api_key}"
17
+ }
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module RubyAI
2
+ VERSION = "0.1.0".freeze
3
+ end
data/lib/rubyai.rb CHANGED
@@ -1,6 +1,10 @@
1
1
  require_relative "rubyai/client"
2
2
  require_relative "rubyai/configuration"
3
+ require_relative "rubyai/http"
4
+ require_relative "rubyai/version"
5
+
6
+ require 'faraday'
3
7
 
4
8
  module RubyAI
5
9
  class Error < StandardError; end
6
- end
10
+ end
metadata CHANGED
@@ -1,35 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubyai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
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-21 00:00:00.000000000 Z
12
- dependencies: []
13
- description:
11
+ date: 2024-10-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.10'
41
+ description: RubyAI is a wrapper for the OpenAI API that allows you to interact with
42
+ GPT-3 and GPT-4 from within Ruby applications. It provides simple methods for integrating
43
+ language model capabilities into your Ruby projects.
14
44
  email:
15
45
  executables: []
16
46
  extensions: []
17
47
  extra_rdoc_files: []
18
48
  files:
49
+ - CHANGELOG.md
50
+ - LICENSE
51
+ - README.md
19
52
  - lib/rubyai.rb
53
+ - lib/rubyai/client.rb
54
+ - lib/rubyai/configuration.rb
55
+ - lib/rubyai/http.rb
56
+ - lib/rubyai/version.rb
20
57
  homepage: https://github.com/alexshapalov/rubyai
21
58
  licenses:
22
59
  - MIT
23
- metadata: {}
60
+ metadata:
61
+ source_code_uri: https://github.com/alexshapalov/rubyai
62
+ changelog_uri: https://github.com/alexshapalov/rubyai/CHANGELOG.md
63
+ documentation_uri: https://github.com/alexshapalov/rubyai#readme
24
64
  post_install_message:
25
65
  rdoc_options: []
26
66
  require_paths:
27
- - lib
67
+ - "."
28
68
  required_ruby_version: !ruby/object:Gem::Requirement
29
69
  requirements:
30
70
  - - ">="
31
71
  - !ruby/object:Gem::Version
32
- version: '0'
72
+ version: '2.7'
33
73
  required_rubygems_version: !ruby/object:Gem::Requirement
34
74
  requirements:
35
75
  - - ">="
@@ -39,5 +79,5 @@ requirements: []
39
79
  rubygems_version: 3.5.11
40
80
  signing_key:
41
81
  specification_version: 4
42
- summary: A Ruby gem for the OpenAI (GPT-3 and GPT-4) API
82
+ summary: A Ruby gem for the OpenAI (GPT-4) API
43
83
  test_files: []