Skip to content

Commit

Permalink
Merge pull request #12 from ajaynomics/ajaynomics/feb-2024-model-updates
Browse files Browse the repository at this point in the history
fixes from implementation of feb-2024
  • Loading branch information
ajaynomics authored Feb 29, 2024
2 parents 4457960 + f9f5129 commit e55a542
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/cloudflare/ai/models.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/cloudflare/ai/results/image_to_text.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lib/cloudflare/ai/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Cloudflare
module AI
VERSION = "0.9.1"
VERSION = "0.9.2"
end
end
29 changes: 29 additions & 0 deletions test/cloudflare/ai/results/image_to_text_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit e55a542

Please sign in to comment.