zuno 0.0.4 → 0.1.0
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/groq_cloud.rb +35 -0
- data/lib/providers/openai.rb +3 -1
- data/lib/zuno/chat.rb +5 -2
- data/lib/zuno/translation.rb +11 -0
- data/lib/zuno/version.rb +1 -1
- data/lib/zuno.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77955f7ab70bc212f516b3a7590a00eb03c3790df12a3e2eecb823dd7d1ffea8
|
4
|
+
data.tar.gz: 6e50ab43d348817f32c2b589204bc582a0f071d3eeb483bc294f759211e05509
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98da00fecffe4ea2a97b71bc6425c69b0da202e57665f58c4b557a1740b7c44555c2e5508b7aaf63a3e83d1647137e482a5133ef034220d7402cbe9566a166c9
|
7
|
+
data.tar.gz: c51e1ee3944c3c63233cfbfdaee925406f169fc9d7467b4aaaa5ac33f5967255a0c5ce6117a4e1b50498dfcac764c1bf26c490428956edb00e0975d0f6e8cc8a
|
data/lib/providers/groq_cloud.rb
CHANGED
@@ -27,5 +27,40 @@ module Providers
|
|
27
27
|
|
28
28
|
OpenStruct.new(text: JSON.parse(response.body)["text"])
|
29
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
|
+
elsif parsed_response["choices"][0]["message"]["content"]
|
60
|
+
OpenStruct.new(response: parsed_response["choices"][0]["message"]["content"])
|
61
|
+
elsif parsed_response["choices"][0]["message"]["tool_calls"]
|
62
|
+
OpenStruct.new(tool_calls: parsed_response["choices"][0]["message"]["tool_calls"])
|
63
|
+
end
|
64
|
+
end
|
30
65
|
end
|
31
66
|
end
|
data/lib/providers/openai.rb
CHANGED
@@ -24,8 +24,10 @@ module Providers
|
|
24
24
|
|
25
25
|
if response.body["error"]
|
26
26
|
raise response.body["error"]["message"]
|
27
|
-
|
27
|
+
elsif response.body["choices"][0]["message"]["content"]
|
28
28
|
OpenStruct.new(response: response.body["choices"][0]["message"]["content"])
|
29
|
+
elsif response.body["choices"][0]["message"]["tool_calls"]
|
30
|
+
OpenStruct.new(tool_calls: response.body["choices"][0]["message"]["tool_calls"])
|
29
31
|
end
|
30
32
|
end
|
31
33
|
end
|
data/lib/zuno/chat.rb
CHANGED
@@ -6,9 +6,10 @@ require "providers/anthropic"
|
|
6
6
|
module Zuno
|
7
7
|
OPENAI_MODELS = %w[gpt-3.5-turbo gpt-4-turbo gpt-4-turbo-preview].freeze
|
8
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
15
|
provider.chat_completion(messages, model, options)
|
@@ -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/version.rb
CHANGED
data/lib/zuno.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: zuno
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Paul
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-07-
|
11
|
+
date: 2024-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: AI toolkit for Ruby
|
14
14
|
email:
|
@@ -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:
|