cloudflare-ai 0.4.1 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -3
- data/lib/cloudflare/ai/client.rb +6 -0
- data/lib/cloudflare/ai/results/translation.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: 9085ff95f730366db7b3261cc94935f782d719b8129dd1341796ee6d66fd373c
|
4
|
+
data.tar.gz: 60b29886c88200aebdd1c46e743a28dd597540144494e8288098e05c6ddb8e04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b95c01b2cab4dec4c0bdd476d99f5ab65183215a64e6c6711a50caed5874a51ff34b78b530b1877b13a1be8851fc527202a1b250f94d57a554ff46b25716136
|
7
|
+
data.tar.gz: 86721eb5cf51bfd886a6f9e1a4be71c4b33492cd90e2a2adedbe2f6474c7e601b4e2f1bc52bfd315039a3b24ea202fd627dc032a2dda63e8ad6f04b0e01da08a
|
data/README.md
CHANGED
@@ -21,9 +21,9 @@ It's still early days, and here are my immediate priorities:
|
|
21
21
|
* [ ] Support for more AI model categories
|
22
22
|
* [x] [Text Generation](https://developers.cloudflare.com/workers-ai/models/text-generation/)
|
23
23
|
* [x] [Text Embeddings](https://developers.cloudflare.com/workers-ai/models/text-embeddings/)
|
24
|
-
* [
|
24
|
+
* [x] [Text Classification](https://developers.cloudflare.com/workers-ai/models/text-classification/)
|
25
|
+
* [x] [Translation](https://developers.cloudflare.com/workers-ai/models/translation/)
|
25
26
|
* [ ] [Image Classification](https://developers.cloudflare.com/workers-ai/models/image-classification/)
|
26
|
-
* [ ] [Translation](https://developers.cloudflare.com/workers-ai/models/translation/)
|
27
27
|
* [ ] [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
|
|
@@ -99,6 +99,12 @@ result = client.complete(prompt: "Hi!") { |data| puts data}
|
|
99
99
|
# [DONE]
|
100
100
|
|
101
101
|
```
|
102
|
+
#### Token limits
|
103
|
+
Invocations of the `prompt` and `chat` can take an optional `max_tokens` argument that defaults to 256.
|
104
|
+
```ruby
|
105
|
+
result = client.complete(prompt: "What is your name?", max_tokens: 512)
|
106
|
+
```
|
107
|
+
|
102
108
|
#### Result object
|
103
109
|
All invocations of the `prompt` and `chat` methods return a `Cloudflare::AI::Results::TextGeneration` object. This object's serializable JSON output is
|
104
110
|
based on the raw response from the Cloudflare API.
|
@@ -119,7 +125,6 @@ puts result.failure? # => true
|
|
119
125
|
puts result.to_json # => {"result":null,"success":false,"errors":[{"code":7009,"message":"Upstream service unavailable"}],"messages":[]}
|
120
126
|
```
|
121
127
|
|
122
|
-
|
123
128
|
### Text embedding
|
124
129
|
```ruby
|
125
130
|
result = client.embed(text: "Hello")
|
@@ -144,6 +149,15 @@ p result.result # => [{"label"=>"NEGATIVE", "score"=>0.6647962927818298}, {"labe
|
|
144
149
|
#### Result object
|
145
150
|
All invocations of the `classify` methods return a `Cloudflare::AI::Results::TextClassification`.
|
146
151
|
|
152
|
+
### Translation
|
153
|
+
```ruby
|
154
|
+
result = client.translate(text: "Hello Jello", source_lang: "en", target_lang: "fr")
|
155
|
+
p result.translated_text # => Hola Jello
|
156
|
+
```
|
157
|
+
|
158
|
+
#### Result object
|
159
|
+
All invocations of the `translate` methods return a `Cloudflare::AI::Results::Translate`.
|
160
|
+
|
147
161
|
# Logging
|
148
162
|
|
149
163
|
This gem uses standard logging mechanisms and defaults to `:warn` level. Most messages are at info level, but we will add debug or warn statements as needed.
|
data/lib/cloudflare/ai/client.rb
CHANGED
@@ -39,6 +39,12 @@ class Cloudflare::AI::Client
|
|
39
39
|
Cloudflare::AI::Results::TextEmbedding.new(connection.post(url, payload).body)
|
40
40
|
end
|
41
41
|
|
42
|
+
def translate(text:, target_lang:, source_lang: "en", model_name: Cloudflare::AI::Models.translation.first)
|
43
|
+
url = service_url_for(account_id: account_id, model_name: model_name)
|
44
|
+
payload = {text: text, target_lang: target_lang, source_lang: source_lang}.to_json
|
45
|
+
Cloudflare::AI::Results::Translation.new(connection.post(url, payload).body)
|
46
|
+
end
|
47
|
+
|
42
48
|
private
|
43
49
|
|
44
50
|
def connection
|
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.5.1
|
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-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -101,6 +101,7 @@ files:
|
|
101
101
|
- lib/cloudflare/ai/results/text_classification.rb
|
102
102
|
- lib/cloudflare/ai/results/text_embedding.rb
|
103
103
|
- lib/cloudflare/ai/results/text_generation.rb
|
104
|
+
- lib/cloudflare/ai/results/translation.rb
|
104
105
|
- lib/cloudflare/ai/version.rb
|
105
106
|
homepage: https://rubygems.org/gems/cloudflare-ai
|
106
107
|
licenses:
|