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,345 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
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
|
+
# Returns a paginated list of chat completions (prompts) for the agent, with applied tags expanded as { id, name }
|
|
14
|
+
# and share metadata.
|
|
15
|
+
#
|
|
16
|
+
# @param request_options [Hash]
|
|
17
|
+
# @param params [Hash]
|
|
18
|
+
# @option request_options [String] :base_url
|
|
19
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
20
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
21
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
22
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
23
|
+
# @option params [Integer, nil] :page
|
|
24
|
+
# @option params [Integer, nil] :per_page
|
|
25
|
+
# @option params [String, nil] :agent_id
|
|
26
|
+
# @option params [String, nil] :channel_id
|
|
27
|
+
# @option params [String, nil] :bible_id
|
|
28
|
+
# @option params [String, nil] :cached
|
|
29
|
+
# @option params [String, nil] :client
|
|
30
|
+
# @option params [String, nil] :config_id
|
|
31
|
+
# @option params [String, nil] :conversation_id
|
|
32
|
+
# @option params [String, nil] :device_id
|
|
33
|
+
# @option params [String, nil] :flagged
|
|
34
|
+
# @option params [String, nil] :favorited
|
|
35
|
+
# @option params [String, nil] :language
|
|
36
|
+
# @option params [String, nil] :liked
|
|
37
|
+
# @option params [String, nil] :session_id
|
|
38
|
+
# @option params [String, nil] :user_id
|
|
39
|
+
# @option params [String, nil] :min_timestamp
|
|
40
|
+
# @option params [String, nil] :max_timestamp
|
|
41
|
+
#
|
|
42
|
+
# @example
|
|
43
|
+
# client.chat.list_chat_completions
|
|
44
|
+
#
|
|
45
|
+
# @return [Apologist::Chat::Types::ListChatCompletionsResponse]
|
|
46
|
+
def list_chat_completions(request_options: {}, **params)
|
|
47
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
48
|
+
query_params = {}
|
|
49
|
+
query_params["page"] = params[:page] if params.key?(:page)
|
|
50
|
+
query_params["per_page"] = params[:per_page] if params.key?(:per_page)
|
|
51
|
+
query_params["agent_id"] = params[:agent_id] if params.key?(:agent_id)
|
|
52
|
+
query_params["channel_id"] = params[:channel_id] if params.key?(:channel_id)
|
|
53
|
+
query_params["bible_id"] = params[:bible_id] if params.key?(:bible_id)
|
|
54
|
+
query_params["cached"] = params[:cached] if params.key?(:cached)
|
|
55
|
+
query_params["client"] = params[:client] if params.key?(:client)
|
|
56
|
+
query_params["config_id"] = params[:config_id] if params.key?(:config_id)
|
|
57
|
+
query_params["conversation_id"] = params[:conversation_id] if params.key?(:conversation_id)
|
|
58
|
+
query_params["device_id"] = params[:device_id] if params.key?(:device_id)
|
|
59
|
+
query_params["flagged"] = params[:flagged] if params.key?(:flagged)
|
|
60
|
+
query_params["favorited"] = params[:favorited] if params.key?(:favorited)
|
|
61
|
+
query_params["language"] = params[:language] if params.key?(:language)
|
|
62
|
+
query_params["liked"] = params[:liked] if params.key?(:liked)
|
|
63
|
+
query_params["session_id"] = params[:session_id] if params.key?(:session_id)
|
|
64
|
+
query_params["user_id"] = params[:user_id] if params.key?(:user_id)
|
|
65
|
+
query_params["min_timestamp"] = params[:min_timestamp] if params.key?(:min_timestamp)
|
|
66
|
+
query_params["max_timestamp"] = params[:max_timestamp] if params.key?(:max_timestamp)
|
|
67
|
+
|
|
68
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
69
|
+
base_url: request_options[:base_url],
|
|
70
|
+
method: "GET",
|
|
71
|
+
path: "chat/completions",
|
|
72
|
+
query: query_params,
|
|
73
|
+
request_options: request_options
|
|
74
|
+
)
|
|
75
|
+
begin
|
|
76
|
+
response = @client.send(request)
|
|
77
|
+
rescue Net::HTTPRequestTimeout
|
|
78
|
+
raise Apologist::Errors::TimeoutError
|
|
79
|
+
end
|
|
80
|
+
code = response.code.to_i
|
|
81
|
+
if code.between?(200, 299)
|
|
82
|
+
Apologist::Chat::Types::ListChatCompletionsResponse.load(response.body)
|
|
83
|
+
else
|
|
84
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
85
|
+
raise error_class.new(response.body, code: code)
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Creates a chat completion using the agent's configured model. Supports both streaming and non-streaming
|
|
90
|
+
# responses.
|
|
91
|
+
#
|
|
92
|
+
# @param request_options [Hash]
|
|
93
|
+
# @param params [Apologist::Types::ChatCompletionRequest]
|
|
94
|
+
# @option request_options [String] :base_url
|
|
95
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
96
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
97
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
98
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
99
|
+
#
|
|
100
|
+
# @example
|
|
101
|
+
# client.chat.create_chat_completion(request: {
|
|
102
|
+
# key: "value"
|
|
103
|
+
# })
|
|
104
|
+
#
|
|
105
|
+
# @return [Apologist::Types::ChatCompletionResponse]
|
|
106
|
+
def create_chat_completion(request_options: {}, **params)
|
|
107
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
108
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
109
|
+
base_url: request_options[:base_url],
|
|
110
|
+
method: "POST",
|
|
111
|
+
path: "chat/completions",
|
|
112
|
+
body: Apologist::Types::ChatCompletionRequest.new(params).to_h,
|
|
113
|
+
request_options: request_options
|
|
114
|
+
)
|
|
115
|
+
begin
|
|
116
|
+
response = @client.send(request)
|
|
117
|
+
rescue Net::HTTPRequestTimeout
|
|
118
|
+
raise Apologist::Errors::TimeoutError
|
|
119
|
+
end
|
|
120
|
+
code = response.code.to_i
|
|
121
|
+
if code.between?(200, 299)
|
|
122
|
+
Apologist::Types::ChatCompletionResponse.load(response.body)
|
|
123
|
+
else
|
|
124
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
125
|
+
raise error_class.new(response.body, code: code)
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Updates the like status of a specific chat completion
|
|
130
|
+
#
|
|
131
|
+
# @param request_options [Hash]
|
|
132
|
+
# @param params [Apologist::Chat::Types::LikeRequest]
|
|
133
|
+
# @option request_options [String] :base_url
|
|
134
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
135
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
136
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
137
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
138
|
+
# @option params [String] :id
|
|
139
|
+
#
|
|
140
|
+
# @example
|
|
141
|
+
# client.chat.like_completion(
|
|
142
|
+
# id: "id",
|
|
143
|
+
# liked: true
|
|
144
|
+
# )
|
|
145
|
+
#
|
|
146
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
147
|
+
def like_completion(request_options: {}, **params)
|
|
148
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
149
|
+
request_data = Apologist::Chat::Types::LikeRequest.new(params).to_h
|
|
150
|
+
non_body_param_names = %w[id]
|
|
151
|
+
body = request_data.except(*non_body_param_names)
|
|
152
|
+
|
|
153
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
154
|
+
base_url: request_options[:base_url],
|
|
155
|
+
method: "POST",
|
|
156
|
+
path: "chat/completions/#{URI.encode_uri_component(params[:id].to_s)}/like",
|
|
157
|
+
body: body,
|
|
158
|
+
request_options: request_options
|
|
159
|
+
)
|
|
160
|
+
begin
|
|
161
|
+
response = @client.send(request)
|
|
162
|
+
rescue Net::HTTPRequestTimeout
|
|
163
|
+
raise Apologist::Errors::TimeoutError
|
|
164
|
+
end
|
|
165
|
+
code = response.code.to_i
|
|
166
|
+
if code.between?(200, 299)
|
|
167
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
168
|
+
else
|
|
169
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
170
|
+
raise error_class.new(response.body, code: code)
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
# Updates the flagged status of a specific chat completion
|
|
175
|
+
#
|
|
176
|
+
# @param request_options [Hash]
|
|
177
|
+
# @param params [Apologist::Chat::Types::FlagRequest]
|
|
178
|
+
# @option request_options [String] :base_url
|
|
179
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
180
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
181
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
182
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
183
|
+
# @option params [String] :id
|
|
184
|
+
#
|
|
185
|
+
# @example
|
|
186
|
+
# client.chat.flag_completion(
|
|
187
|
+
# id: "id",
|
|
188
|
+
# flagged: true
|
|
189
|
+
# )
|
|
190
|
+
#
|
|
191
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
192
|
+
def flag_completion(request_options: {}, **params)
|
|
193
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
194
|
+
request_data = Apologist::Chat::Types::FlagRequest.new(params).to_h
|
|
195
|
+
non_body_param_names = %w[id]
|
|
196
|
+
body = request_data.except(*non_body_param_names)
|
|
197
|
+
|
|
198
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
199
|
+
base_url: request_options[:base_url],
|
|
200
|
+
method: "POST",
|
|
201
|
+
path: "chat/completions/#{URI.encode_uri_component(params[:id].to_s)}/flag",
|
|
202
|
+
body: body,
|
|
203
|
+
request_options: request_options
|
|
204
|
+
)
|
|
205
|
+
begin
|
|
206
|
+
response = @client.send(request)
|
|
207
|
+
rescue Net::HTTPRequestTimeout
|
|
208
|
+
raise Apologist::Errors::TimeoutError
|
|
209
|
+
end
|
|
210
|
+
code = response.code.to_i
|
|
211
|
+
if code.between?(200, 299)
|
|
212
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
213
|
+
else
|
|
214
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
215
|
+
raise error_class.new(response.body, code: code)
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# Adds user feedback to a specific chat completion
|
|
220
|
+
#
|
|
221
|
+
# @param request_options [Hash]
|
|
222
|
+
# @param params [Apologist::Chat::Types::FeedbackRequest]
|
|
223
|
+
# @option request_options [String] :base_url
|
|
224
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
225
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
226
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
227
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
228
|
+
# @option params [String] :id
|
|
229
|
+
#
|
|
230
|
+
# @example
|
|
231
|
+
# client.chat.feedback_completion(
|
|
232
|
+
# id: "id",
|
|
233
|
+
# feedback: "feedback"
|
|
234
|
+
# )
|
|
235
|
+
#
|
|
236
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
237
|
+
def feedback_completion(request_options: {}, **params)
|
|
238
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
239
|
+
request_data = Apologist::Chat::Types::FeedbackRequest.new(params).to_h
|
|
240
|
+
non_body_param_names = %w[id]
|
|
241
|
+
body = request_data.except(*non_body_param_names)
|
|
242
|
+
|
|
243
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
244
|
+
base_url: request_options[:base_url],
|
|
245
|
+
method: "POST",
|
|
246
|
+
path: "chat/completions/#{URI.encode_uri_component(params[:id].to_s)}/feedback",
|
|
247
|
+
body: body,
|
|
248
|
+
request_options: request_options
|
|
249
|
+
)
|
|
250
|
+
begin
|
|
251
|
+
response = @client.send(request)
|
|
252
|
+
rescue Net::HTTPRequestTimeout
|
|
253
|
+
raise Apologist::Errors::TimeoutError
|
|
254
|
+
end
|
|
255
|
+
code = response.code.to_i
|
|
256
|
+
if code.between?(200, 299)
|
|
257
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
258
|
+
else
|
|
259
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
260
|
+
raise error_class.new(response.body, code: code)
|
|
261
|
+
end
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
# Creates a share record for a specific chat completion
|
|
265
|
+
#
|
|
266
|
+
# @param request_options [Hash]
|
|
267
|
+
# @param params [Apologist::Chat::Types::ShareRequest]
|
|
268
|
+
# @option request_options [String] :base_url
|
|
269
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
270
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
271
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
272
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
273
|
+
# @option params [String] :id
|
|
274
|
+
#
|
|
275
|
+
# @example
|
|
276
|
+
# client.chat.share_completion(id: "id")
|
|
277
|
+
#
|
|
278
|
+
# @return [Apologist::Types::SuccessResponse]
|
|
279
|
+
def share_completion(request_options: {}, **params)
|
|
280
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
281
|
+
request_data = Apologist::Chat::Types::ShareRequest.new(params).to_h
|
|
282
|
+
non_body_param_names = %w[id]
|
|
283
|
+
body = request_data.except(*non_body_param_names)
|
|
284
|
+
|
|
285
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
286
|
+
base_url: request_options[:base_url],
|
|
287
|
+
method: "POST",
|
|
288
|
+
path: "chat/completions/#{URI.encode_uri_component(params[:id].to_s)}/share",
|
|
289
|
+
body: body,
|
|
290
|
+
request_options: request_options
|
|
291
|
+
)
|
|
292
|
+
begin
|
|
293
|
+
response = @client.send(request)
|
|
294
|
+
rescue Net::HTTPRequestTimeout
|
|
295
|
+
raise Apologist::Errors::TimeoutError
|
|
296
|
+
end
|
|
297
|
+
code = response.code.to_i
|
|
298
|
+
if code.between?(200, 299)
|
|
299
|
+
Apologist::Types::SuccessResponse.load(response.body)
|
|
300
|
+
else
|
|
301
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
302
|
+
raise error_class.new(response.body, code: code)
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# Returns a single chat completion (prompt) by numeric id or UUID, including applied tags, guardrail/cta metadata,
|
|
307
|
+
# share metadata, and automation results.
|
|
308
|
+
#
|
|
309
|
+
# @param request_options [Hash]
|
|
310
|
+
# @param params [Hash]
|
|
311
|
+
# @option request_options [String] :base_url
|
|
312
|
+
# @option request_options [Hash{String => Object}] :additional_headers
|
|
313
|
+
# @option request_options [Hash{String => Object}] :additional_query_parameters
|
|
314
|
+
# @option request_options [Hash{String => Object}] :additional_body_parameters
|
|
315
|
+
# @option request_options [Integer] :timeout_in_seconds
|
|
316
|
+
# @option params [String] :id
|
|
317
|
+
#
|
|
318
|
+
# @example
|
|
319
|
+
# client.chat.get_chat_completion(id: "id")
|
|
320
|
+
#
|
|
321
|
+
# @return [Apologist::Chat::Types::GetChatCompletionResponse]
|
|
322
|
+
def get_chat_completion(request_options: {}, **params)
|
|
323
|
+
params = Apologist::Internal::Types::Utils.normalize_keys(params)
|
|
324
|
+
request = Apologist::Internal::JSON::Request.new(
|
|
325
|
+
base_url: request_options[:base_url],
|
|
326
|
+
method: "GET",
|
|
327
|
+
path: "chat/completions/#{URI.encode_uri_component(params[:id].to_s)}",
|
|
328
|
+
request_options: request_options
|
|
329
|
+
)
|
|
330
|
+
begin
|
|
331
|
+
response = @client.send(request)
|
|
332
|
+
rescue Net::HTTPRequestTimeout
|
|
333
|
+
raise Apologist::Errors::TimeoutError
|
|
334
|
+
end
|
|
335
|
+
code = response.code.to_i
|
|
336
|
+
if code.between?(200, 299)
|
|
337
|
+
Apologist::Chat::Types::GetChatCompletionResponse.load(response.body)
|
|
338
|
+
else
|
|
339
|
+
error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
|
|
340
|
+
raise error_class.new(response.body, code: code)
|
|
341
|
+
end
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
345
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class FeedbackRequest < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :feedback, -> { String }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class FlagRequest < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :flagged, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class LikeRequest < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :liked, -> { Internal::Types::Boolean }, optional: false, nullable: false
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class ListChatCompletionsRequest < Internal::Types::Model
|
|
7
|
+
field :page, -> { Integer }, optional: true, nullable: false
|
|
8
|
+
|
|
9
|
+
field :per_page, -> { Integer }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :agent_id, -> { String }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :channel_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
|
|
15
|
+
field :bible_id, -> { String }, optional: true, nullable: false
|
|
16
|
+
|
|
17
|
+
field :cached, -> { String }, optional: true, nullable: false
|
|
18
|
+
|
|
19
|
+
field :client, -> { String }, optional: true, nullable: false
|
|
20
|
+
|
|
21
|
+
field :config_id, -> { String }, optional: true, nullable: false
|
|
22
|
+
|
|
23
|
+
field :conversation_id, -> { String }, optional: true, nullable: false
|
|
24
|
+
|
|
25
|
+
field :device_id, -> { String }, optional: true, nullable: false
|
|
26
|
+
|
|
27
|
+
field :flagged, -> { String }, optional: true, nullable: false
|
|
28
|
+
|
|
29
|
+
field :favorited, -> { String }, optional: true, nullable: false
|
|
30
|
+
|
|
31
|
+
field :language, -> { String }, optional: true, nullable: false
|
|
32
|
+
|
|
33
|
+
field :liked, -> { String }, optional: true, nullable: false
|
|
34
|
+
|
|
35
|
+
field :session_id, -> { String }, optional: true, nullable: false
|
|
36
|
+
|
|
37
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
38
|
+
|
|
39
|
+
field :min_timestamp, -> { String }, optional: true, nullable: false
|
|
40
|
+
|
|
41
|
+
field :max_timestamp, -> { String }, optional: true, nullable: false
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class ListChatCompletionsResponse < Internal::Types::Model
|
|
7
|
+
field :data, -> { Internal::Types::Array[Internal::Types::Hash[String, Object]] }, optional: true, nullable: false
|
|
8
|
+
|
|
9
|
+
field :total, -> { Integer }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :page, -> { Integer }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :per_page, -> { Integer }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
module Chat
|
|
5
|
+
module Types
|
|
6
|
+
class ShareRequest < Internal::Types::Model
|
|
7
|
+
field :id, -> { String }, optional: false, nullable: false
|
|
8
|
+
|
|
9
|
+
field :conversation_id, -> { String }, optional: true, nullable: false
|
|
10
|
+
|
|
11
|
+
field :session_id, -> { String }, optional: true, nullable: false
|
|
12
|
+
|
|
13
|
+
field :user_id, -> { String }, optional: true, nullable: false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Apologist
|
|
4
|
+
class AgentClient
|
|
5
|
+
# @param api_key [String]
|
|
6
|
+
# @param base_url [String, nil]
|
|
7
|
+
# @param domain [String, nil]
|
|
8
|
+
# @param max_retries [Integer]
|
|
9
|
+
#
|
|
10
|
+
# @return [void]
|
|
11
|
+
def initialize(api_key:, base_url: nil, domain: nil, max_retries: 2)
|
|
12
|
+
unless domain.nil?
|
|
13
|
+
domain_value = domain.nil? ? "your-agent-domain.com" : domain
|
|
14
|
+
environment_url_templates = {
|
|
15
|
+
Apologist::Environment::DEFAULT => "https://#{domain_value}/api/v1"
|
|
16
|
+
}
|
|
17
|
+
base_url = base_url.nil? ? "https://#{domain_value}/api/v1" : environment_url_templates.fetch(base_url, base_url)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
@raw_client = Apologist::Internal::Http::RawClient.new(
|
|
21
|
+
base_url: base_url || Apologist::Environment::DEFAULT,
|
|
22
|
+
headers: {
|
|
23
|
+
"User-Agent" => "apologist/0.0.5",
|
|
24
|
+
"X-Fern-Language" => "Ruby",
|
|
25
|
+
"x-api-key" => api_key.to_s
|
|
26
|
+
},
|
|
27
|
+
max_retries: max_retries
|
|
28
|
+
)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [Apologist::Chat::Client]
|
|
32
|
+
def chat
|
|
33
|
+
@chat ||= Apologist::Chat::Client.new(client: @raw_client)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# @return [Apologist::Corpus::Client]
|
|
37
|
+
def corpus
|
|
38
|
+
@corpus ||= Apologist::Corpus::Client.new(client: @raw_client)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# @return [Apologist::Evaluators::Client]
|
|
42
|
+
def evaluators
|
|
43
|
+
@evaluators ||= Apologist::Evaluators::Client.new(client: @raw_client)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @return [Apologist::CtAs::Client]
|
|
47
|
+
def ct_as
|
|
48
|
+
@ct_as ||= Apologist::CtAs::Client.new(client: @raw_client)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# @return [Apologist::Users::Client]
|
|
52
|
+
def users
|
|
53
|
+
@users ||= Apologist::Users::Client.new(client: @raw_client)
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# @return [Apologist::Benchmarks::Client]
|
|
57
|
+
def benchmarks
|
|
58
|
+
@benchmarks ||= Apologist::Benchmarks::Client.new(client: @raw_client)
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [Apologist::Channels::Client]
|
|
62
|
+
def channels
|
|
63
|
+
@channels ||= Apologist::Channels::Client.new(client: @raw_client)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# @return [Apologist::Shares::Client]
|
|
67
|
+
def shares
|
|
68
|
+
@shares ||= Apologist::Shares::Client.new(client: @raw_client)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|