zuno 0.0.1
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 +7 -0
- data/lib/providers/anthropic.rb +26 -0
- data/lib/providers/openai.rb +26 -0
- data/lib/zuno/chat.rb +35 -0
- data/lib/zuno/configuration.rb +9 -0
- data/lib/zuno/version.rb +5 -0
- data/lib/zuno.rb +17 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51b2206418e88cbbfcd5f130d8e7d0f8486773317bd463e639ddcdf1ded31dd9
|
4
|
+
data.tar.gz: db8b41989dbec0e5f07405a567c56de04b0ed6badb4537514845574ab1afbc37
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 37a62efd042c8511fbe7553a8dcf4ab880886d816317ed31bc5f0800b1554d6205af300394841e6c238700a8b6018ba4be33ec55af8a87c9c983dac773346368
|
7
|
+
data.tar.gz: '028768a79656ab3cb2695ee2d475a0627317eb6cbc87817a782dd0aa6048081c77cc24e4a124d72a00cffae0217c6a516076ef30a33376f86bc8702e04edcec0'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Providers
|
2
|
+
class Anthropic
|
3
|
+
def initialize
|
4
|
+
@connection = Faraday.new(url: "https://api.anthropic.com") do |faraday|
|
5
|
+
faraday.request :json
|
6
|
+
faraday.response :json
|
7
|
+
faraday.adapter Faraday.default_adapter
|
8
|
+
end
|
9
|
+
|
10
|
+
@api_key = Zuno.configuration.openai_api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def chat_completion(messages, model, options = {})
|
14
|
+
response = @connection.post("/v1/chat/completions") do |req|
|
15
|
+
req.headers["Content-Type"] = "application/json"
|
16
|
+
req.headers["Authorization"] = "Bearer #{@api_key}"
|
17
|
+
req.body = {
|
18
|
+
model: model,
|
19
|
+
messages: messages
|
20
|
+
}.merge(options).to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
{ response: response.body["choices"][0]["message"]["content"] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Providers
|
2
|
+
class OpenAI
|
3
|
+
def initialize
|
4
|
+
@connection = Faraday.new(url: "https://api.openai.com") do |faraday|
|
5
|
+
faraday.request :json
|
6
|
+
faraday.response :json
|
7
|
+
faraday.adapter Faraday.default_adapter
|
8
|
+
end
|
9
|
+
|
10
|
+
@api_key = Zuno.configuration.openai_api_key
|
11
|
+
end
|
12
|
+
|
13
|
+
def chat_completion(messages, model, options = {})
|
14
|
+
response = @connection.post("/v1/chat/completions") do |req|
|
15
|
+
req.headers["Content-Type"] = "application/json"
|
16
|
+
req.headers["Authorization"] = "Bearer #{@api_key}"
|
17
|
+
req.body = {
|
18
|
+
model: model,
|
19
|
+
messages: messages
|
20
|
+
}.merge(options).to_json
|
21
|
+
end
|
22
|
+
|
23
|
+
{ response: response.body["choices"][0]["message"]["content"] }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/zuno/chat.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "providers/openai"
|
4
|
+
require "providers/anthropic"
|
5
|
+
|
6
|
+
module Zuno
|
7
|
+
OPENAI_MODELS = %w[gpt-3.5-turbo gpt-4-turbo gpt-4-turbo-preview].freeze
|
8
|
+
ANTHROPIC_MODELS = %w[claude-3-opus-20240229].freeze
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def chat(messages:, model:)
|
12
|
+
model ||= Zuno.configuration.chat_completion_model
|
13
|
+
provider = provider_for_model(model)
|
14
|
+
provider.chat_completion(messages, model)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def provider_for_model(model)
|
20
|
+
case model
|
21
|
+
when *OPENAI_MODELS then Providers::OpenAI.new
|
22
|
+
when *ANTHROPIC_MODELS then Providers::Anthropic.new
|
23
|
+
else
|
24
|
+
raise ArgumentError, "Unsupported model: #{model}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def model_providers_mapping
|
29
|
+
@model_providers_mapping ||= {
|
30
|
+
**OPENAI_MODELS.to_h { |model| [model, Providers::OpenAI.new] },
|
31
|
+
**ANTHROPIC_MODELS.to_h { |model| [model, Providers::Anthropic.new] }
|
32
|
+
}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/zuno/version.rb
ADDED
data/lib/zuno.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "zuno/version"
|
4
|
+
require_relative "zuno/configuration"
|
5
|
+
require "zuno/chat"
|
6
|
+
require "faraday"
|
7
|
+
|
8
|
+
module Zuno
|
9
|
+
class << self
|
10
|
+
attr_accessor :configuration
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.configure
|
14
|
+
self.configuration ||= Configuration.new
|
15
|
+
yield(configuration)
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: zuno
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- John Paul
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-06-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: AI toolkit for Ruby
|
14
|
+
email:
|
15
|
+
- johnarpaul@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/providers/anthropic.rb
|
21
|
+
- lib/providers/openai.rb
|
22
|
+
- lib/zuno.rb
|
23
|
+
- lib/zuno/chat.rb
|
24
|
+
- lib/zuno/configuration.rb
|
25
|
+
- lib/zuno/version.rb
|
26
|
+
homepage: https://github.com/dqnamo
|
27
|
+
licenses:
|
28
|
+
- MIT
|
29
|
+
metadata:
|
30
|
+
homepage_uri: https://github.com/dqnamo
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 3.0.0
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubygems_version: 3.4.10
|
47
|
+
signing_key:
|
48
|
+
specification_version: 4
|
49
|
+
summary: AI toolkit for Ruby
|
50
|
+
test_files: []
|