omniai 1.3.0 → 1.3.1
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/README.md +2 -31
- data/lib/omniai/chat.rb +1 -0
- data/lib/omniai/client.rb +1 -1
- data/lib/omniai/instrumentation.rb +37 -0
- data/lib/omniai/speak.rb +1 -0
- data/lib/omniai/transcribe.rb +1 -0
- data/lib/omniai/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28e6e2a736d78cbc0135308eb28320a85a319b78a888cd96fa3320456c3c0222
|
4
|
+
data.tar.gz: '044786d21ba8f2316599836af153c6dec80d055a0cbcf1e843c000296d1df350'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c260f1b52fe5ffec70dc5c6755426c9798062bb234da303d76ec21319d450433e95f03ca787fcfa8cd966899235416d5a83580ffd11c24615d8a58df8d64efbc
|
7
|
+
data.tar.gz: 0acc9d0556d0bf8de430ca3a52977c88c6a43edfe017226d1831b4ccc034d2ba3bcde38fad112d61d8910bfc9a9ee440999354919a8d4c3cb614a0d0fc3e2314
|
data/README.md
CHANGED
@@ -87,40 +87,11 @@ client = OmniAI::Example::Client.new(logger:)
|
|
87
87
|
```
|
88
88
|
|
89
89
|
```
|
90
|
-
|
91
|
-
|
90
|
+
[INFO]: POST https://...
|
91
|
+
[INFO]: 200 OK
|
92
92
|
...
|
93
|
-
{"messages":[{"role":"user","content":"Tell me a joke!"}],"model":"..."}
|
94
|
-
I, [...] INFO -- : < 200 OK
|
95
|
-
D, [...] DEBUG -- : Date: ...
|
96
|
-
...
|
97
|
-
{
|
98
|
-
"id": "...",
|
99
|
-
"object": "...",
|
100
|
-
...
|
101
|
-
}
|
102
|
-
```
|
103
|
-
|
104
|
-
The level of the logger can be configured to either `INFO` and `DEBUG`:
|
105
|
-
|
106
|
-
**INFO**:
|
107
|
-
|
108
|
-
```ruby
|
109
|
-
logger.level = Logger::INFO
|
110
93
|
```
|
111
94
|
|
112
|
-
- Request: verb / URI
|
113
|
-
- Response: status
|
114
|
-
|
115
|
-
**DEBUG**:
|
116
|
-
|
117
|
-
```ruby
|
118
|
-
logger.level = Logger::DEBUG
|
119
|
-
```
|
120
|
-
|
121
|
-
- Request: verb / URI / headers / body
|
122
|
-
- Response: status / headers / body
|
123
|
-
|
124
95
|
#### Timeouts
|
125
96
|
|
126
97
|
Timeouts are configurable by passing a `timeout` an integer duration for the request / response of any APIs using:
|
data/lib/omniai/chat.rb
CHANGED
data/lib/omniai/client.rb
CHANGED
@@ -57,7 +57,7 @@ module OmniAI
|
|
57
57
|
# @return [HTTP::Client]
|
58
58
|
def connection
|
59
59
|
http = HTTP.persistent(@host)
|
60
|
-
http = http.use(
|
60
|
+
http = http.use(instrumentation: { instrumenter: Instrumentation.new(logger: @logger) }) if @logger
|
61
61
|
http = http.timeout(@timeout) if @timeout
|
62
62
|
http
|
63
63
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OmniAI
|
4
|
+
# Used for logging.
|
5
|
+
class Instrumentation
|
6
|
+
# @param logger [Logger]
|
7
|
+
def initialize(logger:)
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
# @param name [String]
|
12
|
+
# @param payload [Hash]
|
13
|
+
# @option payload [Exception] :error
|
14
|
+
def instrument(name, payload = {})
|
15
|
+
error = payload[:error]
|
16
|
+
return unless error
|
17
|
+
|
18
|
+
@logger.error("#{name}: #{error.message}")
|
19
|
+
end
|
20
|
+
|
21
|
+
# @param name [String]
|
22
|
+
# @param payload [Hash]
|
23
|
+
# @option payload [HTTP::Request] :request
|
24
|
+
def start(_, payload)
|
25
|
+
request = payload[:request]
|
26
|
+
@logger.info("#{request.verb.upcase} #{request.uri}")
|
27
|
+
end
|
28
|
+
|
29
|
+
# @param name [String]
|
30
|
+
# @param payload [Hash]
|
31
|
+
# @option payload [HTTP::Response] :response
|
32
|
+
def finish(_, payload)
|
33
|
+
response = payload[:response]
|
34
|
+
@logger.info("#{response.status.code} #{response.status.reason}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/omniai/speak.rb
CHANGED
data/lib/omniai/transcribe.rb
CHANGED
@@ -117,6 +117,7 @@ module OmniAI
|
|
117
117
|
# @return [OmniAI::Transcribe::Transcription]
|
118
118
|
def process!
|
119
119
|
response = request!
|
120
|
+
|
120
121
|
raise HTTPError, response.flush unless response.status.ok?
|
121
122
|
|
122
123
|
text = @format.nil? || @format.eql?(Format::JSON) ? response.parse['text'] : String(response.body)
|
data/lib/omniai/version.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.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kevin Sylvestre
|
@@ -80,6 +80,7 @@ files:
|
|
80
80
|
- lib/omniai/chat/usage.rb
|
81
81
|
- lib/omniai/client.rb
|
82
82
|
- lib/omniai/config.rb
|
83
|
+
- lib/omniai/instrumentation.rb
|
83
84
|
- lib/omniai/speak.rb
|
84
85
|
- lib/omniai/transcribe.rb
|
85
86
|
- lib/omniai/transcribe/transcription.rb
|