omniai 1.6.3 → 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: fe2124a214845732f67f1944d0d9538927a7fe034948f67485fb923d232ce3e7
4
- data.tar.gz: 41849074c457cde063e0a14866c43370046b9a33c3e9354655ea5167201f5781
3
+ metadata.gz: 5d9011a55d57b9dd0923f4d7edd70001c3f9ee5b8211e98d59f9d001687af044
4
+ data.tar.gz: 204e2f0ec0a44f65cba11cb49819e7f5c4e933a92d6bc1b48c4d630dee180ecd
5
5
  SHA512:
6
- metadata.gz: c11a71d77fd58667c3fb618284e0b5706c0e12d28ae6f09119123cc3d90f5410338a1fda3448c6b213d38af140d46a4baa3e509d55eaed6c6d338a6680715662
7
- data.tar.gz: 56b16d80a3ec823d2d4a43e93553d904849a65e24e8aefebbf69b0cce5a2d8ba0427e7a039c4373c4e59875994f290559a013bef1ae634f6c706d8b5af26a0dd
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,13 +58,18 @@ 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]
59
69
  #
60
70
  # @return [HTTP::Response]
61
71
  def request!
62
- response = HTTP.get(@uri)
72
+ response = HTTP.follow.get(@uri)
63
73
  raise FetchError, response.flush unless response.status.success?
64
74
 
65
75
  response
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.6.3'
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.3
4
+ version: 1.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Sylvestre