jevrb 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/LICENSE +21 -0
- data/README.md +175 -0
- data/lib/jevrb/answer.rb +214 -0
- data/lib/jevrb/choice.rb +41 -0
- data/lib/jevrb/client.rb +185 -0
- data/lib/jevrb/constants.rb +11 -0
- data/lib/jevrb/errors.rb +76 -0
- data/lib/jevrb/noul.rb +36 -0
- data/lib/jevrb/question.rb +22 -0
- data/lib/jevrb/result.rb +59 -0
- data/lib/jevrb/retry_policy.rb +130 -0
- data/lib/jevrb/score.rb +29 -0
- data/lib/jevrb/support.rb +57 -0
- data/lib/jevrb/transport.rb +45 -0
- data/lib/jevrb/usage.rb +27 -0
- data/lib/jevrb/version.rb +5 -0
- data/lib/jevrb.rb +22 -0
- data/sig/jevrb.rbs +203 -0
- metadata +61 -0
data/sig/jevrb.rbs
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
module Jevrb
|
|
2
|
+
type json_value = String | Integer | Float | bool | nil | Array[json_value] | Hash[String | Symbol, json_value]
|
|
3
|
+
type json_content = String | Array[json_value] | Hash[String | Symbol, json_value]
|
|
4
|
+
type question_key = String | Symbol
|
|
5
|
+
type answer = NoulAnswer | ChoiceAnswer | ScoreAnswer
|
|
6
|
+
|
|
7
|
+
VERSION: String
|
|
8
|
+
API_KEY_ENV: String
|
|
9
|
+
BASE_URL_ENV: String
|
|
10
|
+
DEFAULT_MODEL_ENV: String
|
|
11
|
+
DEFAULT_BASE_URL: String
|
|
12
|
+
DEFAULT_MODEL: String
|
|
13
|
+
DEFAULT_TIMEOUT: Float
|
|
14
|
+
|
|
15
|
+
class Error < StandardError
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
class ConfigurationError < Error
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
class APIError < Error
|
|
22
|
+
attr_reader status: Integer
|
|
23
|
+
attr_reader body: untyped
|
|
24
|
+
attr_reader headers: Hash[String, String]
|
|
25
|
+
attr_reader endpoint: String
|
|
26
|
+
|
|
27
|
+
def initialize: (status: Integer, body: untyped, headers: Hash[String, String], endpoint: String, ?message: String?) -> void
|
|
28
|
+
def request_id: () -> String?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
class BadRequestError < APIError
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class AuthenticationError < APIError
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class PermissionDeniedError < APIError
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
class NotFoundError < APIError
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
class UnprocessableEntityError < APIError
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class RateLimitError < APIError
|
|
47
|
+
def retry_after_ms: () -> Float?
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class InternalServerError < APIError
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
class ConnectionError < Error
|
|
54
|
+
attr_reader endpoint: String
|
|
55
|
+
|
|
56
|
+
def initialize: (endpoint: String, ?message: String?) -> void
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
class TimeoutError < ConnectionError
|
|
60
|
+
attr_reader timeout: Float
|
|
61
|
+
|
|
62
|
+
def initialize: (endpoint: String, timeout: Float, ?message: String?) -> void
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
class ResponseValidationError < APIError
|
|
66
|
+
attr_reader field_path: String
|
|
67
|
+
|
|
68
|
+
def initialize: (status: Integer, body: untyped, headers: Hash[String, String], field_path: String, endpoint: String, ?message: String?) -> void
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
class Question
|
|
72
|
+
attr_reader type: String
|
|
73
|
+
attr_reader instructions: json_content
|
|
74
|
+
attr_reader criteria: untyped
|
|
75
|
+
|
|
76
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
class Noul < Question
|
|
80
|
+
CRITERIA_KEYS: Array[String]
|
|
81
|
+
|
|
82
|
+
def self.build: (instructions: json_content, ?criteria: Hash[String | Symbol | bool, json_content?]?) -> Noul
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
class Choice < Question
|
|
86
|
+
MAX_OPTIONS: Integer
|
|
87
|
+
|
|
88
|
+
def self.build: (instructions: json_content, criteria: Hash[String | Symbol, json_content?]) -> Choice
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
class Score < Question
|
|
92
|
+
MIN_LEVELS: Integer
|
|
93
|
+
MAX_LEVELS: Integer
|
|
94
|
+
|
|
95
|
+
def self.build: (instructions: json_content, criteria: Array[json_content]) -> Score
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class Answer
|
|
99
|
+
attr_reader type: String
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
class NoulAnswer < Answer
|
|
103
|
+
attr_reader noul: Float
|
|
104
|
+
|
|
105
|
+
def self.from_hash: (Hash[String, untyped], path: String) -> NoulAnswer
|
|
106
|
+
def to_h: () -> { type: String, noul: Float }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
class ChoiceAnswer < Answer
|
|
110
|
+
attr_reader choice: String
|
|
111
|
+
attr_reader probabilities: Hash[String, Float]
|
|
112
|
+
attr_reader confidence: Float
|
|
113
|
+
|
|
114
|
+
def self.from_hash: (Hash[String, untyped], path: String) -> ChoiceAnswer
|
|
115
|
+
def to_h: () -> { type: String, choice: String, probabilities: Hash[String, Float], confidence: Float }
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
class ScoreAnswer < Answer
|
|
119
|
+
attr_reader score: Float
|
|
120
|
+
attr_reader legend: Hash[Integer, json_content]
|
|
121
|
+
attr_reader probabilities: Hash[Integer, Float]
|
|
122
|
+
attr_reader confidence: Float
|
|
123
|
+
|
|
124
|
+
def self.from_hash: (Hash[String, untyped], path: String) -> ScoreAnswer
|
|
125
|
+
def to_h: () -> { type: String, score: Float, legend: Hash[Integer, json_content], probabilities: Hash[Integer, Float], confidence: Float }
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
class Usage
|
|
129
|
+
attr_reader input_tokens: Integer?
|
|
130
|
+
attr_reader output_tokens: Integer?
|
|
131
|
+
|
|
132
|
+
def self.from_hash: (Hash[String, untyped], ?path: String) -> Usage
|
|
133
|
+
def to_h: () -> { input_tokens: Integer?, output_tokens: Integer? }
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
class Result
|
|
137
|
+
ANSWER_CLASSES: Hash[String, singleton(NoulAnswer) | singleton(ChoiceAnswer) | singleton(ScoreAnswer)]
|
|
138
|
+
|
|
139
|
+
attr_reader model: String
|
|
140
|
+
attr_reader answers: Hash[question_key, answer]
|
|
141
|
+
attr_reader usage: Usage
|
|
142
|
+
attr_reader request_id: String?
|
|
143
|
+
|
|
144
|
+
def self.from_hash: (Hash[String, untyped], ?key_map: Hash[String, question_key], ?request_id: String?) -> Result
|
|
145
|
+
def nouls: () -> Hash[question_key, NoulAnswer]
|
|
146
|
+
def choices: () -> Hash[question_key, ChoiceAnswer]
|
|
147
|
+
def scores: () -> Hash[question_key, ScoreAnswer]
|
|
148
|
+
def to_h: () -> Hash[Symbol, untyped]
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
class RetryPolicy
|
|
152
|
+
DEFAULT_HTTP_STATUSES: Enumerable[Integer]
|
|
153
|
+
|
|
154
|
+
attr_reader max_retries: Integer
|
|
155
|
+
attr_reader backoff_initial: Float
|
|
156
|
+
attr_reader backoff_max: Float
|
|
157
|
+
attr_reader backoff_jitter: Float
|
|
158
|
+
attr_reader http_statuses: Enumerable[Integer]
|
|
159
|
+
attr_reader respect_retry_after: bool
|
|
160
|
+
attr_reader retry_connection_errors: bool
|
|
161
|
+
attr_reader retry_timeout_errors: bool
|
|
162
|
+
attr_reader timeout: Float?
|
|
163
|
+
|
|
164
|
+
def initialize: (
|
|
165
|
+
?max_retries: Integer,
|
|
166
|
+
?backoff_initial: Float,
|
|
167
|
+
?backoff_max: Float,
|
|
168
|
+
?backoff_jitter: Float,
|
|
169
|
+
?http_statuses: Enumerable[Integer],
|
|
170
|
+
?respect_retry_after: bool,
|
|
171
|
+
?retry_connection_errors: bool,
|
|
172
|
+
?retry_timeout_errors: bool,
|
|
173
|
+
?timeout: Float?,
|
|
174
|
+
?sleeper: ^(Float) -> void,
|
|
175
|
+
?random: untyped,
|
|
176
|
+
?clock: ^() -> Float
|
|
177
|
+
) -> void
|
|
178
|
+
|
|
179
|
+
def execute: [T] () { () -> T } -> T
|
|
180
|
+
def retryable?: (Error) -> bool
|
|
181
|
+
def retry_delay: (Error, Integer) -> Float
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
class Client
|
|
185
|
+
attr_reader api_key: String
|
|
186
|
+
attr_reader base_url: String
|
|
187
|
+
attr_reader model: String
|
|
188
|
+
attr_reader timeout: Float
|
|
189
|
+
attr_reader retry_policy: RetryPolicy
|
|
190
|
+
|
|
191
|
+
def initialize: (
|
|
192
|
+
?api_key: String,
|
|
193
|
+
?base_url: String,
|
|
194
|
+
?model: String,
|
|
195
|
+
?timeout: Float,
|
|
196
|
+
?retry_policy: RetryPolicy?
|
|
197
|
+
) -> void
|
|
198
|
+
|
|
199
|
+
def system_one: (json_content state, questions: Hash[question_key, Question], ?model: String?) -> Result
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
module Jev = Jevrb
|
metadata
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: jevrb
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- maful
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Send typed questions to TypeSafe System One and receive typed Ruby response
|
|
13
|
+
objects.
|
|
14
|
+
email:
|
|
15
|
+
- me@maful.web.id
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/jevrb.rb
|
|
23
|
+
- lib/jevrb/answer.rb
|
|
24
|
+
- lib/jevrb/choice.rb
|
|
25
|
+
- lib/jevrb/client.rb
|
|
26
|
+
- lib/jevrb/constants.rb
|
|
27
|
+
- lib/jevrb/errors.rb
|
|
28
|
+
- lib/jevrb/noul.rb
|
|
29
|
+
- lib/jevrb/question.rb
|
|
30
|
+
- lib/jevrb/result.rb
|
|
31
|
+
- lib/jevrb/retry_policy.rb
|
|
32
|
+
- lib/jevrb/score.rb
|
|
33
|
+
- lib/jevrb/support.rb
|
|
34
|
+
- lib/jevrb/transport.rb
|
|
35
|
+
- lib/jevrb/usage.rb
|
|
36
|
+
- lib/jevrb/version.rb
|
|
37
|
+
- sig/jevrb.rbs
|
|
38
|
+
homepage: https://github.com/maful/jev
|
|
39
|
+
licenses:
|
|
40
|
+
- MIT
|
|
41
|
+
metadata:
|
|
42
|
+
bug_tracker_uri: https://github.com/maful/jev/issues
|
|
43
|
+
rubygems_mfa_required: 'true'
|
|
44
|
+
rdoc_options: []
|
|
45
|
+
require_paths:
|
|
46
|
+
- lib
|
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
48
|
+
requirements:
|
|
49
|
+
- - ">="
|
|
50
|
+
- !ruby/object:Gem::Version
|
|
51
|
+
version: 3.2.0
|
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: '0'
|
|
57
|
+
requirements: []
|
|
58
|
+
rubygems_version: 4.0.20
|
|
59
|
+
specification_version: 4
|
|
60
|
+
summary: Ruby client for the TypeSafe System One API
|
|
61
|
+
test_files: []
|