omniai 1.6.4 → 1.6.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/omniai/chat/content.rb +8 -0
- data/lib/omniai/chat/file.rb +16 -3
- data/lib/omniai/chat/media.rb +5 -0
- data/lib/omniai/chat/message.rb +8 -0
- data/lib/omniai/chat/prompt.rb +5 -0
- data/lib/omniai/chat/text.rb +5 -0
- data/lib/omniai/chat/url.rb +21 -6
- data/lib/omniai/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bc92ec17e5ca87590eca2181453b6a3e54c2d15bb6dda0c80c604a443e59660
|
4
|
+
data.tar.gz: e4eb4ad22437711fbac2c538edc644861107985662f24a236b317d229802f7b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75b7b695353ec0899b786ee057beaedcd8ab21ba15efca6f3a21c4e22730dc73b7676fbdfece11f624a1dce77638ad2d7cc4a6ff054c2180edb8f423b20ca6ee
|
7
|
+
data.tar.gz: 9c7ab97db7e4d8085774c9fd76803b8abfe53905b6d9b6d141caed311d019347d3f0e880e957597b529de8e479d1b69415213e82ca1daba34bf00d7049eddbae
|
data/lib/omniai/chat/content.rb
CHANGED
@@ -4,6 +4,14 @@ module OmniAI
|
|
4
4
|
class Chat
|
5
5
|
# A placeholder for parts of a message. Any subclass must implement the serializable interface.
|
6
6
|
class Content
|
7
|
+
# @return [String]
|
8
|
+
def self.summarize(content)
|
9
|
+
return content.map { |entry| summarize(entry) }.join("\n\n") if content.is_a?(Array)
|
10
|
+
return content if content.is_a?(String)
|
11
|
+
|
12
|
+
content.summarize
|
13
|
+
end
|
14
|
+
|
7
15
|
# @param context [Context] optional
|
8
16
|
#
|
9
17
|
# @return [String]
|
data/lib/omniai/chat/file.rb
CHANGED
@@ -29,10 +29,23 @@ module OmniAI
|
|
29
29
|
# @param context [Context]
|
30
30
|
# @return [Hash]
|
31
31
|
def serialize(context: nil)
|
32
|
-
|
33
|
-
|
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
|
-
|
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
|
data/lib/omniai/chat/media.rb
CHANGED
data/lib/omniai/chat/message.rb
CHANGED
@@ -31,6 +31,14 @@ module OmniAI
|
|
31
31
|
"#<#{self.class} role=#{@role.inspect} content=#{@content.inspect}>"
|
32
32
|
end
|
33
33
|
|
34
|
+
# @return [String]
|
35
|
+
def summarize
|
36
|
+
<<~TEXT
|
37
|
+
#{@role}
|
38
|
+
#{Content.summarize(@content)}
|
39
|
+
TEXT
|
40
|
+
end
|
41
|
+
|
34
42
|
# Usage:
|
35
43
|
#
|
36
44
|
# Message.deserialize({ role: :user, content: 'Hello!' }) # => #<Message ...>
|
data/lib/omniai/chat/prompt.rb
CHANGED
@@ -62,6 +62,11 @@ module OmniAI
|
|
62
62
|
"#<#{self.class.name} messages=#{@messages.inspect}>"
|
63
63
|
end
|
64
64
|
|
65
|
+
# @return [String]
|
66
|
+
def summarize
|
67
|
+
@messages.map(&:summarize).join("\n\n")
|
68
|
+
end
|
69
|
+
|
65
70
|
# Usage:
|
66
71
|
#
|
67
72
|
# prompt.serialize # => [{ content: "What is the capital of Canada?", role: :user }]
|
data/lib/omniai/chat/text.rb
CHANGED
data/lib/omniai/chat/url.rb
CHANGED
@@ -16,6 +16,11 @@ module OmniAI
|
|
16
16
|
@uri = uri
|
17
17
|
end
|
18
18
|
|
19
|
+
# @return [String]
|
20
|
+
def summarize
|
21
|
+
"[#{filename}]"
|
22
|
+
end
|
23
|
+
|
19
24
|
# @return [String]
|
20
25
|
def inspect
|
21
26
|
"#<#{self.class} uri=#{@uri.inspect}>"
|
@@ -36,13 +41,18 @@ module OmniAI
|
|
36
41
|
#
|
37
42
|
# @return [Hash]
|
38
43
|
def serialize(context: nil)
|
39
|
-
|
40
|
-
|
44
|
+
if text?
|
45
|
+
content = fetch!
|
46
|
+
Text.new("<file>#{filename}: #{content}</file>").serialize(context:)
|
47
|
+
else
|
48
|
+
serializer = context&.serializers&.[](:url)
|
49
|
+
return serializer.call(self, context:) if serializer
|
41
50
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
51
|
+
{
|
52
|
+
type: "#{kind}_url",
|
53
|
+
"#{kind}_url": { url: @uri },
|
54
|
+
}
|
55
|
+
end
|
46
56
|
end
|
47
57
|
|
48
58
|
# @raise [FetchError]
|
@@ -53,6 +63,11 @@ module OmniAI
|
|
53
63
|
String(response.body)
|
54
64
|
end
|
55
65
|
|
66
|
+
# @return [String]
|
67
|
+
def filename
|
68
|
+
::File.basename(@uri)
|
69
|
+
end
|
70
|
+
|
56
71
|
protected
|
57
72
|
|
58
73
|
# @raise [FetchError]
|
data/lib/omniai/version.rb
CHANGED