zuno 0.0.4 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d1704ad858e219dc6216e0dd8ac6bdaf8b57cb0052c1a0e4d6dfaed794b75f1
4
- data.tar.gz: 4580bf2697e8746aad1de8e4f9e42c87be944f00e81fc93758cb299c1fa9e76e
3
+ metadata.gz: 378df9dab08b062608ea23bba7f54f4abccf4604e76335d7f4a33a1fcb6e3f8e
4
+ data.tar.gz: 83e578be4532ad403e419a4419919ddde40692a7aa7778fdb3be0ac0dad2f26f
5
5
  SHA512:
6
- metadata.gz: 13e4b4687664ad655c7125933e37e8adaa0e7440c41b2e9ff3452ba87446e889e00f3c2727189a466340d7756d2ce0f947c50274ec6a5f282b4308d14969b942
7
- data.tar.gz: ee873e43504615c7ce040e3952ab68e5ab649eda573b035cf1b27e164a10a521657484895c7d93a481803517952eff3bce9180ee440711605c039edeea70cf3d
6
+ metadata.gz: 9a9b863540c88a01a0b33a1f5f6444f74a80644805d407b427169a8dbdc5760004d58e9dc66f70136bdc2df3e20717dae61a4101b5143367f5714fc351ca1256
7
+ data.tar.gz: 70ec8841a22fbefd2cf9e4926f088a6ff674ccef5277d33e32ff8658641b1c3d7b8ffb8b8c13f1add0cb2ce1759dcc69187307c474361dd5727dbd6ad2a6999e
@@ -27,5 +27,38 @@ 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
+ else
60
+ OpenStruct.new(response: parsed_response["choices"][0]["message"]["content"])
61
+ end
62
+ end
30
63
  end
31
64
  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:, **options)
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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "providers/groq_cloud"
4
+
5
+ module Zuno
6
+ class << self
7
+ def translate(audio:)
8
+ Providers::GroqCloud.new.translate(audio)
9
+ end
10
+ end
11
+ end
data/lib/zuno/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Zuno
4
- VERSION = "0.0.4"
4
+ VERSION = "0.0.5"
5
5
  end
data/lib/zuno.rb CHANGED
@@ -4,6 +4,7 @@ require_relative "zuno/version"
4
4
  require_relative "zuno/configuration"
5
5
  require "zuno/chat"
6
6
  require "zuno/transcription"
7
+ require "zuno/translation"
7
8
  require "faraday"
8
9
 
9
10
  module Zuno
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
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: