omniai 1.3.0 → 1.3.1

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: 341ce12cf0950b167a43c298f3ccb1df821bbdc469bc6824b14219bef4e38ab5
4
- data.tar.gz: 9badfe7e48d20fe84054d9206e8572a333f382407c3236a3715e1d85cf6b6a84
3
+ metadata.gz: 28e6e2a736d78cbc0135308eb28320a85a319b78a888cd96fa3320456c3c0222
4
+ data.tar.gz: '044786d21ba8f2316599836af153c6dec80d055a0cbcf1e843c000296d1df350'
5
5
  SHA512:
6
- metadata.gz: f81164e402f5e1e4b2ccc2e627675d42631cfda985bf91469eb32735a789eecbe69c7f10bd9d2d5b4959f2d0f2484ae1bf7ced58f607a7cae822846c831ce96c
7
- data.tar.gz: '0182828dad6fb6f6d98550608c3bd57ee980ff4acbcc6dfb3ee7d61a16200566f1c8965424537583d0b73225298ca5eba6ddafd3c51791ca847f53264a7654fd'
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
- I, [...] INFO -- : > POST https://...
91
- D, [...] DEBUG -- : Authorization: Bearer ...
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
@@ -59,6 +59,7 @@ module OmniAI
59
59
  # @raise [HTTPError]
60
60
  def process!
61
61
  response = request!
62
+
62
63
  raise HTTPError, response.flush unless response.status.ok?
63
64
 
64
65
  parse!(response:)
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(logging: { logger: @logger }) if @logger
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
@@ -84,6 +84,7 @@ module OmniAI
84
84
  # @return [Tempfile]
85
85
  def process!(&block)
86
86
  response = request!
87
+
87
88
  raise HTTPError, response.flush unless response.status.ok?
88
89
 
89
90
  if block
@@ -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)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OmniAI
4
- VERSION = '1.3.0'
4
+ VERSION = '1.3.1'
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.3.0
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