omniai 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +13 -0
- data/bin/console +8 -0
- data/bin/setup +6 -0
- data/lib/omniai/chat/completion/response.rb +0 -0
- data/lib/omniai/chat/completion.rb +74 -0
- data/lib/omniai/chat.rb +34 -0
- data/lib/omniai/client.rb +31 -20
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +17 -1
- metadata +15 -37
- data/.rspec +0 -3
- data/.rubocop.yml +0 -2
- data/Rakefile +0 -12
- data/sig/omniai.rbs +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62a5db8ecb28e379812a5dce657588fb44c55b7af4b8a2463bdb712d91b9f0a9
|
4
|
+
data.tar.gz: 3d5a935c85975fb46a5062c8a4999c0f1fcdb187f2aa542863a4503791dc095b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4846e70507f51344862e5382ffcf5043b4896408eff86377d75af7439bd5cb6d865a19b84f67ae87be686c9c0be9e1005d3321896a3083ea2a0d208e051a2a6b
|
7
|
+
data.tar.gz: ab185c7be3efffc942c9eb104f4ad77bec9847718f0ee91456e2fd57cd1fd2ca3206fc73f601ba964084bb0c6aa3450da17c8280c53592fa363854d19640faae
|
data/Gemfile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
File without changes
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
class Chat
|
5
|
+
# An abstract class that provides an interface for chatting for various vendors (e.g. OpenAI::OpenAI::ChatGPT::Completion).
|
6
|
+
#
|
7
|
+
# Usage:
|
8
|
+
#
|
9
|
+
# class OmniAI::OpenAI::ChatGPT::Completion < OmniAI::Chat::Completion
|
10
|
+
# module Model
|
11
|
+
# CHAT = "davinci"
|
12
|
+
# end
|
13
|
+
# def completion(messages, model:, temperature: 0.0, format: :text)
|
14
|
+
# end
|
15
|
+
# end
|
16
|
+
#
|
17
|
+
# Once defined, the subclass can be used to interface with the vendor's chat API as follows:
|
18
|
+
#
|
19
|
+
# client.chat.completion(messages, model: "...", temperature: 0.0, format: :text)
|
20
|
+
class Completion
|
21
|
+
# @param client [OmniAI::Client] the client
|
22
|
+
# @param messages [String]
|
23
|
+
# @param model [String]
|
24
|
+
# @param temperature [Float]
|
25
|
+
# @param format [Symbol] either :text or :json
|
26
|
+
def initialize(client:, messages:, model:, temperature: 0.0, format: :text)
|
27
|
+
@client = client
|
28
|
+
@messages = messages
|
29
|
+
@model = model
|
30
|
+
@temperature = temperature
|
31
|
+
@format = format
|
32
|
+
end
|
33
|
+
|
34
|
+
# @param prompt [String, Message]
|
35
|
+
# @param model [String]
|
36
|
+
# @param format [Symbol] either :text or :json
|
37
|
+
# @param temperature [Float]
|
38
|
+
# @return [Hash]
|
39
|
+
# @raise [ExecutionError]
|
40
|
+
def process!
|
41
|
+
response = request!
|
42
|
+
raise HTTPError, response unless response.status.ok?
|
43
|
+
|
44
|
+
parse!(response:)
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
# @param response [HTTP::Response]
|
50
|
+
# @return [OmniAI::Chat::Completion::Response]
|
51
|
+
def parse!(response:)
|
52
|
+
raise NotImplementedError, "#{self.class.name}#parse! undefined"
|
53
|
+
end
|
54
|
+
|
55
|
+
# @return [Hash]
|
56
|
+
def payload
|
57
|
+
raise NotImplementedError, "#{self.class.name}#payload undefined"
|
58
|
+
end
|
59
|
+
|
60
|
+
# @return [String]
|
61
|
+
def path
|
62
|
+
raise NotImplementedError, "#{self.class.name}#path undefined"
|
63
|
+
end
|
64
|
+
|
65
|
+
# @return [HTTP::Response]
|
66
|
+
def request!
|
67
|
+
@client
|
68
|
+
.connection
|
69
|
+
.accept(:json)
|
70
|
+
.post(path, json: payload)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/omniai/chat.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
# An abstract class that provides an interface for chatting for various vendors (e.g. OpenAI::ChatGPT).
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# class OmniAI::OpenAI::Chat < OmniAI::Chat
|
9
|
+
# def completion(messages, model:, temperature: 0.0, format: :text)
|
10
|
+
# # TODO: implement
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# Once defined, it can be used to interface with the vendor's chat API as follows:
|
15
|
+
#
|
16
|
+
# client.chat.completion("...", model: "...", temperature: 0.0, format: :text)
|
17
|
+
#
|
18
|
+
# @param client [OmniAI::Client] the client
|
19
|
+
class Chat
|
20
|
+
def initialize(client:)
|
21
|
+
@client = client
|
22
|
+
end
|
23
|
+
|
24
|
+
# @raise [OmniAI::Error]
|
25
|
+
# @param messages [String]
|
26
|
+
# @param model [String]
|
27
|
+
# @param format [Symbol] either :text or :json
|
28
|
+
# @param temperature [Float]
|
29
|
+
# @return [OmniAI::Chat::Completion] an instance of OmniAI::Chat::Completion
|
30
|
+
def completion(messages, model:, temperature: 0.0, format: :text)
|
31
|
+
raise NotImplementedError, "#{self.class.name}#completion undefined"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/omniai/client.rb
CHANGED
@@ -1,27 +1,38 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
#
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
#
|
13
|
-
#
|
14
|
-
#
|
3
|
+
module OmniAI
|
4
|
+
# An abstract class that must be subclassed (e.g. OmniAI::OpenAI::Client).
|
5
|
+
#
|
6
|
+
# Usage:
|
7
|
+
#
|
8
|
+
# class OmniAI::OpenAI::Client < OmniAI::Client
|
9
|
+
# def initialize(api_key: ENV.fetch('OPENAI_API_KEY'))
|
10
|
+
# super
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# @return [OmniAI::OpenAI::Chat]
|
14
|
+
# def chat
|
15
|
+
# # TODO: implement
|
16
|
+
# end
|
17
|
+
# end
|
18
|
+
class Client
|
19
|
+
class Error < StandardError; end
|
15
20
|
|
16
|
-
|
17
|
-
class Error < StandardError; end
|
21
|
+
attr_accessor :api_key
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
+
# @param api_key [String]
|
24
|
+
def initialize(api_key:)
|
25
|
+
@api_key = api_key
|
26
|
+
end
|
27
|
+
|
28
|
+
# @return [HTTP::Client]
|
29
|
+
def connection
|
30
|
+
HTTP.auth("Bearer #{api_key}")
|
31
|
+
end
|
23
32
|
|
24
|
-
|
25
|
-
|
33
|
+
# @return [OmniAI::Chat] an instance of OmniAI::Chat
|
34
|
+
def chat
|
35
|
+
raise NotImplementedError, "#{self.class.name}#chat undefined"
|
36
|
+
end
|
26
37
|
end
|
27
38
|
end
|
data/lib/omniai/version.rb
CHANGED
data/lib/omniai.rb
CHANGED
@@ -1,7 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require 'http'
|
4
|
+
|
5
|
+
require_relative 'omniai/version'
|
6
|
+
require_relative 'omniai/client'
|
7
|
+
require_relative 'omniai/chat'
|
8
|
+
require_relative 'omniai/chat/completion'
|
4
9
|
|
5
10
|
module OmniAI
|
6
11
|
class Error < StandardError; end
|
12
|
+
|
13
|
+
# An error that wraps an HTTP::Response for non-OK requests.
|
14
|
+
class HTTPError < Error
|
15
|
+
attr_accessor :response
|
16
|
+
|
17
|
+
# @param response [HTTP::Response]
|
18
|
+
def initialize(response)
|
19
|
+
super("status=#{response.status} headers=#{response.headers} body=#{response.body}")
|
20
|
+
@response = response
|
21
|
+
end
|
22
|
+
end
|
7
23
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -24,53 +24,31 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
|
-
description: Gives a consistent interface for interacting with OpenAI's ChatGPT, Google's
|
56
|
-
Gemini, Anthropic's Claude, Mistral's LeChat, and more.
|
27
|
+
description: An interface for OpenAI's ChatGPT, Google's Gemini, Anthropic's Claude,
|
28
|
+
Mistral's LeChat, etc.
|
57
29
|
email:
|
58
30
|
- kevin@ksylvest.com
|
59
31
|
executables: []
|
60
32
|
extensions: []
|
61
33
|
extra_rdoc_files: []
|
62
34
|
files:
|
63
|
-
-
|
64
|
-
- ".rubocop.yml"
|
35
|
+
- Gemfile
|
65
36
|
- README.md
|
66
|
-
-
|
37
|
+
- bin/console
|
38
|
+
- bin/setup
|
67
39
|
- lib/omniai.rb
|
40
|
+
- lib/omniai/chat.rb
|
41
|
+
- lib/omniai/chat/completion.rb
|
42
|
+
- lib/omniai/chat/completion/response.rb
|
68
43
|
- lib/omniai/client.rb
|
69
44
|
- lib/omniai/version.rb
|
70
|
-
- sig/omniai.rbs
|
71
45
|
homepage: https://github.com/ksylvest/omniai
|
72
46
|
licenses: []
|
73
|
-
metadata:
|
47
|
+
metadata:
|
48
|
+
homepage_uri: https://github.com/ksylvest/omniai
|
49
|
+
source_code_uri: https://github.com/ksylvest/omniai
|
50
|
+
changelog_uri: https://github.com/ksylvest/omniai/releases
|
51
|
+
rubygems_mfa_required: 'true'
|
74
52
|
post_install_message:
|
75
53
|
rdoc_options: []
|
76
54
|
require_paths:
|
@@ -79,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
79
57
|
requirements:
|
80
58
|
- - ">="
|
81
59
|
- !ruby/object:Gem::Version
|
82
|
-
version: 3.
|
60
|
+
version: 3.3.0
|
83
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
62
|
requirements:
|
85
63
|
- - ">="
|
data/.rspec
DELETED
data/.rubocop.yml
DELETED
data/Rakefile
DELETED
data/sig/omniai.rbs
DELETED