cloudflare-ai 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -1
- data/lib/cloudflare/ai/client.rb +7 -0
- data/lib/cloudflare/ai/results/text_classification.rb +3 -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: f8c78786e06d2a3cc05b177aedc99672b4be56016c33d6be2e718533b6b3f507
|
4
|
+
data.tar.gz: 535f23f9e6ffedbe0e090ded97459e021e57b84025456dab77d3d85dd2da194d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 `
|
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
|
|
data/lib/cloudflare/ai/client.rb
CHANGED
@@ -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
|
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.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-
|
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
|