typesafe-ai-ruby 0.1.0
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 +7 -0
- data/CHANGELOG.md +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +176 -0
- data/lib/typesafe/client.rb +56 -0
- data/lib/typesafe/configuration.rb +129 -0
- data/lib/typesafe/constants.rb +49 -0
- data/lib/typesafe/errors.rb +117 -0
- data/lib/typesafe/http/connection_manager.rb +82 -0
- data/lib/typesafe/http/net_http_transport.rb +74 -0
- data/lib/typesafe/http/request.rb +30 -0
- data/lib/typesafe/http/requestor.rb +153 -0
- data/lib/typesafe/http/response.rb +48 -0
- data/lib/typesafe/http/retrier.rb +57 -0
- data/lib/typesafe/instrumentation.rb +84 -0
- data/lib/typesafe/logging.rb +37 -0
- data/lib/typesafe/questions/choice.rb +33 -0
- data/lib/typesafe/questions/normalizer.rb +65 -0
- data/lib/typesafe/questions/noul.rb +36 -0
- data/lib/typesafe/questions/question.rb +48 -0
- data/lib/typesafe/questions/score.rb +32 -0
- data/lib/typesafe/request_options.rb +56 -0
- data/lib/typesafe/resources/models.rb +18 -0
- data/lib/typesafe/responses/answer.rb +143 -0
- data/lib/typesafe/responses/list_models_response.rb +93 -0
- data/lib/typesafe/responses/reader.rb +75 -0
- data/lib/typesafe/responses/system_one_response.rb +89 -0
- data/lib/typesafe/responses/usage.rb +37 -0
- data/lib/typesafe/retry_policy.rb +133 -0
- data/lib/typesafe/util.rb +156 -0
- data/lib/typesafe/version.rb +5 -0
- data/lib/typesafe-ai-ruby.rb +4 -0
- data/lib/typesafe.rb +114 -0
- data/sig/typesafe/http.rbs +77 -0
- data/sig/typesafe/questions.rbs +48 -0
- data/sig/typesafe/responses.rbs +131 -0
- data/sig/typesafe.rbs +261 -0
- metadata +97 -0
data/sig/typesafe.rbs
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
module TypeSafe
|
|
2
|
+
VERSION: String
|
|
3
|
+
|
|
4
|
+
# Text, a JSON object, or an array as accepted for state, instructions and criteria descriptions.
|
|
5
|
+
type json_content = String | Hash[String, untyped] | Array[untyped]
|
|
6
|
+
|
|
7
|
+
# Anything accepted as state or instructions before normalization.
|
|
8
|
+
type json_input = String | Hash[untyped, untyped] | Array[untyped]
|
|
9
|
+
|
|
10
|
+
# A question object or a raw Hash with a "type" key.
|
|
11
|
+
type question_input = Questions::Question | Hash[untyped, untyped]
|
|
12
|
+
|
|
13
|
+
type request_options_input = RequestOptions | Hash[Symbol | String, untyped] | nil
|
|
14
|
+
|
|
15
|
+
type retry_policy_input = RetryPolicy | Hash[Symbol | String, untyped] | nil
|
|
16
|
+
|
|
17
|
+
class Noul = Questions::Noul
|
|
18
|
+
class Choice = Questions::Choice
|
|
19
|
+
class Score = Questions::Score
|
|
20
|
+
|
|
21
|
+
def self.configuration: () -> Configuration
|
|
22
|
+
def self.configure: () { (Configuration) -> void } -> Configuration
|
|
23
|
+
def self.client: () -> Client
|
|
24
|
+
def self.reset_client!: () -> void
|
|
25
|
+
def self.reset!: () -> void
|
|
26
|
+
def self.noul: (?json_input? instructions, ?Hash[untyped, untyped]? criteria, **untyped named) -> Questions::Noul
|
|
27
|
+
def self.choice: (?json_input? instructions, ?Hash[untyped, untyped]? criteria, **untyped named) -> Questions::Choice
|
|
28
|
+
def self.score: (?json_input? instructions, ?Array[untyped]? criteria) -> Questions::Score
|
|
29
|
+
|
|
30
|
+
module Constants
|
|
31
|
+
API_KEY_ENV: String
|
|
32
|
+
BASE_URL_ENV: String
|
|
33
|
+
DEFAULT_MODEL_ENV: String
|
|
34
|
+
LOG_LEVEL_ENV: String
|
|
35
|
+
DEFAULT_BASE_URL: String
|
|
36
|
+
DEFAULT_MODEL: String
|
|
37
|
+
DEFAULT_TIMEOUT: Float
|
|
38
|
+
DEFAULT_LOG_LEVEL: Symbol
|
|
39
|
+
SYSTEM_ONE_PATH: String
|
|
40
|
+
MODELS_PATH: String
|
|
41
|
+
SDK_NAME: String
|
|
42
|
+
JSON_CONTENT_TYPE: String
|
|
43
|
+
|
|
44
|
+
module Headers
|
|
45
|
+
AUTHORIZATION: String
|
|
46
|
+
ACCEPT: String
|
|
47
|
+
CONTENT_TYPE: String
|
|
48
|
+
USER_AGENT: String
|
|
49
|
+
SDK: String
|
|
50
|
+
RUNTIME: String
|
|
51
|
+
RETRY_COUNT: String
|
|
52
|
+
REQUEST_ID: String
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
class Error < StandardError
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class ConfigurationError < Error
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class ValidationError < Error
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class APIError < Error
|
|
66
|
+
STATUS_CLASSES: Hash[Integer, singleton(APIError)]
|
|
67
|
+
|
|
68
|
+
attr_reader status: Integer?
|
|
69
|
+
attr_reader body: untyped
|
|
70
|
+
attr_reader headers: Hash[String, String]
|
|
71
|
+
attr_reader endpoint: String?
|
|
72
|
+
|
|
73
|
+
def initialize: (?String? message, ?status: Integer?, ?body: untyped, ?headers: Hash[untyped, untyped], ?endpoint: String?) -> void
|
|
74
|
+
def request_id: () -> String?
|
|
75
|
+
def self.from_response: (HTTP::Response response) -> APIError
|
|
76
|
+
def self.class_for_status: (Integer? status) -> singleton(APIError)
|
|
77
|
+
def self.build_message: (status: Integer?, body: untyped, endpoint: String?, request_id: String?) -> String
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
class BadRequestError < APIError
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
class AuthenticationError < APIError
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class PermissionDeniedError < APIError
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
class NotFoundError < APIError
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class UnprocessableEntityError < APIError
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class InternalServerError < APIError
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class OverloadedError < InternalServerError
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
class RateLimitError < APIError
|
|
102
|
+
def retry_after: () -> Float?
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
class APIResponseValidationError < APIError
|
|
106
|
+
attr_reader field_path: String
|
|
107
|
+
|
|
108
|
+
def initialize: (?String? message, field_path: String, **untyped options) -> void
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
class APIConnectionError < Error
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
class APITimeoutError < APIConnectionError
|
|
115
|
+
attr_reader timeout: Numeric?
|
|
116
|
+
|
|
117
|
+
def initialize: (?String? message, ?timeout: Numeric?) -> void
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
class IndifferentHash < Hash[String, untyped]
|
|
121
|
+
def self.from: (Hash[untyped, untyped] hash) -> IndifferentHash
|
|
122
|
+
def []: (String | Symbol key) -> untyped
|
|
123
|
+
def []=: (String | Symbol key, untyped value) -> untyped
|
|
124
|
+
def fetch: (String | Symbol key, *untyped args) ?{ (String) -> untyped } -> untyped
|
|
125
|
+
def key?: (String | Symbol key) -> bool
|
|
126
|
+
def dig: (String | Symbol key, *untyped rest) -> untyped
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
class Configuration
|
|
130
|
+
LOG_LEVELS: Hash[Symbol, Integer]
|
|
131
|
+
|
|
132
|
+
attr_accessor api_key: String?
|
|
133
|
+
attr_accessor base_url: String?
|
|
134
|
+
attr_accessor model: String?
|
|
135
|
+
attr_accessor timeout: Numeric?
|
|
136
|
+
attr_accessor headers: Hash[untyped, untyped]?
|
|
137
|
+
attr_accessor logger: Logger?
|
|
138
|
+
attr_accessor log_level: (Symbol | String)?
|
|
139
|
+
attr_accessor retry_policy: retry_policy_input
|
|
140
|
+
attr_accessor transport: HTTP::_Transport?
|
|
141
|
+
|
|
142
|
+
def initialize: (?api_key: String?, ?base_url: String?, ?model: String?, ?timeout: Numeric?,
|
|
143
|
+
?headers: Hash[untyped, untyped]?, ?logger: Logger?, ?log_level: (Symbol | String)?,
|
|
144
|
+
?retry_policy: retry_policy_input, ?transport: HTTP::_Transport?) -> void
|
|
145
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
146
|
+
def resolve: (?env: _Env) -> Configuration
|
|
147
|
+
def logger_severity: () -> Integer
|
|
148
|
+
|
|
149
|
+
interface _Env
|
|
150
|
+
def []: (String name) -> String?
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
class RetryPolicy
|
|
155
|
+
DEFAULT_HTTP_STATUSES: Array[Integer]
|
|
156
|
+
DEFAULT: RetryPolicy
|
|
157
|
+
|
|
158
|
+
attr_reader max_retries: Integer
|
|
159
|
+
attr_reader backoff_initial: Numeric
|
|
160
|
+
attr_reader backoff_max: Numeric
|
|
161
|
+
attr_reader backoff_jitter: Numeric
|
|
162
|
+
attr_reader http_statuses: Array[Integer]
|
|
163
|
+
attr_reader respect_retry_after: bool
|
|
164
|
+
attr_reader max_retry_after: Numeric
|
|
165
|
+
attr_reader api_connection_error: bool
|
|
166
|
+
attr_reader api_timeout_error: bool
|
|
167
|
+
attr_reader timeout: Numeric?
|
|
168
|
+
|
|
169
|
+
def self.from: (retry_policy_input value, ?base: RetryPolicy?) -> RetryPolicy
|
|
170
|
+
def initialize: (?max_retries: Integer, ?backoff_initial: Numeric, ?backoff_max: Numeric, ?backoff_jitter: Numeric,
|
|
171
|
+
?http_statuses: _Each[Integer], ?respect_retry_after: bool, ?max_retry_after: Numeric,
|
|
172
|
+
?api_connection_error: bool, ?api_timeout_error: bool, ?timeout: Numeric?) -> void
|
|
173
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
174
|
+
def with: (**untyped overrides) -> RetryPolicy
|
|
175
|
+
def ==: (untyped other) -> bool
|
|
176
|
+
alias eql? ==
|
|
177
|
+
def hash: () -> Integer
|
|
178
|
+
def retry_status?: (Integer? status) -> bool
|
|
179
|
+
def retry_error?: (Exception error) -> bool
|
|
180
|
+
def delay_for: (Integer attempt, ?headers: Hash[untyped, untyped]?, ?random: _Random) -> Numeric
|
|
181
|
+
|
|
182
|
+
interface _Random
|
|
183
|
+
def rand: () -> Float
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
class RequestOptions
|
|
188
|
+
KEYS: Array[Symbol]
|
|
189
|
+
|
|
190
|
+
attr_reader timeout: Numeric?
|
|
191
|
+
attr_reader headers: Hash[String, String]
|
|
192
|
+
attr_reader extra_body: Hash[String, untyped]?
|
|
193
|
+
attr_reader retry_policy: retry_policy_input
|
|
194
|
+
|
|
195
|
+
def self.from: (request_options_input options) -> RequestOptions
|
|
196
|
+
def initialize: (?timeout: Numeric?, ?headers: Hash[untyped, untyped]?, ?extra_body: Hash[untyped, untyped]?,
|
|
197
|
+
?retry_policy: retry_policy_input) -> void
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
class Client
|
|
201
|
+
attr_reader config: Configuration
|
|
202
|
+
attr_reader models: Resources::Models
|
|
203
|
+
|
|
204
|
+
def initialize: (?api_key: String?, ?base_url: String?, ?model: String?, ?timeout: Numeric?,
|
|
205
|
+
?headers: Hash[untyped, untyped]?, ?logger: Logger?, ?log_level: (Symbol | String)?,
|
|
206
|
+
?retry_policy: retry_policy_input, ?transport: HTTP::_Transport?) -> void
|
|
207
|
+
def system_one: (state: json_input, questions: Hash[String | Symbol, question_input], ?model: String?,
|
|
208
|
+
?request_options: request_options_input) -> Responses::SystemOneResponse
|
|
209
|
+
def close: () -> void
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
module Resources
|
|
213
|
+
class Models
|
|
214
|
+
def initialize: (HTTP::Requestor requestor) -> void
|
|
215
|
+
def list: (?request_options: request_options_input) -> Responses::ListModelsResponse
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
module Logging
|
|
220
|
+
PROGNAME: String
|
|
221
|
+
REDACTED: String
|
|
222
|
+
REDACTED_HEADERS: Array[String]
|
|
223
|
+
|
|
224
|
+
def self?.log?: (Configuration config, Integer severity) -> bool
|
|
225
|
+
def self?.info: (Configuration config) { () -> String } -> void
|
|
226
|
+
def self?.debug: (Configuration config) { () -> String } -> void
|
|
227
|
+
def self?.redact_headers: (Hash[untyped, untyped] headers) -> Hash[untyped, untyped]
|
|
228
|
+
def self?.format_headers: (Hash[untyped, untyped] headers) -> String
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
module Instrumentation
|
|
232
|
+
TOPICS: Array[Symbol]
|
|
233
|
+
|
|
234
|
+
class RequestBeginEvent
|
|
235
|
+
attr_reader method: Symbol
|
|
236
|
+
attr_reader path: String
|
|
237
|
+
attr_reader user_data: Hash[untyped, untyped]
|
|
238
|
+
|
|
239
|
+
def initialize: (method: Symbol, path: String) -> void
|
|
240
|
+
end
|
|
241
|
+
|
|
242
|
+
class RequestEndEvent
|
|
243
|
+
attr_reader method: Symbol
|
|
244
|
+
attr_reader path: String
|
|
245
|
+
attr_reader http_status: Integer?
|
|
246
|
+
attr_reader duration: Float
|
|
247
|
+
attr_reader num_retries: Integer
|
|
248
|
+
attr_reader request_id: String?
|
|
249
|
+
attr_reader error: Exception?
|
|
250
|
+
attr_reader user_data: Hash[untyped, untyped]
|
|
251
|
+
|
|
252
|
+
def initialize: (method: Symbol, path: String, http_status: Integer?, duration: Float, num_retries: Integer,
|
|
253
|
+
request_id: String?, error: Exception?, user_data: Hash[untyped, untyped]) -> void
|
|
254
|
+
end
|
|
255
|
+
|
|
256
|
+
def self.subscribe: (Symbol topic, ?untyped name) { (RequestBeginEvent | RequestEndEvent) -> void } -> untyped
|
|
257
|
+
def self.unsubscribe: (Symbol topic, untyped name) -> void
|
|
258
|
+
def self.notify: (Symbol topic, untyped event) -> void
|
|
259
|
+
def self.reset!: () -> void
|
|
260
|
+
end
|
|
261
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: typesafe-ai-ruby
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- hnegishi
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: logger
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '1.5'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '1.5'
|
|
26
|
+
description: |-
|
|
27
|
+
Ask TypeSafe's Jev model typed Noul, Choice, and Score questions about text or
|
|
28
|
+
structured state and get calibrated, structured answers back. Zero runtime dependencies.
|
|
29
|
+
email:
|
|
30
|
+
- negishi_h@uuum.jp
|
|
31
|
+
executables: []
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- CHANGELOG.md
|
|
36
|
+
- LICENSE.txt
|
|
37
|
+
- README.md
|
|
38
|
+
- lib/typesafe-ai-ruby.rb
|
|
39
|
+
- lib/typesafe.rb
|
|
40
|
+
- lib/typesafe/client.rb
|
|
41
|
+
- lib/typesafe/configuration.rb
|
|
42
|
+
- lib/typesafe/constants.rb
|
|
43
|
+
- lib/typesafe/errors.rb
|
|
44
|
+
- lib/typesafe/http/connection_manager.rb
|
|
45
|
+
- lib/typesafe/http/net_http_transport.rb
|
|
46
|
+
- lib/typesafe/http/request.rb
|
|
47
|
+
- lib/typesafe/http/requestor.rb
|
|
48
|
+
- lib/typesafe/http/response.rb
|
|
49
|
+
- lib/typesafe/http/retrier.rb
|
|
50
|
+
- lib/typesafe/instrumentation.rb
|
|
51
|
+
- lib/typesafe/logging.rb
|
|
52
|
+
- lib/typesafe/questions/choice.rb
|
|
53
|
+
- lib/typesafe/questions/normalizer.rb
|
|
54
|
+
- lib/typesafe/questions/noul.rb
|
|
55
|
+
- lib/typesafe/questions/question.rb
|
|
56
|
+
- lib/typesafe/questions/score.rb
|
|
57
|
+
- lib/typesafe/request_options.rb
|
|
58
|
+
- lib/typesafe/resources/models.rb
|
|
59
|
+
- lib/typesafe/responses/answer.rb
|
|
60
|
+
- lib/typesafe/responses/list_models_response.rb
|
|
61
|
+
- lib/typesafe/responses/reader.rb
|
|
62
|
+
- lib/typesafe/responses/system_one_response.rb
|
|
63
|
+
- lib/typesafe/responses/usage.rb
|
|
64
|
+
- lib/typesafe/retry_policy.rb
|
|
65
|
+
- lib/typesafe/util.rb
|
|
66
|
+
- lib/typesafe/version.rb
|
|
67
|
+
- sig/typesafe.rbs
|
|
68
|
+
- sig/typesafe/http.rbs
|
|
69
|
+
- sig/typesafe/questions.rbs
|
|
70
|
+
- sig/typesafe/responses.rbs
|
|
71
|
+
homepage: https://github.com/hnegishi/typesafe-ai-ruby
|
|
72
|
+
licenses:
|
|
73
|
+
- MIT
|
|
74
|
+
metadata:
|
|
75
|
+
source_code_uri: https://github.com/hnegishi/typesafe-ai-ruby
|
|
76
|
+
changelog_uri: https://github.com/hnegishi/typesafe-ai-ruby/blob/main/CHANGELOG.md
|
|
77
|
+
bug_tracker_uri: https://github.com/hnegishi/typesafe-ai-ruby/issues
|
|
78
|
+
documentation_uri: https://docs.typesafe.ai/
|
|
79
|
+
rubygems_mfa_required: 'true'
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: 3.1.0
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubygems_version: 3.6.9
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Ruby client for the TypeSafe AI System One API (Jev)
|
|
97
|
+
test_files: []
|