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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fd6229b4b78dc25546114b25fdab7237c946dbb5c36e0c40c55f5c411b5cc2b6
4
- data.tar.gz: c003ba3200b6236a6eec39d4b9a45b9737599a9c234150ef33ec0697bbfb5482
3
+ metadata.gz: 378df9dab08b062608ea23bba7f54f4abccf4604e76335d7f4a33a1fcb6e3f8e
4
+ data.tar.gz: 83e578be4532ad403e419a4419919ddde40692a7aa7778fdb3be0ac0dad2f26f
5
5
  SHA512:
6
- metadata.gz: f0d6d53335fbebede4f20728e9ce3c067ca3e286980d1d9a978238375e19599c31830cc6fe616b82a4ab662e318a7c567979f6db9a614982141c443bff2f37c1
7
- data.tar.gz: 59a861200fef2fc8b85b548d44866aa7530442ec2baac252b3220555d5cf81b6f5caa98b1c9f4944b613e9f16483e24da9e1b83f5b6a5c9bbfa7773da8797d1f
6
+ metadata.gz: 9a9b863540c88a01a0b33a1f5f6444f74a80644805d407b427169a8dbdc5760004d58e9dc66f70136bdc2df3e20717dae61a4101b5143367f5714fc351ca1256
7
+ data.tar.gz: 70ec8841a22fbefd2cf9e4926f088a6ff674ccef5277d33e32ff8658641b1c3d7b8ffb8b8c13f1add0cb2ce1759dcc69187307c474361dd5727dbd6ad2a6999e
@@ -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.openai_api_key
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/chat/completions") do |req|
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["Authorization"] = "Bearer #{@api_key}"
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
- { response: response.body["choices"][0]["message"]["content"] }
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
@@ -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
- { text: JSON.parse(response.body)["text"] }
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
@@ -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
- { response: response.body["choices"][0]["message"]["content"] }
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
@@ -3,7 +3,10 @@ module Zuno
3
3
  attr_accessor :chat_completion_model, :openai_api_key, :anthropic_api_key, :groq_cloud_api_key
4
4
 
5
5
  def initialize
6
+ @chat_completion_model = nil
6
7
  @openai_api_key = nil
8
+ @anthropic_api_key = nil
9
+ @groq_cloud_api_key = nil
7
10
  end
8
11
  end
9
12
  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.3"
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.3
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: