omniai-anthropic 2.6.3 → 2.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d649f48ca88feb9f8e50084e23056018b8c4686a0d75fd0191acceefc60e32fa
4
- data.tar.gz: e00ff5518435b57a3a2b77cde19a9632f9a8bd620377a2a37c3ebfe77b036148
3
+ metadata.gz: b7d29daa6ac2d97df35d173aa8942a89cc6aadb19086b29704c18aabaaafaa99
4
+ data.tar.gz: 46947aa8180b213f2a93e5ac65adbc7987d4b6c1c13959fed38a06762ef94314
5
5
  SHA512:
6
- metadata.gz: 0e501003829f8f263daf8736feedde7697f21c3eb93b046f61255643e6a77bc96006532b232e2f7707041d962d3e2ac87125fd618680ec3ba6908dc86d521326
7
- data.tar.gz: 3bfba26cfdf4e8cc90ce1d9446aac5e61f9d9e23b7ede7bd3ea1d47c898ead9772c2f5ade6a9eaf21b469c5ab94f464f37e13b6ddc178281513f8cd29c74ff41
6
+ metadata.gz: c43605fdfa8ebf6ff5302fc296f428cbded2c0f81048621d9d4904e91a47ccd53b4e735ad89b8c4cb8e254c89fedd2022535ec939963ed3ceefaeccc08661414
7
+ data.tar.gz: 8af8a70dda5cebe82db5534081ac9589081a2ec74e2b9f33b0076d120657c36717bcbb62c3a3251c024108a63a1f3d749eb5252594d960bae87d414da6471a6c
data/Gemfile CHANGED
@@ -5,6 +5,7 @@ source "https://rubygems.org"
5
5
  gemspec
6
6
 
7
7
  gem "logger"
8
+ gem "openssl"
8
9
  gem "rake"
9
10
  gem "redcarpet"
10
11
  gem "rspec"
data/README.md CHANGED
@@ -98,14 +98,19 @@ client.chat('Be poetic.', stream:)
98
98
 
99
99
  #### Format
100
100
 
101
- `format` takes an optional symbol (`:json`) and modifies requests to send
102
- additional system text requesting JSON:
101
+ `format` takes an optional symbol (`:json`, `:text`, or `OmniAI::Schema::Format`) and modifies the system message to include additional context for formatting:
103
102
 
104
103
  ```ruby
104
+ format = OmniAI::Schema.format(name: "Contact", schema: OmniAI::Schema.object(
105
+ properties: {
106
+ name: OmniAI::Schema.string,
107
+ },
108
+ required: %i[name]
109
+ ))
105
110
  completion = client.chat(format: :json) do |prompt|
106
- prompt.system(OmniAI::Chat::JSON_PROMPT)
107
111
  prompt.user('What is the name of the drummer for the Beatles?')
108
- JSON.parse(completion.text) # { "name": "Ringo" }
112
+ end
113
+ format.parse(completion.text) # { "name": "Ringo" }
109
114
  ```
110
115
 
111
116
  [Anthropic API Reference `control-output-format`](https://docs.anthropic.com/en/docs/control-output-format)
@@ -94,10 +94,11 @@ module OmniAI
94
94
 
95
95
  # @return [String, nil]
96
96
  def system
97
- messages = @prompt.messages.filter(&:system?)
98
- return if messages.empty?
97
+ parts = @prompt.messages.filter(&:system?).filter(&:text?).map(&:text)
98
+ parts << formatting if formatting?
99
+ return if parts.empty?
99
100
 
100
- messages.filter(&:text?).map(&:text).join("\n\n")
101
+ parts.join("\n\n")
101
102
  end
102
103
 
103
104
  # @return [String]
@@ -123,6 +124,20 @@ module OmniAI
123
124
 
124
125
  private
125
126
 
127
+ # @return [Boolean]
128
+ def formatting?
129
+ !@format.nil?
130
+ end
131
+
132
+ # @return [String, nil]
133
+ def formatting
134
+ case @format
135
+ when OmniAI::Schema::Format then @format.prompt
136
+ when :text then "You must respond with TEXT."
137
+ when :json then "You must respond with JSON."
138
+ end
139
+ end
140
+
126
141
  # @return [Array<Hash>, nil]
127
142
  def tools_payload
128
143
  @tools.map { |tool| tool.serialize(context:) } if @tools&.any?
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OmniAI
4
4
  module Anthropic
5
- VERSION = "2.6.3"
5
+ VERSION = "2.9.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai-anthropic
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.6.3
4
+ version: 2.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -29,14 +29,14 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.6'
32
+ version: '2.9'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '2.6'
39
+ version: '2.9'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: zeitwerk
42
42
  requirement: !ruby/object:Gem::Requirement