zuno 0.0.3 → 0.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/lib/providers/anthropic.rb +13 -6
- data/lib/providers/groq_cloud.rb +35 -1
- data/lib/providers/openai.rb +7 -1
- data/lib/zuno/chat.rb +7 -4
- data/lib/zuno/configuration.rb +3 -0
- data/lib/zuno/translation.rb +11 -0
- data/lib/zuno/version.rb +1 -1
- data/lib/zuno.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378df9dab08b062608ea23bba7f54f4abccf4604e76335d7f4a33a1fcb6e3f8e
|
4
|
+
data.tar.gz: 83e578be4532ad403e419a4419919ddde40692a7aa7778fdb3be0ac0dad2f26f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9a9b863540c88a01a0b33a1f5f6444f74a80644805d407b427169a8dbdc5760004d58e9dc66f70136bdc2df3e20717dae61a4101b5143367f5714fc351ca1256
|
7
|
+
data.tar.gz: 70ec8841a22fbefd2cf9e4926f088a6ff674ccef5277d33e32ff8658641b1c3d7b8ffb8b8c13f1add0cb2ce1759dcc69187307c474361dd5727dbd6ad2a6999e
|
data/lib/providers/anthropic.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Providers
|
2
4
|
class Anthropic
|
3
5
|
def initialize
|
@@ -7,20 +9,25 @@ module Providers
|
|
7
9
|
faraday.adapter Faraday.default_adapter
|
8
10
|
end
|
9
11
|
|
10
|
-
@api_key = Zuno.configuration.
|
12
|
+
@api_key = Zuno.configuration.anthropic_api_key
|
11
13
|
end
|
12
14
|
|
13
15
|
def chat_completion(messages, model, options = {})
|
14
|
-
response = @connection.post("/v1/
|
16
|
+
response = @connection.post("/v1/messages") do |req|
|
17
|
+
req.headers["x-api-key"] = @api_key
|
15
18
|
req.headers["Content-Type"] = "application/json"
|
16
|
-
req.headers["
|
19
|
+
req.headers["anthropic-version"] = "2023-06-01"
|
17
20
|
req.body = {
|
18
21
|
model: model,
|
19
|
-
messages: messages
|
22
|
+
messages: messages,
|
20
23
|
}.merge(options).to_json
|
21
24
|
end
|
22
|
-
|
23
|
-
|
25
|
+
|
26
|
+
if response.body["error"]
|
27
|
+
raise response.body["error"]["message"]
|
28
|
+
else
|
29
|
+
OpenStruct.new(response: response.body["content"][0]["text"])
|
30
|
+
end
|
24
31
|
end
|
25
32
|
end
|
26
33
|
end
|
data/lib/providers/groq_cloud.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'httparty'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'ostruct'
|
3
4
|
|
4
5
|
module Providers
|
5
6
|
class GroqCloud
|
@@ -24,7 +25,40 @@ module Providers
|
|
24
25
|
}
|
25
26
|
)
|
26
27
|
|
27
|
-
|
28
|
+
OpenStruct.new(text: JSON.parse(response.body)["text"])
|
29
|
+
end
|
30
|
+
|
31
|
+
def translate(audio)
|
32
|
+
response = self.class.post(
|
33
|
+
'/openai/v1/audio/translations',
|
34
|
+
multipart: true,
|
35
|
+
body: {
|
36
|
+
file: audio,
|
37
|
+
model: 'whisper-large-v3',
|
38
|
+
temperature: 0,
|
39
|
+
response_format: 'json',
|
40
|
+
}
|
41
|
+
)
|
42
|
+
|
43
|
+
OpenStruct.new(text: JSON.parse(response.body)["text"])
|
44
|
+
end
|
45
|
+
|
46
|
+
def chat_completion(messages, model, options = {})
|
47
|
+
response = self.class.post(
|
48
|
+
'/openai/v1/chat/completions',
|
49
|
+
body: {
|
50
|
+
model: model,
|
51
|
+
messages: messages
|
52
|
+
}.merge(options).to_json
|
53
|
+
)
|
54
|
+
|
55
|
+
parsed_response = JSON.parse(response.body)
|
56
|
+
|
57
|
+
if parsed_response["error"]
|
58
|
+
raise parsed_response["error"]["message"]
|
59
|
+
else
|
60
|
+
OpenStruct.new(response: parsed_response["choices"][0]["message"]["content"])
|
61
|
+
end
|
28
62
|
end
|
29
63
|
end
|
30
64
|
end
|
data/lib/providers/openai.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
1
3
|
module Providers
|
2
4
|
class OpenAI
|
3
5
|
def initialize
|
@@ -20,7 +22,11 @@ module Providers
|
|
20
22
|
}.merge(options).to_json
|
21
23
|
end
|
22
24
|
|
23
|
-
|
25
|
+
if response.body["error"]
|
26
|
+
raise response.body["error"]["message"]
|
27
|
+
else
|
28
|
+
OpenStruct.new(response: response.body["choices"][0]["message"]["content"])
|
29
|
+
end
|
24
30
|
end
|
25
31
|
end
|
26
32
|
end
|
data/lib/zuno/chat.rb
CHANGED
@@ -5,13 +5,14 @@ require "providers/anthropic"
|
|
5
5
|
|
6
6
|
module Zuno
|
7
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
|
8
|
+
ANTHROPIC_MODELS = %w[claude-3-5-sonnet-20240620 claude-3-opus-20240229 claude-3-sonnet-20240229 claude-3-haiku-20240307].freeze
|
9
|
+
GROQ_CLOUD_MODELS = %w[llama3-8b-8192 llama3-70b-8192 mixtral-8x7b-32768 gemma-7b-it gemma2-9b-it].freeze
|
9
10
|
|
10
11
|
class << self
|
11
|
-
def chat(messages:, model:)
|
12
|
+
def chat(messages:, model: nil, **options)
|
12
13
|
model ||= Zuno.configuration.chat_completion_model
|
13
14
|
provider = provider_for_model(model)
|
14
|
-
provider.chat_completion(messages, model)
|
15
|
+
provider.chat_completion(messages, model, options)
|
15
16
|
end
|
16
17
|
|
17
18
|
private
|
@@ -20,6 +21,7 @@ module Zuno
|
|
20
21
|
case model
|
21
22
|
when *OPENAI_MODELS then Providers::OpenAI.new
|
22
23
|
when *ANTHROPIC_MODELS then Providers::Anthropic.new
|
24
|
+
when *GROQ_CLOUD_MODELS then Providers::GroqCloud.new
|
23
25
|
else
|
24
26
|
raise ArgumentError, "Unsupported model: #{model}"
|
25
27
|
end
|
@@ -28,7 +30,8 @@ module Zuno
|
|
28
30
|
def model_providers_mapping
|
29
31
|
@model_providers_mapping ||= {
|
30
32
|
**OPENAI_MODELS.to_h { |model| [model, Providers::OpenAI.new] },
|
31
|
-
**ANTHROPIC_MODELS.to_h { |model| [model, Providers::Anthropic.new] }
|
33
|
+
**ANTHROPIC_MODELS.to_h { |model| [model, Providers::Anthropic.new] },
|
34
|
+
**GROQ_CLOUD_MODELS.to_h { |model| [model, Providers::GroqCloud.new] }
|
32
35
|
}
|
33
36
|
end
|
34
37
|
end
|
data/lib/zuno/configuration.rb
CHANGED
data/lib/zuno/version.rb
CHANGED
data/lib/zuno.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Paul
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- lib/zuno/chat.rb
|
25
25
|
- lib/zuno/configuration.rb
|
26
26
|
- lib/zuno/transcription.rb
|
27
|
+
- lib/zuno/translation.rb
|
27
28
|
- lib/zuno/version.rb
|
28
29
|
homepage: https://github.com/dqnamo
|
29
30
|
licenses:
|