apologist 1.0.2
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/.fern/metadata.json +13 -0
- data/.fernignore +2 -0
- data/.rubocop.yml +108 -0
- data/CONTRIBUTING.md +120 -0
- data/README.md +169 -0
- data/Rakefile +20 -0
- data/custom.gemspec.rb +17 -0
- data/lib/Apologist/benchmarks/client.rb +160 -0
- data/lib/Apologist/benchmarks/types/benchmark_run_request.rb +39 -0
- data/lib/Apologist/benchmarks/types/benchmark_run_request_content.rb +16 -0
- data/lib/Apologist/benchmarks/types/benchmark_run_request_reasoning_effort.rb +15 -0
- data/lib/Apologist/benchmarks/types/benchmark_run_request_verbosity.rb +16 -0
- data/lib/Apologist/benchmarks/types/get_benchmark_run_request.rb +13 -0
- data/lib/Apologist/benchmarks/types/get_benchmark_run_response.rb +11 -0
- data/lib/Apologist/benchmarks/types/list_benchmark_runs_request.rb +33 -0
- data/lib/Apologist/benchmarks/types/list_benchmark_runs_response.rb +17 -0
- data/lib/Apologist/channels/client.rb +319 -0
- data/lib/Apologist/channels/types/get_discord_channel_status_request.rb +11 -0
- data/lib/Apologist/channels/types/get_discord_channel_status_response.rb +15 -0
- data/lib/Apologist/channels/types/get_instagram_privacy_policy_request.rb +11 -0
- data/lib/Apologist/channels/types/receive_discord_interaction_request.rb +17 -0
- data/lib/Apologist/channels/types/receive_facebook_message_request.rb +13 -0
- data/lib/Apologist/channels/types/receive_telegram_update_request.rb +13 -0
- data/lib/Apologist/channels/types/receive_twilio_message_request.rb +15 -0
- data/lib/Apologist/channels/types/verify_facebook_webhook_request.rb +17 -0
- data/lib/Apologist/channels/types/verify_facebook_webhook_request_hub_mode.rb +13 -0
- data/lib/Apologist/chat/client.rb +345 -0
- data/lib/Apologist/chat/types/feedback_request.rb +13 -0
- data/lib/Apologist/chat/types/flag_request.rb +13 -0
- data/lib/Apologist/chat/types/get_chat_completion_request.rb +11 -0
- data/lib/Apologist/chat/types/get_chat_completion_response.rb +11 -0
- data/lib/Apologist/chat/types/like_request.rb +13 -0
- data/lib/Apologist/chat/types/list_chat_completions_request.rb +45 -0
- data/lib/Apologist/chat/types/list_chat_completions_response.rb +17 -0
- data/lib/Apologist/chat/types/share_request.rb +17 -0
- data/lib/Apologist/client.rb +71 -0
- data/lib/Apologist/corpus/client.rb +244 -0
- data/lib/Apologist/corpus/types/corpus_search_request.rb +17 -0
- data/lib/Apologist/corpus/types/corpus_search_request_filters.rb +25 -0
- data/lib/Apologist/corpus/types/impression_request.rb +17 -0
- data/lib/Apologist/corpus/types/log_corpus_referral_redirect_request.rb +19 -0
- data/lib/Apologist/corpus/types/referral_request.rb +17 -0
- data/lib/Apologist/corpus/types/search_corpus_response.rb +11 -0
- data/lib/Apologist/corpus/types/view_request.rb +17 -0
- data/lib/Apologist/ct_as/client.rb +98 -0
- data/lib/Apologist/ct_as/types/cta_click_request.rb +13 -0
- data/lib/Apologist/ct_as/types/match_ctas_response.rb +11 -0
- data/lib/Apologist/environment.rb +7 -0
- data/lib/Apologist/errors/api_error.rb +8 -0
- data/lib/Apologist/errors/client_error.rb +17 -0
- data/lib/Apologist/errors/redirect_error.rb +8 -0
- data/lib/Apologist/errors/response_error.rb +42 -0
- data/lib/Apologist/errors/server_error.rb +11 -0
- data/lib/Apologist/errors/timeout_error.rb +8 -0
- data/lib/Apologist/evaluators/client.rb +164 -0
- data/lib/Apologist/evaluators/types/evaluate_content_response.rb +11 -0
- data/lib/Apologist/evaluators/types/evaluator_request.rb +31 -0
- data/lib/Apologist/evaluators/types/evaluator_request_content.rb +15 -0
- data/lib/Apologist/evaluators/types/evaluator_request_reasoning_effort.rb +15 -0
- data/lib/Apologist/evaluators/types/evaluator_request_verbosity.rb +16 -0
- data/lib/Apologist/evaluators/types/get_evaluation_request.rb +13 -0
- data/lib/Apologist/evaluators/types/get_evaluation_response.rb +11 -0
- data/lib/Apologist/evaluators/types/list_evaluations_request.rb +35 -0
- data/lib/Apologist/evaluators/types/list_evaluations_response.rb +17 -0
- data/lib/Apologist/internal/errors/constraint_error.rb +10 -0
- data/lib/Apologist/internal/errors/type_error.rb +10 -0
- data/lib/Apologist/internal/http/base_request.rb +51 -0
- data/lib/Apologist/internal/http/raw_client.rb +252 -0
- data/lib/Apologist/internal/iterators/cursor_item_iterator.rb +28 -0
- data/lib/Apologist/internal/iterators/cursor_page_iterator.rb +63 -0
- data/lib/Apologist/internal/iterators/item_iterator.rb +65 -0
- data/lib/Apologist/internal/iterators/offset_item_iterator.rb +30 -0
- data/lib/Apologist/internal/iterators/offset_page_iterator.rb +103 -0
- data/lib/Apologist/internal/json/request.rb +41 -0
- data/lib/Apologist/internal/json/serializable.rb +25 -0
- data/lib/Apologist/internal/multipart/multipart_encoder.rb +141 -0
- data/lib/Apologist/internal/multipart/multipart_form_data.rb +78 -0
- data/lib/Apologist/internal/multipart/multipart_form_data_part.rb +51 -0
- data/lib/Apologist/internal/multipart/multipart_request.rb +40 -0
- data/lib/Apologist/internal/types/array.rb +47 -0
- data/lib/Apologist/internal/types/boolean.rb +34 -0
- data/lib/Apologist/internal/types/enum.rb +56 -0
- data/lib/Apologist/internal/types/hash.rb +36 -0
- data/lib/Apologist/internal/types/model/field.rb +38 -0
- data/lib/Apologist/internal/types/model.rb +208 -0
- data/lib/Apologist/internal/types/type.rb +35 -0
- data/lib/Apologist/internal/types/union.rb +161 -0
- data/lib/Apologist/internal/types/unknown.rb +15 -0
- data/lib/Apologist/internal/types/utils.rb +116 -0
- data/lib/Apologist/internal/url_encoded/request.rb +41 -0
- data/lib/Apologist/shares/client.rb +52 -0
- data/lib/Apologist/shares/types/get_shared_messages_request.rb +11 -0
- data/lib/Apologist/shares/types/get_shared_messages_response.rb +11 -0
- data/lib/Apologist/types/chat_completion_request.rb +11 -0
- data/lib/Apologist/types/chat_completion_request_logprobs.rb +13 -0
- data/lib/Apologist/types/chat_completion_request_metadata.rb +29 -0
- data/lib/Apologist/types/chat_completion_request_reasoning_effort.rb +13 -0
- data/lib/Apologist/types/chat_completion_request_response_format.rb +11 -0
- data/lib/Apologist/types/chat_completion_request_response_format_json_schema.rb +17 -0
- data/lib/Apologist/types/chat_completion_request_response_format_type.rb +15 -0
- data/lib/Apologist/types/chat_completion_request_tool_choice.rb +13 -0
- data/lib/Apologist/types/chat_completion_request_tool_choice_zero.rb +13 -0
- data/lib/Apologist/types/chat_completion_request_verbosity.rb +14 -0
- data/lib/Apologist/types/chat_completion_response.rb +21 -0
- data/lib/Apologist/types/chat_completion_response_choices_item.rb +15 -0
- data/lib/Apologist/types/chat_completion_response_usage.rb +13 -0
- data/lib/Apologist/types/chat_message.rb +11 -0
- data/lib/Apologist/types/chat_message_role.rb +13 -0
- data/lib/Apologist/types/cta_match_request.rb +11 -0
- data/lib/Apologist/types/error.rb +11 -0
- data/lib/Apologist/types/success_response.rb +11 -0
- data/lib/Apologist/types/tag_ref.rb +11 -0
- data/lib/Apologist/types/user.rb +23 -0
- data/lib/Apologist/types/user_flag.rb +18 -0
- data/lib/Apologist/types/webhook_agent_ref.rb +11 -0
- data/lib/Apologist/types/webhook_cta.rb +13 -0
- data/lib/Apologist/types/webhook_evaluation.rb +14 -0
- data/lib/Apologist/types/webhook_event_info.rb +13 -0
- data/lib/Apologist/types/webhook_event_info_key.rb +28 -0
- data/lib/Apologist/types/webhook_named_ref.rb +11 -0
- data/lib/Apologist/types/webhook_notification_ref.rb +12 -0
- data/lib/Apologist/types/webhook_payload.rb +30 -0
- data/lib/Apologist/users/client.rb +193 -0
- data/lib/Apologist/users/types/get_user_request.rb +11 -0
- data/lib/Apologist/users/types/get_user_response.rb +11 -0
- data/lib/Apologist/users/types/list_user_flags_request.rb +13 -0
- data/lib/Apologist/users/types/list_user_flags_response.rb +17 -0
- data/lib/Apologist/users/types/list_users_request.rb +23 -0
- data/lib/Apologist/users/types/list_users_response.rb +17 -0
- data/lib/Apologist/users/types/update_user_response.rb +11 -0
- data/lib/Apologist/users/types/user_update_request.rb +17 -0
- data/lib/Apologist/users/types/user_update_request_tags_item.rb +15 -0
- data/lib/Apologist/version.rb +5 -0
- data/lib/Apologist.rb +131 -0
- data/reference.md +2927 -0
- metadata +183 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
class Client
|
|
6
|
+
# @param client [Apologist::Internal::Http::RawClient]
|
|
7
|
+
#
|
|
8
|
+
# @return [void]
|
|
9
|
+
def initialize(client:)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Performs a semantic search across the agent's corpus of knowledge
|
|
14
|
+
#
|
|
15
|
+
# @param request_options [Hash]
|
|
16
|
+
# @param params [Apologist::Corpus::Types::CorpusSearchRequest]
|
|
17
|
+
# @option request_options [String] :base_url
|
|
18
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
19
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
20
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
21
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
# client.corpus.search_corpus(query: "query")
|
|
25
|
+
#
|
|
26
|
+
# @return [Apologist::Corpus::Types::SearchCorpusResponse]
|
|
27
|
+
def search_corpus(request_options: {}, **params)
|
|
28
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
29
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
30
|
+
base_url: request_options[:base_url],
|
|
31
|
+
method: "POST",
|
|
32
|
+
path: "corpus/search",
|
|
33
|
+
body: Apologist::Corpus::Types::CorpusSearchRequest.new(params).to_h,
|
|
34
|
+
request_options: request_options
|
|
35
|
+
)
|
|
36
|
+
begin
|
|
37
|
+
response = @client.send(request)
|
|
38
|
+
rescue Net::HTTPRequestTimeout
|
|
39
|
+
raise Apologist::Errors::TimeoutError
|
|
40
|
+
end
|
|
41
|
+
code = response.code.to_i
|
|
42
|
+
if code.between?(200, 299)
|
|
43
|
+
Apologist::Corpus::Types::SearchCorpusResponse.load(response.body)
|
|
44
|
+
else
|
|
45
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
46
|
+
raise error_class.new(response.body, code: code)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Records that a user viewed a specific corpus item
|
|
51
|
+
#
|
|
52
|
+
# @param request_options [Hash]
|
|
53
|
+
# @param params [Apologist::Corpus::Types::ViewRequest]
|
|
54
|
+
# @option request_options [String] :base_url
|
|
55
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
56
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
57
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
58
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
59
|
+
# @option params [String] :model
|
|
60
|
+
# @option params [String] :id
|
|
61
|
+
#
|
|
62
|
+
# @example
|
|
63
|
+
# client.corpus.log_corpus_view(
|
|
64
|
+
# model: "model",
|
|
65
|
+
# id: "id",
|
|
66
|
+
# prompt_id: "prompt_id"
|
|
67
|
+
# )
|
|
68
|
+
#
|
|
69
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
70
|
+
def log_corpus_view(request_options: {}, **params)
|
|
71
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
72
|
+
request_data = Apologist::Corpus::Types::ViewRequest.new(params).to_h
|
|
73
|
+
non_body_param_names = %w[model id]
|
|
74
|
+
body = request_data.except(*non_body_param_names)
|
|
75
|
+
|
|
76
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
77
|
+
base_url: request_options[:base_url],
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: "corpus/#{URI.encode_uri_component(params[:model].to_s)}/#{URI.encode_uri_component(params[:id].to_s)}/view",
|
|
80
|
+
body: body,
|
|
81
|
+
request_options: request_options
|
|
82
|
+
)
|
|
83
|
+
begin
|
|
84
|
+
response = @client.send(request)
|
|
85
|
+
rescue Net::HTTPRequestTimeout
|
|
86
|
+
raise Apologist::Errors::TimeoutError
|
|
87
|
+
end
|
|
88
|
+
code = response.code.to_i
|
|
89
|
+
if code.between?(200, 299)
|
|
90
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
91
|
+
else
|
|
92
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
93
|
+
raise error_class.new(response.body, code: code)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Records that a corpus item was shown to a user
|
|
98
|
+
#
|
|
99
|
+
# @param request_options [Hash]
|
|
100
|
+
# @param params [Apologist::Corpus::Types::ImpressionRequest]
|
|
101
|
+
# @option request_options [String] :base_url
|
|
102
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
103
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
104
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
105
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
106
|
+
# @option params [String] :model
|
|
107
|
+
# @option params [String] :id
|
|
108
|
+
#
|
|
109
|
+
# @example
|
|
110
|
+
# client.corpus.log_corpus_impression(
|
|
111
|
+
# model: "model",
|
|
112
|
+
# id: "id",
|
|
113
|
+
# prompt_id: "prompt_id"
|
|
114
|
+
# )
|
|
115
|
+
#
|
|
116
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
117
|
+
def log_corpus_impression(request_options: {}, **params)
|
|
118
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
119
|
+
request_data = Apologist::Corpus::Types::ImpressionRequest.new(params).to_h
|
|
120
|
+
non_body_param_names = %w[model id]
|
|
121
|
+
body = request_data.except(*non_body_param_names)
|
|
122
|
+
|
|
123
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
124
|
+
base_url: request_options[:base_url],
|
|
125
|
+
method: "POST",
|
|
126
|
+
path: "corpus/#{URI.encode_uri_component(params[:model].to_s)}/#{URI.encode_uri_component(params[:id].to_s)}/impression",
|
|
127
|
+
body: body,
|
|
128
|
+
request_options: request_options
|
|
129
|
+
)
|
|
130
|
+
begin
|
|
131
|
+
response = @client.send(request)
|
|
132
|
+
rescue Net::HTTPRequestTimeout
|
|
133
|
+
raise Apologist::Errors::TimeoutError
|
|
134
|
+
end
|
|
135
|
+
code = response.code.to_i
|
|
136
|
+
if code.between?(200, 299)
|
|
137
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
138
|
+
else
|
|
139
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
140
|
+
raise error_class.new(response.body, code: code)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Records a referral for a corpus item and, when a `url` is supplied, issues a 302 redirect to it. Without a
|
|
145
|
+
# `url`, responds with a success message. Requires either the search API entitlement or a same-origin request.
|
|
146
|
+
#
|
|
147
|
+
# @param request_options [Hash]
|
|
148
|
+
# @param params [Hash]
|
|
149
|
+
# @option request_options [String] :base_url
|
|
150
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
151
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
152
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
153
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
154
|
+
# @option params [String] :model
|
|
155
|
+
# @option params [String] :id
|
|
156
|
+
# @option params [String] :prompt_id
|
|
157
|
+
# @option params [String, nil] :user_id
|
|
158
|
+
# @option params [String, nil] :url
|
|
159
|
+
#
|
|
160
|
+
# @example
|
|
161
|
+
# client.corpus.log_corpus_referral_redirect(
|
|
162
|
+
# model: "model",
|
|
163
|
+
# id: "id",
|
|
164
|
+
# prompt_id: "prompt_id"
|
|
165
|
+
# )
|
|
166
|
+
#
|
|
167
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
168
|
+
def log_corpus_referral_redirect(request_options: {}, **params)
|
|
169
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
170
|
+
query_params = {}
|
|
171
|
+
query_params["prompt_id"] = params[:prompt_id] if params.key?(:prompt_id)
|
|
172
|
+
query_params["user_id"] = params[:user_id] if params.key?(:user_id)
|
|
173
|
+
query_params["url"] = params[:url] if params.key?(:url)
|
|
174
|
+
|
|
175
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
176
|
+
base_url: request_options[:base_url],
|
|
177
|
+
method: "GET",
|
|
178
|
+
path: "corpus/#{URI.encode_uri_component(params[:model].to_s)}/#{URI.encode_uri_component(params[:id].to_s)}/referral",
|
|
179
|
+
query: query_params,
|
|
180
|
+
request_options: request_options
|
|
181
|
+
)
|
|
182
|
+
begin
|
|
183
|
+
response = @client.send(request)
|
|
184
|
+
rescue Net::HTTPRequestTimeout
|
|
185
|
+
raise Apologist::Errors::TimeoutError
|
|
186
|
+
end
|
|
187
|
+
code = response.code.to_i
|
|
188
|
+
if code.between?(200, 299)
|
|
189
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
190
|
+
else
|
|
191
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
192
|
+
raise error_class.new(response.body, code: code)
|
|
193
|
+
end
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Records that a user was referred to a corpus item
|
|
197
|
+
#
|
|
198
|
+
# @param request_options [Hash]
|
|
199
|
+
# @param params [Apologist::Corpus::Types::ReferralRequest]
|
|
200
|
+
# @option request_options [String] :base_url
|
|
201
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
202
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
203
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
204
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
205
|
+
# @option params [String] :model
|
|
206
|
+
# @option params [String] :id
|
|
207
|
+
#
|
|
208
|
+
# @example
|
|
209
|
+
# client.corpus.log_corpus_referral(
|
|
210
|
+
# model: "model",
|
|
211
|
+
# id: "id",
|
|
212
|
+
# prompt_id: "prompt_id"
|
|
213
|
+
# )
|
|
214
|
+
#
|
|
215
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
216
|
+
def log_corpus_referral(request_options: {}, **params)
|
|
217
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
218
|
+
request_data = Apologist::Corpus::Types::ReferralRequest.new(params).to_h
|
|
219
|
+
non_body_param_names = %w[model id]
|
|
220
|
+
body = request_data.except(*non_body_param_names)
|
|
221
|
+
|
|
222
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
223
|
+
base_url: request_options[:base_url],
|
|
224
|
+
method: "POST",
|
|
225
|
+
path: "corpus/#{URI.encode_uri_component(params[:model].to_s)}/#{URI.encode_uri_component(params[:id].to_s)}/referral",
|
|
226
|
+
body: body,
|
|
227
|
+
request_options: request_options
|
|
228
|
+
)
|
|
229
|
+
begin
|
|
230
|
+
response = @client.send(request)
|
|
231
|
+
rescue Net::HTTPRequestTimeout
|
|
232
|
+
raise Apologist::Errors::TimeoutError
|
|
233
|
+
end
|
|
234
|
+
code = response.code.to_i
|
|
235
|
+
if code.between?(200, 299)
|
|
236
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
237
|
+
else
|
|
238
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
239
|
+
raise error_class.new(response.body, code: code)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
end
|
|
243
|
+
end
|
|
244
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class CorpusSearchRequest < Internal::Types::Model
|
|
7
|
+
field :query, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :prompt_id, -> { String }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :limit, -> { Integer }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :filters, -> { Apologist::Corpus::Types::CorpusSearchRequestFilters }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class CorpusSearchRequestFilters < Internal::Types::Model
|
|
7
|
+
field :model, -> { String }, optional: true, nullable: false
|
|
8
|
+
|
|
9
|
+
field :ids, -> { Internal::Types::Array[Integer] }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :types, -> { Internal::Types::Array[String] }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :languages, -> { Internal::Types::Array[String] }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :collection_ids, -> { Internal::Types::Array[Integer] }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :contributor_ids, -> { Internal::Types::Array[Integer] }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :category_ids, -> { Internal::Types::Array[Integer] }, optional: true, nullable: false
|
|
20
|
+
|
|
21
|
+
field :classification_ids, -> { Internal::Types::Array[Integer] }, optional: true, nullable: false
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class ImpressionRequest < Internal::Types::Model
|
|
7
|
+
field :model, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :prompt_id, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class LogCorpusReferralRedirectRequest < Internal::Types::Model
|
|
7
|
+
field :model, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :prompt_id, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :url, -> { String }, optional: true, nullable: false
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class ReferralRequest < Internal::Types::Model
|
|
7
|
+
field :model, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :prompt_id, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class SearchCorpusResponse < Internal::Types::Model
|
|
7
|
+
field :results, -> { Internal::Types::Array[Internal::Types::Hash[String, Object]] }, optional: true, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Corpus
|
|
5
|
+
module Types
|
|
6
|
+
class ViewRequest < Internal::Types::Model
|
|
7
|
+
field :model, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
10
|
+
|
|
11
|
+
field :prompt_id, -> { String }, optional: false, nullable: false
|
|
12
|
+
|
|
13
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module CtAs
|
|
5
|
+
class Client
|
|
6
|
+
# @param client [Apologist::Internal::Http::RawClient]
|
|
7
|
+
#
|
|
8
|
+
# @return [void]
|
|
9
|
+
def initialize(client:)
|
|
10
|
+
@client = client
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Finds matching CTAs based on conversation context, user, session, device, or messages
|
|
14
|
+
#
|
|
15
|
+
# @param request_options [Hash]
|
|
16
|
+
# @param params [Apologist::Types::CtaMatchRequest]
|
|
17
|
+
# @option request_options [String] :base_url
|
|
18
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
19
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
20
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
21
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
22
|
+
#
|
|
23
|
+
# @example
|
|
24
|
+
# client.ct_as.match_ctas(request: {
|
|
25
|
+
# key: "value"
|
|
26
|
+
# })
|
|
27
|
+
#
|
|
28
|
+
# @return [Apologist::CtAs::Types::MatchCtasResponse]
|
|
29
|
+
def match_ctas(request_options: {}, **params)
|
|
30
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
31
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
32
|
+
base_url: request_options[:base_url],
|
|
33
|
+
method: "POST",
|
|
34
|
+
path: "ctas/match",
|
|
35
|
+
body: Apologist::Types::CtaMatchRequest.new(params).to_h,
|
|
36
|
+
request_options: request_options
|
|
37
|
+
)
|
|
38
|
+
begin
|
|
39
|
+
response = @client.send(request)
|
|
40
|
+
rescue Net::HTTPRequestTimeout
|
|
41
|
+
raise Apologist::Errors::TimeoutError
|
|
42
|
+
end
|
|
43
|
+
code = response.code.to_i
|
|
44
|
+
if code.between?(200, 299)
|
|
45
|
+
Apologist::CtAs::Types::MatchCtasResponse.load(response.body)
|
|
46
|
+
else
|
|
47
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
48
|
+
raise error_class.new(response.body, code: code)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Records that a user clicked on a specific CTA
|
|
53
|
+
#
|
|
54
|
+
# @param request_options [Hash]
|
|
55
|
+
# @param params [Apologist::CtAs::Types::CtaClickRequest]
|
|
56
|
+
# @option request_options [String] :base_url
|
|
57
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
58
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
59
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
60
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
61
|
+
# @option params [String] :id
|
|
62
|
+
#
|
|
63
|
+
# @example
|
|
64
|
+
# client.ct_as.log_cta_click(
|
|
65
|
+
# id: "id",
|
|
66
|
+
# prompt_id: "prompt_id"
|
|
67
|
+
# )
|
|
68
|
+
#
|
|
69
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
70
|
+
def log_cta_click(request_options: {}, **params)
|
|
71
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
72
|
+
request_data = Apologist::CtAs::Types::CtaClickRequest.new(params).to_h
|
|
73
|
+
non_body_param_names = %w[id]
|
|
74
|
+
body = request_data.except(*non_body_param_names)
|
|
75
|
+
|
|
76
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
77
|
+
base_url: request_options[:base_url],
|
|
78
|
+
method: "POST",
|
|
79
|
+
path: "ctas/#{URI.encode_uri_component(params[:id].to_s)}/click",
|
|
80
|
+
body: body,
|
|
81
|
+
request_options: request_options
|
|
82
|
+
)
|
|
83
|
+
begin
|
|
84
|
+
response = @client.send(request)
|
|
85
|
+
rescue Net::HTTPRequestTimeout
|
|
86
|
+
raise Apologist::Errors::TimeoutError
|
|
87
|
+
end
|
|
88
|
+
code = response.code.to_i
|
|
89
|
+
if code.between?(200, 299)
|
|
90
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
91
|
+
else
|
|
92
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
93
|
+
raise error_class.new(response.body, code: code)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module CtAs
|
|
5
|
+
module Types
|
|
6
|
+
class CtaClickRequest < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :prompt_id, -> { String }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module CtAs
|
|
5
|
+
module Types
|
|
6
|
+
class MatchCtasResponse < Internal::Types::Model
|
|
7
|
+
field :ctas, -> { Internal::Types::Array[Internal::Types::Hash[String, Object]] }, optional: true, nullable: false
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Errors
|
|
5
|
+
class ClientError < ResponseError
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
class UnauthorizedError < ClientError
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
class ForbiddenError < ClientError
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class NotFoundError < ClientError
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Errors
|
|
5
|
+
class ResponseError < ApiError
|
|
6
|
+
attr_reader :code
|
|
7
|
+
|
|
8
|
+
def initialize(msg, code:)
|
|
9
|
+
@code = code
|
|
10
|
+
super(msg)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def inspect
|
|
14
|
+
"#<#{self.class.name} @code=#{code} @body=#{message}>"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Returns the most appropriate error class for the given code.
|
|
18
|
+
#
|
|
19
|
+
# @return [Class]
|
|
20
|
+
def self.subclass_for_code(code)
|
|
21
|
+
case code
|
|
22
|
+
when 300..399
|
|
23
|
+
RedirectError
|
|
24
|
+
when 401
|
|
25
|
+
UnauthorizedError
|
|
26
|
+
when 403
|
|
27
|
+
ForbiddenError
|
|
28
|
+
when 404
|
|
29
|
+
NotFoundError
|
|
30
|
+
when 400..499
|
|
31
|
+
ClientError
|
|
32
|
+
when 503
|
|
33
|
+
ServiceUnavailableError
|
|
34
|
+
when 500..599
|
|
35
|
+
ServerError
|
|
36
|
+
else
|
|
37
|
+
ResponseError
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|