omniai 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/omniai/chat/content/file.rb +27 -0
- data/lib/omniai/chat/content/media.rb +56 -0
- data/lib/omniai/chat/content/text.rb +17 -0
- data/lib/omniai/chat/content/url.rb +41 -0
- data/lib/omniai/version.rb +1 -1
- data/lib/omniai.rb +2 -0
- metadata +5 -2
- data/lib/omniai/chat/content.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b37e667b2b004a012bf7d7d76fd80c08aa8948d46b8670651daa3a426c591d2
|
4
|
+
data.tar.gz: ded01ccbbf34486159fd965953a9d5cec9a62da16404960e5b0c8bca8d5384ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6c26067f0b0b3c7ecefbdc00ed1746f0f597f729a41ff1e0a253bb723cf89ef1b82ccc2c411a8b43b93d5f54c83a9f3e58ab7074be324e9b3bf24e099e7ca2a
|
7
|
+
data.tar.gz: fe75154f85d6a68b1698c923548570695c724293462225bdb9d29db8ccf884ab2965bce3090a9f9c64851c5547ab4a655e59e7079c0923bff9ee18f46320517c
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
class Chat
|
5
|
+
module Content
|
6
|
+
# A file that is either audio / image / video.
|
7
|
+
class File < Media
|
8
|
+
attr_accessor :io
|
9
|
+
|
10
|
+
# @param io [IO, Pathname, String]
|
11
|
+
# @param type [Symbol, String] :image, :video, :audio, "audio/flac", "image/jpeg", "video/mpeg", etc.
|
12
|
+
def initialize(io, type)
|
13
|
+
super(type)
|
14
|
+
@io = io
|
15
|
+
end
|
16
|
+
|
17
|
+
# @return [String]
|
18
|
+
def fetch!
|
19
|
+
case @io
|
20
|
+
when IO then @io.read
|
21
|
+
else ::File.binread(@io)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
class Chat
|
5
|
+
module Content
|
6
|
+
# An abstract class that represents audio / image / video and is used for both files and urls.
|
7
|
+
class Media
|
8
|
+
attr_accessor :type
|
9
|
+
|
10
|
+
# @param type [String] "audio/flac", "image/jpeg", "video/mpeg", etc.
|
11
|
+
def initialize(type)
|
12
|
+
@type = type
|
13
|
+
end
|
14
|
+
|
15
|
+
# @return [Boolean]
|
16
|
+
def text?
|
17
|
+
@type.match?(%r{^text/})
|
18
|
+
end
|
19
|
+
|
20
|
+
# @return [Boolean]
|
21
|
+
def audio?
|
22
|
+
@type.match?(%r{^audio/})
|
23
|
+
end
|
24
|
+
|
25
|
+
# @return [Boolean]
|
26
|
+
def image?
|
27
|
+
@type.match?(%r{^image/})
|
28
|
+
end
|
29
|
+
|
30
|
+
# @return [Boolean]
|
31
|
+
def video?
|
32
|
+
@type.match?(%r{^video/})
|
33
|
+
end
|
34
|
+
|
35
|
+
# @yield [io]
|
36
|
+
def fetch!(&)
|
37
|
+
raise NotImplementedError, "#{self.class}#fetch! undefined"
|
38
|
+
end
|
39
|
+
|
40
|
+
# e.g. "Hello" -> "SGVsbG8h"
|
41
|
+
#
|
42
|
+
# @return [String]
|
43
|
+
def data
|
44
|
+
Base64.strict_encode64(fetch!)
|
45
|
+
end
|
46
|
+
|
47
|
+
# e.g. "data:text/html;base64,..."
|
48
|
+
#
|
49
|
+
# @return [String]
|
50
|
+
def data_uri
|
51
|
+
"data:#{@type};base64,#{data}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
class Chat
|
5
|
+
module Content
|
6
|
+
# A url that is either audio / image / video.
|
7
|
+
class URL < Media
|
8
|
+
attr_accessor :url, :type
|
9
|
+
|
10
|
+
class HTTPError < OmniAI::HTTPError; end
|
11
|
+
|
12
|
+
# @param url [URI, String]
|
13
|
+
# @param type [Symbol, String] "audio/flac", "image/jpeg", "video/mpeg", etc.
|
14
|
+
def initialize(url, type)
|
15
|
+
super(type)
|
16
|
+
@url = url
|
17
|
+
end
|
18
|
+
|
19
|
+
# @raise [HTTPError]
|
20
|
+
#
|
21
|
+
# @return [String]
|
22
|
+
def fetch!
|
23
|
+
response = request!
|
24
|
+
String(response.body)
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
# @raise [HTTPError]
|
30
|
+
#
|
31
|
+
# @return [HTTP::Response]
|
32
|
+
def request!
|
33
|
+
response = HTTP.get(@url)
|
34
|
+
raise HTTPError, response.flush unless response.status.success?
|
35
|
+
|
36
|
+
response
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/omniai/version.rb
CHANGED
data/lib/omniai.rb
CHANGED
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.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -69,7 +69,10 @@ files:
|
|
69
69
|
- lib/omniai/chat/choice.rb
|
70
70
|
- lib/omniai/chat/chunk.rb
|
71
71
|
- lib/omniai/chat/completion.rb
|
72
|
-
- lib/omniai/chat/content.rb
|
72
|
+
- lib/omniai/chat/content/file.rb
|
73
|
+
- lib/omniai/chat/content/media.rb
|
74
|
+
- lib/omniai/chat/content/text.rb
|
75
|
+
- lib/omniai/chat/content/url.rb
|
73
76
|
- lib/omniai/chat/delta.rb
|
74
77
|
- lib/omniai/chat/message.rb
|
75
78
|
- lib/omniai/chat/stream.rb
|
data/lib/omniai/chat/content.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OmniAI
|
4
|
-
class Chat
|
5
|
-
# A file used for analysis.
|
6
|
-
class Content
|
7
|
-
attr_accessor :type, :value
|
8
|
-
|
9
|
-
# @param value [String]
|
10
|
-
# @param type [Symbol] :image / :video / :audio / :text
|
11
|
-
def initialize(value, type: :text)
|
12
|
-
@value = value
|
13
|
-
@type = type
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|