omniai 1.0.2 → 1.0.4
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/choice.rb +3 -1
- data/lib/omniai/chat/completion.rb +11 -1
- data/lib/omniai/chat/message.rb +15 -10
- data/lib/omniai/chat/usage.rb +16 -22
- data/lib/omniai/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d821530b3b40043754c26a175c2b5d9c70fe3f04bd62bf61c5506963e56dae3
|
4
|
+
data.tar.gz: 6f0cf3e3292b11492bd25526391ec3a396d5a9262050dcf4d5aba35726c2ed04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f2d2fa897c94b741435df368ca0952fe00e4dafd0f199756008749a1267ac2d4ea325338b1da359c7c84944b76ec3a875d678039b9bd88ee819cacb470a6fdd
|
7
|
+
data.tar.gz: 698f4ec0159ac6a359f5bd93c02db3e4acd0cde6cfd42c17a30c341d6ad674720aa442040c0890cd3c600068c52717b011b28601335721fbdd7a55c1d74ae61d
|
data/lib/omniai/chat/choice.rb
CHANGED
@@ -33,7 +33,17 @@ module OmniAI
|
|
33
33
|
|
34
34
|
# @return [OmniAI::Chat::Usage]
|
35
35
|
def usage
|
36
|
-
|
36
|
+
return unless @data['usage']
|
37
|
+
|
38
|
+
input_tokens = @data['usage']['input_tokens'] || @data['usage']['prompt_tokens']
|
39
|
+
output_tokens = @data['usage']['output_tokens'] || @data['usage']['completion_tokens']
|
40
|
+
total_tokens = @data['usage']['total_tokens'] || (input_tokens + output_tokens)
|
41
|
+
|
42
|
+
@usage ||= Usage.new(
|
43
|
+
input_tokens:,
|
44
|
+
output_tokens:,
|
45
|
+
total_tokens:
|
46
|
+
)
|
37
47
|
end
|
38
48
|
|
39
49
|
# @return [Array<OmniAI::Chat::Choice>]
|
data/lib/omniai/chat/message.rb
CHANGED
@@ -4,22 +4,27 @@ module OmniAI
|
|
4
4
|
class Chat
|
5
5
|
# A message returned by the API.
|
6
6
|
class Message
|
7
|
-
attr_accessor :
|
7
|
+
attr_accessor :role, :content
|
8
8
|
|
9
|
-
# @param
|
10
|
-
# @
|
11
|
-
def
|
12
|
-
|
9
|
+
# @param data [Hash]
|
10
|
+
# @return [OmniAI::Chat::Message]
|
11
|
+
def self.for(data:)
|
12
|
+
content = data['content'] || data[:content]
|
13
|
+
role = data['role'] || data[:role]
|
14
|
+
|
15
|
+
new(content:, role: role || Role::USER)
|
13
16
|
end
|
14
17
|
|
15
|
-
# @
|
16
|
-
|
17
|
-
|
18
|
+
# @param content [String]
|
19
|
+
# @param role [String] optional (default to "user") e.g. "assistant" / "user" / "system"
|
20
|
+
def initialize(content:, role: OmniAI::Chat::Role::USER)
|
21
|
+
@role = role
|
22
|
+
@content = content
|
18
23
|
end
|
19
24
|
|
20
25
|
# @return [String]
|
21
|
-
def
|
22
|
-
|
26
|
+
def inspect
|
27
|
+
"#<#{self.class.name} role=#{role.inspect} content=#{content.inspect}>"
|
23
28
|
end
|
24
29
|
end
|
25
30
|
end
|
data/lib/omniai/chat/usage.rb
CHANGED
@@ -3,37 +3,31 @@
|
|
3
3
|
module OmniAI
|
4
4
|
class Chat
|
5
5
|
# A usage returned by the API.
|
6
|
-
class
|
7
|
-
attr_accessor :
|
6
|
+
class Usage
|
7
|
+
attr_accessor :input_tokens, :output_tokens, :total_tokens
|
8
8
|
|
9
|
-
# @param
|
10
|
-
|
11
|
-
|
9
|
+
# @param input_tokens [Integer]
|
10
|
+
# @param output_tokens [Integer]
|
11
|
+
# @param total_tokens [Integer]
|
12
|
+
def initialize(input_tokens:, output_tokens:, total_tokens:)
|
13
|
+
@input_tokens = input_tokens
|
14
|
+
@output_tokens = output_tokens
|
15
|
+
@total_tokens = total_tokens
|
12
16
|
end
|
13
17
|
|
14
|
-
# @return [Integer
|
18
|
+
# @return [Integer]
|
15
19
|
def completion_tokens
|
16
|
-
@
|
20
|
+
@output_tokens
|
17
21
|
end
|
18
22
|
|
19
|
-
# @return [Integer
|
23
|
+
# @return [Integer]
|
20
24
|
def prompt_tokens
|
21
|
-
@
|
25
|
+
@input_tokens
|
22
26
|
end
|
23
27
|
|
24
|
-
# @return [
|
25
|
-
def
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
# @return [Integer, nil]
|
30
|
-
def input_tokens
|
31
|
-
@data['input_tokens']
|
32
|
-
end
|
33
|
-
|
34
|
-
# @return [Integer, nil]
|
35
|
-
def output_tokens
|
36
|
-
@data['output_tokens']
|
28
|
+
# @return [String]
|
29
|
+
def inspect
|
30
|
+
"#<#{self.class.name} input_tokens=#{input_tokens} output_tokens=#{output_tokens} total_tokens=#{total_tokens}>"
|
37
31
|
end
|
38
32
|
end
|
39
33
|
end
|
data/lib/omniai/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: omniai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-06-
|
11
|
+
date: 2024-06-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: event_stream_parser
|