zuno 0.0.2 → 0.0.4

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: cf1792df415cee7140b1c93937b432fa7dbcc1d9f36ac3f13484e32712f4ec50
4
- data.tar.gz: f687effb232e1ac3f920102fe06be674709d740c073c85174ffe698abd918883
3
+ metadata.gz: 8d1704ad858e219dc6216e0dd8ac6bdaf8b57cb0052c1a0e4d6dfaed794b75f1
4
+ data.tar.gz: 4580bf2697e8746aad1de8e4f9e42c87be944f00e81fc93758cb299c1fa9e76e
5
5
  SHA512:
6
- metadata.gz: 44f45a9d8f4067bb258436a4b9434c67629bb0c1a23049423b7039ec48fd923b5b0be327abb3547771caaa825407fe8c872e440158d931486848a6fb538498b4
7
- data.tar.gz: 34dec504254b3149893db199bd149f319c95a427cb56d8d82bb7e4ebfd399dfebbc90781392a0d7b85475d64cf3ea144158a0b5ab6d001a61251718ca1d2c26b
6
+ metadata.gz: 13e4b4687664ad655c7125933e37e8adaa0e7440c41b2e9ff3452ba87446e889e00f3c2727189a466340d7756d2ce0f947c50274ec6a5f282b4308d14969b942
7
+ data.tar.gz: ee873e43504615c7ce040e3952ab68e5ab649eda573b035cf1b27e164a10a521657484895c7d93a481803517952eff3bce9180ee440711605c039edeea70cf3d
@@ -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,7 @@ module Providers
24
25
  }
25
26
  )
26
27
 
27
- { text: JSON.parse(response.body)["text"] }
28
+ OpenStruct.new(text: JSON.parse(response.body)["text"])
28
29
  end
29
30
  end
30
31
  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,13 @@ 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
9
 
10
10
  class << self
11
- def chat(messages:, model:)
11
+ def chat(messages:, model:, **options)
12
12
  model ||= Zuno.configuration.chat_completion_model
13
13
  provider = provider_for_model(model)
14
- provider.chat_completion(messages, model)
14
+ provider.chat_completion(messages, model, options)
15
15
  end
16
16
 
17
17
  private
@@ -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
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.2"
4
+ VERSION = "0.0.4"
5
5
  end
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.2
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Paul