omniai 1.6.4 → 1.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c40ccbf59a89846731fb7e3b1a47c4d2ecc944ea2cb45e56b4911bdc301c13
4
- data.tar.gz: fdcd923f1ccb0db66630e48d0230c406ac1d72eb8602bee2872e4d02d10ce081
3
+ metadata.gz: 5d9011a55d57b9dd0923f4d7edd70001c3f9ee5b8211e98d59f9d001687af044
4
+ data.tar.gz: 204e2f0ec0a44f65cba11cb49819e7f5c4e933a92d6bc1b48c4d630dee180ecd
5
5
  SHA512:
6
- metadata.gz: d1cdb9d2b81d286a593c0f2becff6249c4e33e8143b4d158f3d48204dc4ca0fc6e627804722a52db69121bd5b223ae7d407eeac912d4830d7093eddfae089304
7
- data.tar.gz: 1b0f10832178feb1304da5d12abe1bd9613df52ffa8eb2edf1678668cdb3425487e90323774ca8e092b95002f83001eb4b560bc0c8536bc133222842b67986ff
6
+ metadata.gz: 724827923255adade8f19bd9b43806d1af116d9c4dd6105713f0ba0b16c3d6cd5e5cbafdc2d324912a669523e565ba1ce190ed26035cdc1645a4505f2c6991a9
7
+ data.tar.gz: 5944ef3f285359662fc6105fd2a3aba7a44a279c5062ec0c1bdf194ddecd6842a33b1cd9b20cd4f5b36641b67cd8bc046e677260170d06dd2d5e3b37db37f356
@@ -29,10 +29,23 @@ module OmniAI
29
29
  # @param context [Context]
30
30
  # @return [Hash]
31
31
  def serialize(context: nil)
32
- serializer = context&.serializers&.[](:file)
33
- return serializer.call(self, context:) if serializer
32
+ if text?
33
+ content = fetch!
34
+ Text.new("<file>#{filename}: #{content}</file>").serialize(context:)
35
+ else
36
+ serializer = context&.serializers&.[](:file)
37
+ return serializer.call(self, context:) if serializer
34
38
 
35
- { type: "#{kind}_url", "#{kind}_url": { url: data_uri } }
39
+ { type: "#{kind}_url", "#{kind}_url": { url: data_uri } }
40
+ end
41
+ end
42
+
43
+ # @return [String]
44
+ def filename
45
+ case @io
46
+ when Tempfile, File, String then ::File.basename(@io)
47
+ else 'DATA'
48
+ end
36
49
  end
37
50
  end
38
51
  end
@@ -36,13 +36,18 @@ module OmniAI
36
36
  #
37
37
  # @return [Hash]
38
38
  def serialize(context: nil)
39
- serializer = context&.serializers&.[](:url)
40
- return serializer.call(self, context:) if serializer
39
+ if text?
40
+ content = fetch!
41
+ Text.new("<file>#{filename}: #{content}</file>").serialize(context:)
42
+ else
43
+ serializer = context&.serializers&.[](:url)
44
+ return serializer.call(self, context:) if serializer
41
45
 
42
- {
43
- type: "#{kind}_url",
44
- "#{kind}_url": { url: @uri },
45
- }
46
+ {
47
+ type: "#{kind}_url",
48
+ "#{kind}_url": { url: @uri },
49
+ }
50
+ end
46
51
  end
47
52
 
48
53
  # @raise [FetchError]
@@ -53,6 +58,11 @@ module OmniAI
53
58
  String(response.body)
54
59
  end
55
60
 
61
+ # @return [String]
62
+ def filename
63
+ ::File.basename(@uri)
64
+ end
65
+
56
66
  protected
57
67
 
58
68
  # @raise [FetchError]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.6.4'
4
+ VERSION = '1.6.5'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: omniai
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.4
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre