cloudflare-ai 0.3.0 → 0.4.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: b0a6b80e669a5c4d64ec87433ed1c3426ee0a2a1087016773c5648c799b34912
4
- data.tar.gz: fe1d3b2afb5f70cbe476b1b8e006819b2e6e469184169993a15c7c4c34b89ca8
3
+ metadata.gz: f8c78786e06d2a3cc05b177aedc99672b4be56016c33d6be2e718533b6b3f507
4
+ data.tar.gz: 535f23f9e6ffedbe0e090ded97459e021e57b84025456dab77d3d85dd2da194d
5
5
  SHA512:
6
- metadata.gz: 84dcec88bcd44e4a7b004235b15b559d924c1e8dfce552234b2d9286762ab2a12d282954e8d863523b1c9170c24f49a772da7320b5b475b66b79b141ac2c532d
7
- data.tar.gz: 0f676b2accb65edc63b2b9b1c2b8a532ebfedba588dfdcb1ae38ccfdf7edb4869c1ebee2060e887e5ac166772cda91d3e43e2ca650e878eb63b8c964d7fc19e1
6
+ metadata.gz: 6d35d01ae35a9407b97acfc0643c66c33b26d608d90373daf3c00001f86d7d2d2893162b370c417e2db7a96b43cec74d66e2652caa11ed89bbf31b968b4fd34d
7
+ data.tar.gz: 5af4ef84fdfc0ed649f951f18c10105b97ee4ae55b5d951f90551f7b0e5e452ca98ce408ded86980e67da05bfaf4e42321097b0b3f1cb2cfd224d67da74f8d44
data/README.md CHANGED
@@ -61,6 +61,19 @@ Thiis gem provides a client that wraps around [Cloudflare's REST API](https://de
61
61
  client = Cloudflare::AI::Client.new(account_id: ENV["CLOUDFLARE_ACCOUNT_ID"], api_token: ENV["CLOUDFLARE_API_TOKEN"])
62
62
  ```
63
63
 
64
+ ### Model selection
65
+ The model name is an optional parameter to every one of the client methods described below.
66
+ For example, if an example is documented as
67
+ ```ruby
68
+ result = client.complete(prompt: "Hello my name is")
69
+ ```
70
+ this is implicitly the same as
71
+ ```ruby
72
+ result = client.complete(prompt: "Hello my name is", model: "@cf/meta/llama-2-7b-chat-fp16")
73
+ ```
74
+ The full list of supported models is available here: [models.rb](lib/cloudflare/ai/models.rb).
75
+ More information is available [in the cloudflare documentation](https://developers.cloudflare.com/workers-ai/models/).
76
+ The default model used is the first enumerated model in the applicable set in [models.rb](lib/cloudflare/ai/models.rb).
64
77
 
65
78
  ### Text generation (chat / scoped prompt)
66
79
  ```ruby
@@ -120,7 +133,16 @@ result = client.embed(text: ["Hello", "World"])
120
133
  ```
121
134
 
122
135
  #### Result object
123
- All invocations of the `embedding` methods return a `Cloudflare::AI::Results::TextEmbedding`.
136
+ All invocations of the `embed` methods return a `Cloudflare::AI::Results::TextEmbedding`.
137
+
138
+ ### Text classification
139
+ ```ruby
140
+ result = client.classify(text: "You meanie!")
141
+ p result.result # => [{"label"=>"NEGATIVE", "score"=>0.6647962927818298}, {"label"=>"POSITIVE", "score"=>0.3352036774158478}]
142
+ ```
143
+
144
+ #### Result object
145
+ All invocations of the `classify` methods return a `Cloudflare::AI::Results::TextClassification`.
124
146
 
125
147
  # Logging
126
148
 
@@ -18,6 +18,13 @@ class Cloudflare::AI::Client
18
18
  post_streamable_request(url, payload, &block)
19
19
  end
20
20
 
21
+ def classify(text:, model_name: Cloudflare::AI::Models.text_classification.first)
22
+ url = service_url_for(account_id: account_id, model_name: model_name)
23
+ payload = {text: text}.to_json
24
+
25
+ Cloudflare::AI::Results::TextClassification.new(connection.post(url, payload).body)
26
+ end
27
+
21
28
  def complete(prompt:, model_name: default_text_generation_model_name, &block)
22
29
  url = service_url_for(account_id: account_id, model_name: model_name)
23
30
  stream = block ? true : false
@@ -0,0 +1,3 @@
1
+ class Cloudflare::AI::Results::TextClassification < Cloudflare::AI::Result
2
+ # Empty seam kept for consistency with other result objects that have more complexity.
3
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Cloudflare
4
4
  module AI
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.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.3.0
4
+ version: 0.4.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-21 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -98,6 +98,7 @@ files:
98
98
  - lib/cloudflare/ai/message.rb
99
99
  - lib/cloudflare/ai/models.rb
100
100
  - lib/cloudflare/ai/result.rb
101
+ - lib/cloudflare/ai/results/text_classification.rb
101
102
  - lib/cloudflare/ai/results/text_embedding.rb
102
103
  - lib/cloudflare/ai/results/text_generation.rb
103
104
  - lib/cloudflare/ai/version.rb