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 +4 -4
- data/lib/providers/anthropic.rb +13 -6
- data/lib/providers/groq_cloud.rb +2 -1
- data/lib/providers/openai.rb +7 -1
- data/lib/zuno/chat.rb +3 -3
- data/lib/zuno/configuration.rb +3 -0
- data/lib/zuno/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d1704ad858e219dc6216e0dd8ac6bdaf8b57cb0052c1a0e4d6dfaed794b75f1
|
4
|
+
data.tar.gz: 4580bf2697e8746aad1de8e4f9e42c87be944f00e81fc93758cb299c1fa9e76e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13e4b4687664ad655c7125933e37e8adaa0e7440c41b2e9ff3452ba87446e889e00f3c2727189a466340d7756d2ce0f947c50274ec6a5f282b4308d14969b942
|
7
|
+
data.tar.gz: ee873e43504615c7ce040e3952ab68e5ab649eda573b035cf1b27e164a10a521657484895c7d93a481803517952eff3bce9180ee440711605c039edeea70cf3d
|
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,7 @@ module Providers
|
|
24
25
|
}
|
25
26
|
)
|
26
27
|
|
27
|
-
|
28
|
+
OpenStruct.new(text: JSON.parse(response.body)["text"])
|
28
29
|
end
|
29
30
|
end
|
30
31
|
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,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
|
data/lib/zuno/configuration.rb
CHANGED
data/lib/zuno/version.rb
CHANGED