diff --git a/Gemfile.lock b/Gemfile.lock index f4bc1ee..05b0df7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - cloudflare-ai (0.9.1) + cloudflare-ai (0.9.2) activemodel (~> 7.0) activesupport (~> 7.0) event_stream_parser (~> 1.0) diff --git a/README.md b/README.md index 2ede387..5db161a 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,36 @@ result = client.transcribe(audio: File.open("/path/to/audio.wav")) #### Result object All invocations of the `transcribe` method returns a `Cloudflare::AI::Results::Transcribe`. +### Summarization +```ruby +result = client.summarize(text: "This text should be a lot longer.") +p result.summary # => {"result":{"summary":"Short text"},"success":true,"errors":[],"messages":[]} +``` +#### Result object +All invocations of the `summarize` method returns a `Cloudflare::AI::Results::Summarization` object. + +### Object detection +The object detection endpoint accepts either a path to a file or a file stream. + +```ruby +result = client.detect_objects(image: "/path/to/cat.jpg") +result = client.classify(image: File.open("/path/to/cat.jpg")) +``` + +#### Result object +All invocations of the `detect_objects` method returns a `Cloudflare::AI::Results::ObjectDetection` object. + +### Image-to-text +The captioning endpoint accepts either a path to a file or a file stream. + +```ruby +client.caption(image: "/path/to/cat.jpg").description # => "a cat sitting on a couch" +client.caption(image: File.open("/path/to/cat.jpg")).description # => "a cat sitting on a couch" +``` + +#### Result object +All invocations of the `caption` method returns a `Cloudflare::AI::Results::ImageToText` object. + # Logging 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. diff --git a/lib/cloudflare/ai/models.rb b/lib/cloudflare/ai/models.rb index 9a1640f..c003788 100644 --- a/lib/cloudflare/ai/models.rb +++ b/lib/cloudflare/ai/models.rb @@ -28,7 +28,7 @@ def image_to_text end def object_detection - %w[@cf/meta/det-resnet-50] + %w[@cf/meta/detr-resnet-50] end def summarization diff --git a/lib/cloudflare/ai/results/image_to_text.rb b/lib/cloudflare/ai/results/image_to_text.rb index 2e955f2..91a6ad5 100644 --- a/lib/cloudflare/ai/results/image_to_text.rb +++ b/lib/cloudflare/ai/results/image_to_text.rb @@ -1,3 +1,5 @@ class Cloudflare::AI::Results::ImageToText < Cloudflare::AI::Result - # Empty seam kept for consistency with other result objects that have more complexity. + def description + result&.dig(:description) # nil if no shape + end end diff --git a/lib/cloudflare/ai/version.rb b/lib/cloudflare/ai/version.rb index 91e38f3..7afef2c 100644 --- a/lib/cloudflare/ai/version.rb +++ b/lib/cloudflare/ai/version.rb @@ -2,6 +2,6 @@ module Cloudflare module AI - VERSION = "0.9.1" + VERSION = "0.9.2" end end diff --git a/test/cloudflare/ai/results/image_to_text_test.rb b/test/cloudflare/ai/results/image_to_text_test.rb new file mode 100644 index 0000000..4793fdf --- /dev/null +++ b/test/cloudflare/ai/results/image_to_text_test.rb @@ -0,0 +1,29 @@ +require "test_helper" + +class Cloudflare::AI::Results::ImageToTextTest < Minitest::Test + def setup + @result = Cloudflare::AI::Results::ImageToText.new(successful_response_json) + end + + def test_successful_result + assert @result.success? + refute @result.failure? + + assert_equal successful_response_json["result"]["description"], @result.description + end + + def test_to_json + assert_equal successful_response_json.to_json, @result.to_json + end + + private + + def successful_response_json + { + result: {description: "a cute cat"}, + success: true, + errors: [], + messages: [] + }.deep_stringify_keys + end +end