cloudflare-ai 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f1d5e2776ba81382b1cb02355ac23348bee4a661d141c7c144136f1b9547eed
4
- data.tar.gz: b651a6faed4d18a9b00cfed3f2217bc3cdc47ff9a2f9371cf50ab9c1f6bfab6f
3
+ metadata.gz: 2f16a1fd5c112fb69440d4d89b1f27d167e854c537ca952b91e1f3f673c0efb5
4
+ data.tar.gz: 59f999e994f5bd21071ee2f125b5e138ba353feb857912b1df472f35acc05006
5
5
  SHA512:
6
- metadata.gz: 2fe5ec654b60e662113f79d2e66adf0483c17c0b2ffd2ea483c8f3b45c0d2ae747605b831e5cf6eed9ea8cd7ae614e6992199cf3fcad41870cb8ca8e269cb048
7
- data.tar.gz: 3f4eac6cea6d8cdd00a00f71c3eca95ccfb61b2de8b2f45a4dfa46a7d81b45978eb5c92883569c8fd4398874005d0bad456096baa01cb7c82e22587b9700dc2a
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
- * [ ] [Text-to-Image](https://developers.cloudflare.com/workers-ai/models/text-to-image/)
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` methods return a `Cloudflare::AI::Results::TextClassification`.
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
@@ -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
@@ -30,7 +30,7 @@ class Cloudflare::AI::Result
30
30
  result_data.to_json
31
31
  end
32
32
 
33
- private
33
+ protected
34
34
 
35
35
  attr_reader :result_data
36
36
 
@@ -0,0 +1,5 @@
1
+ class Cloudflare::AI::Results::TextToImage < Cloudflare::AI::Result
2
+ def initialize(file)
3
+ @result_data = {result: file, success: true, errors: [], messages: []}
4
+ end
5
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cloudflare
4
4
  module AI
5
- VERSION = "0.6.0"
5
+ VERSION = "0.7.0"
6
6
  end
7
7
  end
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.6.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-24 00:00:00.000000000 Z
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