omniai-anthropic 2.6.3 → 3.0.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: ffba2da1819ae49dcfd27639fef64cf03cec544b90f4811404fdba968f3c9e98
4
+ data.tar.gz: 32b3601f2667c7bf5db78dbd6a41f4a8a0323ce89471cc8ceb723e6fd790e97c
5
5
  SHA512:
6
- metadata.gz: 0e501003829f8f263daf8736feedde7697f21c3eb93b046f61255643e6a77bc96006532b232e2f7707041d962d3e2ac87125fd618680ec3ba6908dc86d521326
7
- data.tar.gz: 3bfba26cfdf4e8cc90ce1d9446aac5e61f9d9e23b7ede7bd3ea1d47c898ead9772c2f5ade6a9eaf21b469c5ab94f464f37e13b6ddc178281513f8cd29c74ff41
6
+ metadata.gz: a6f4cc99dab8822bbe406daba84cfe4d7c20fb48f3bed03827135713f9b5716b874eb25f8858b1cd24db87902817215af4dc7c9fa4ee2d7b7c2d71b98c5085f1
7
+ data.tar.gz: bdce932ee37b6527e59c219c05da9193b9b544ba9ddfa6f061b0e4c23436a4be672605937b2d53964969d2f383c8a1f65425e25c0f1cdad063fc978286783643
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 = "3.0.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: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre
@@ -29,14 +29,28 @@ dependencies:
29
29
  requirements:
30
30
  - - "~>"
31
31
  - !ruby/object:Gem::Version
32
- version: '2.6'
32
+ version: '3.0'
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: '3.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: openssl
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
40
54
  - !ruby/object:Gem::Dependency
41
55
  name: zeitwerk
42
56
  requirement: !ruby/object:Gem::Requirement