cloudflare-ai 0.6.0 → 0.7.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/README.md +11 -2
- data/lib/cloudflare/ai/client.rb +11 -0
- data/lib/cloudflare/ai/result.rb +1 -1
- data/lib/cloudflare/ai/results/text_to_image.rb +5 -0
- data/lib/cloudflare/ai/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2f16a1fd5c112fb69440d4d89b1f27d167e854c537ca952b91e1f3f673c0efb5
|
4
|
+
data.tar.gz: 59f999e994f5bd21071ee2f125b5e138ba353feb857912b1df472f35acc05006
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d258b49887ca664f616aad4dbc74afc4bb8d49d0452933c2ee907306af56cf81da0bf084c260ddbe4db9d96f522812cc5abfb771c3d94757f12342334b16fd6
|
7
|
+
data.tar.gz: 133fcfd21cedbdb324604ec0e9bd4aacb0750b9f486df7bc217998e4dd117f4e6d482572ba1feee8b629e3362857cb8b8f28d2f1e3c6f1d89acddd18b73752e9
|
data/README.md
CHANGED
@@ -24,7 +24,7 @@ It's still early days, and here are my immediate priorities:
|
|
24
24
|
* [x] [Text Classification](https://developers.cloudflare.com/workers-ai/models/text-classification/)
|
25
25
|
* [x] [Translation](https://developers.cloudflare.com/workers-ai/models/translation/)
|
26
26
|
* [x] [Image Classification](https://developers.cloudflare.com/workers-ai/models/image-classification/)
|
27
|
-
* [
|
27
|
+
* [x] [Text-to-Image](https://developers.cloudflare.com/workers-ai/models/text-to-image/)
|
28
28
|
* [ ] [Automatic Speech Recognition](https://developers.cloudflare.com/workers-ai/models/speech-recognition/)
|
29
29
|
|
30
30
|
# Table of Contents
|
@@ -164,7 +164,16 @@ p result.result # => {"result":[{"label":"TABBY","score":0.6159140467643738},{"l
|
|
164
164
|
```
|
165
165
|
|
166
166
|
#### Result object
|
167
|
-
All invocations of the `classify`
|
167
|
+
All invocations of the `classify` method returns a `Cloudflare::AI::Results::TextClassification`.
|
168
|
+
|
169
|
+
### Text to Image
|
170
|
+
```ruby
|
171
|
+
result = client.draw(prompt: "robot with blue eyes")
|
172
|
+
p result.result # => File:0x0000000110deed68 (png tempfile)
|
173
|
+
```
|
174
|
+
|
175
|
+
#### Result object
|
176
|
+
All invocations of the `draw` method returns a `Cloudflare::AI::Results::TextToImage`.
|
168
177
|
|
169
178
|
### Translation
|
170
179
|
```ruby
|
data/lib/cloudflare/ai/client.rb
CHANGED
@@ -41,6 +41,17 @@ class Cloudflare::AI::Client
|
|
41
41
|
post_streamable_request(url, payload, &block)
|
42
42
|
end
|
43
43
|
|
44
|
+
def draw(prompt:, num_steps: 20, model_name: Cloudflare::AI::Models.text_to_image.first)
|
45
|
+
url = service_url_for(account_id: account_id, model_name: model_name)
|
46
|
+
payload = {prompt: prompt, num_steps: num_steps}.to_json
|
47
|
+
|
48
|
+
result = connection.post(url, payload).body
|
49
|
+
binary_data = result.split(",").map(&:to_i).pack("C*")
|
50
|
+
Cloudflare::AI::Results::TextToImage.new(
|
51
|
+
Tempfile.new(["cloudflare-ai", ".png"], binmode: true).tap { |result| result.write(binary_data) }
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
44
55
|
def embed(text:, model_name: Cloudflare::AI::Models.text_embedding.first)
|
45
56
|
url = service_url_for(account_id: account_id, model_name: model_name)
|
46
57
|
payload = {text: text}.to_json
|
data/lib/cloudflare/ai/result.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudflare-ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ajay Krishnan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-01-
|
11
|
+
date: 2024-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -117,6 +117,7 @@ files:
|
|
117
117
|
- lib/cloudflare/ai/results/text_classification.rb
|
118
118
|
- lib/cloudflare/ai/results/text_embedding.rb
|
119
119
|
- lib/cloudflare/ai/results/text_generation.rb
|
120
|
+
- lib/cloudflare/ai/results/text_to_image.rb
|
120
121
|
- lib/cloudflare/ai/results/translation.rb
|
121
122
|
- lib/cloudflare/ai/version.rb
|
122
123
|
homepage: https://rubygems.org/gems/cloudflare-ai
|