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 +4 -4
- data/Gemfile +1 -0
- data/README.md +9 -4
- data/lib/omniai/anthropic/chat.rb +18 -3
- data/lib/omniai/anthropic/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b7d29daa6ac2d97df35d173aa8942a89cc6aadb19086b29704c18aabaaafaa99
|
|
4
|
+
data.tar.gz: 46947aa8180b213f2a93e5ac65adbc7987d4b6c1c13959fed38a06762ef94314
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c43605fdfa8ebf6ff5302fc296f428cbded2c0f81048621d9d4904e91a47ccd53b4e735ad89b8c4cb8e254c89fedd2022535ec939963ed3ceefaeccc08661414
|
|
7
|
+
data.tar.gz: 8af8a70dda5cebe82db5534081ac9589081a2ec74e2b9f33b0076d120657c36717bcbb62c3a3251c024108a63a1f3d749eb5252594d960bae87d414da6471a6c
|
data/Gemfile
CHANGED
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
|
|
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
|
-
|
|
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
|
-
|
|
98
|
-
|
|
97
|
+
parts = @prompt.messages.filter(&:system?).filter(&:text?).map(&:text)
|
|
98
|
+
parts << formatting if formatting?
|
|
99
|
+
return if parts.empty?
|
|
99
100
|
|
|
100
|
-
|
|
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?
|
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.
|
|
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.
|
|
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.
|
|
39
|
+
version: '2.9'
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: zeitwerk
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|