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.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.fern/metadata.json +13 -0
  3. data/.fernignore +2 -0
  4. data/.rubocop.yml +108 -0
  5. data/CONTRIBUTING.md +120 -0
  6. data/README.md +169 -0
  7. data/Rakefile +20 -0
  8. data/custom.gemspec.rb +17 -0
  9. data/lib/Apologist/benchmarks/client.rb +160 -0
  10. data/lib/Apologist/benchmarks/types/benchmark_run_request.rb +39 -0
  11. data/lib/Apologist/benchmarks/types/benchmark_run_request_content.rb +16 -0
  12. data/lib/Apologist/benchmarks/types/benchmark_run_request_reasoning_effort.rb +15 -0
  13. data/lib/Apologist/benchmarks/types/benchmark_run_request_verbosity.rb +16 -0
  14. data/lib/Apologist/benchmarks/types/get_benchmark_run_request.rb +13 -0
  15. data/lib/Apologist/benchmarks/types/get_benchmark_run_response.rb +11 -0
  16. data/lib/Apologist/benchmarks/types/list_benchmark_runs_request.rb +33 -0
  17. data/lib/Apologist/benchmarks/types/list_benchmark_runs_response.rb +17 -0
  18. data/lib/Apologist/channels/client.rb +319 -0
  19. data/lib/Apologist/channels/types/get_discord_channel_status_request.rb +11 -0
  20. data/lib/Apologist/channels/types/get_discord_channel_status_response.rb +15 -0
  21. data/lib/Apologist/channels/types/get_instagram_privacy_policy_request.rb +11 -0
  22. data/lib/Apologist/channels/types/receive_discord_interaction_request.rb +17 -0
  23. data/lib/Apologist/channels/types/receive_facebook_message_request.rb +13 -0
  24. data/lib/Apologist/channels/types/receive_telegram_update_request.rb +13 -0
  25. data/lib/Apologist/channels/types/receive_twilio_message_request.rb +15 -0
  26. data/lib/Apologist/channels/types/verify_facebook_webhook_request.rb +17 -0
  27. data/lib/Apologist/channels/types/verify_facebook_webhook_request_hub_mode.rb +13 -0
  28. data/lib/Apologist/chat/client.rb +345 -0
  29. data/lib/Apologist/chat/types/feedback_request.rb +13 -0
  30. data/lib/Apologist/chat/types/flag_request.rb +13 -0
  31. data/lib/Apologist/chat/types/get_chat_completion_request.rb +11 -0
  32. data/lib/Apologist/chat/types/get_chat_completion_response.rb +11 -0
  33. data/lib/Apologist/chat/types/like_request.rb +13 -0
  34. data/lib/Apologist/chat/types/list_chat_completions_request.rb +45 -0
  35. data/lib/Apologist/chat/types/list_chat_completions_response.rb +17 -0
  36. data/lib/Apologist/chat/types/share_request.rb +17 -0
  37. data/lib/Apologist/client.rb +71 -0
  38. data/lib/Apologist/corpus/client.rb +244 -0
  39. data/lib/Apologist/corpus/types/corpus_search_request.rb +17 -0
  40. data/lib/Apologist/corpus/types/corpus_search_request_filters.rb +25 -0
  41. data/lib/Apologist/corpus/types/impression_request.rb +17 -0
  42. data/lib/Apologist/corpus/types/log_corpus_referral_redirect_request.rb +19 -0
  43. data/lib/Apologist/corpus/types/referral_request.rb +17 -0
  44. data/lib/Apologist/corpus/types/search_corpus_response.rb +11 -0
  45. data/lib/Apologist/corpus/types/view_request.rb +17 -0
  46. data/lib/Apologist/ct_as/client.rb +98 -0
  47. data/lib/Apologist/ct_as/types/cta_click_request.rb +13 -0
  48. data/lib/Apologist/ct_as/types/match_ctas_response.rb +11 -0
  49. data/lib/Apologist/environment.rb +7 -0
  50. data/lib/Apologist/errors/api_error.rb +8 -0
  51. data/lib/Apologist/errors/client_error.rb +17 -0
  52. data/lib/Apologist/errors/redirect_error.rb +8 -0
  53. data/lib/Apologist/errors/response_error.rb +42 -0
  54. data/lib/Apologist/errors/server_error.rb +11 -0
  55. data/lib/Apologist/errors/timeout_error.rb +8 -0
  56. data/lib/Apologist/evaluators/client.rb +164 -0
  57. data/lib/Apologist/evaluators/types/evaluate_content_response.rb +11 -0
  58. data/lib/Apologist/evaluators/types/evaluator_request.rb +31 -0
  59. data/lib/Apologist/evaluators/types/evaluator_request_content.rb +15 -0
  60. data/lib/Apologist/evaluators/types/evaluator_request_reasoning_effort.rb +15 -0
  61. data/lib/Apologist/evaluators/types/evaluator_request_verbosity.rb +16 -0
  62. data/lib/Apologist/evaluators/types/get_evaluation_request.rb +13 -0
  63. data/lib/Apologist/evaluators/types/get_evaluation_response.rb +11 -0
  64. data/lib/Apologist/evaluators/types/list_evaluations_request.rb +35 -0
  65. data/lib/Apologist/evaluators/types/list_evaluations_response.rb +17 -0
  66. data/lib/Apologist/internal/errors/constraint_error.rb +10 -0
  67. data/lib/Apologist/internal/errors/type_error.rb +10 -0
  68. data/lib/Apologist/internal/http/base_request.rb +51 -0
  69. data/lib/Apologist/internal/http/raw_client.rb +252 -0
  70. data/lib/Apologist/internal/iterators/cursor_item_iterator.rb +28 -0
  71. data/lib/Apologist/internal/iterators/cursor_page_iterator.rb +63 -0
  72. data/lib/Apologist/internal/iterators/item_iterator.rb +65 -0
  73. data/lib/Apologist/internal/iterators/offset_item_iterator.rb +30 -0
  74. data/lib/Apologist/internal/iterators/offset_page_iterator.rb +103 -0
  75. data/lib/Apologist/internal/json/request.rb +41 -0
  76. data/lib/Apologist/internal/json/serializable.rb +25 -0
  77. data/lib/Apologist/internal/multipart/multipart_encoder.rb +141 -0
  78. data/lib/Apologist/internal/multipart/multipart_form_data.rb +78 -0
  79. data/lib/Apologist/internal/multipart/multipart_form_data_part.rb +51 -0
  80. data/lib/Apologist/internal/multipart/multipart_request.rb +40 -0
  81. data/lib/Apologist/internal/types/array.rb +47 -0
  82. data/lib/Apologist/internal/types/boolean.rb +34 -0
  83. data/lib/Apologist/internal/types/enum.rb +56 -0
  84. data/lib/Apologist/internal/types/hash.rb +36 -0
  85. data/lib/Apologist/internal/types/model/field.rb +38 -0
  86. data/lib/Apologist/internal/types/model.rb +208 -0
  87. data/lib/Apologist/internal/types/type.rb +35 -0
  88. data/lib/Apologist/internal/types/union.rb +161 -0
  89. data/lib/Apologist/internal/types/unknown.rb +15 -0
  90. data/lib/Apologist/internal/types/utils.rb +116 -0
  91. data/lib/Apologist/internal/url_encoded/request.rb +41 -0
  92. data/lib/Apologist/shares/client.rb +52 -0
  93. data/lib/Apologist/shares/types/get_shared_messages_request.rb +11 -0
  94. data/lib/Apologist/shares/types/get_shared_messages_response.rb +11 -0
  95. data/lib/Apologist/types/chat_completion_request.rb +11 -0
  96. data/lib/Apologist/types/chat_completion_request_logprobs.rb +13 -0
  97. data/lib/Apologist/types/chat_completion_request_metadata.rb +29 -0
  98. data/lib/Apologist/types/chat_completion_request_reasoning_effort.rb +13 -0
  99. data/lib/Apologist/types/chat_completion_request_response_format.rb +11 -0
  100. data/lib/Apologist/types/chat_completion_request_response_format_json_schema.rb +17 -0
  101. data/lib/Apologist/types/chat_completion_request_response_format_type.rb +15 -0
  102. data/lib/Apologist/types/chat_completion_request_tool_choice.rb +13 -0
  103. data/lib/Apologist/types/chat_completion_request_tool_choice_zero.rb +13 -0
  104. data/lib/Apologist/types/chat_completion_request_verbosity.rb +14 -0
  105. data/lib/Apologist/types/chat_completion_response.rb +21 -0
  106. data/lib/Apologist/types/chat_completion_response_choices_item.rb +15 -0
  107. data/lib/Apologist/types/chat_completion_response_usage.rb +13 -0
  108. data/lib/Apologist/types/chat_message.rb +11 -0
  109. data/lib/Apologist/types/chat_message_role.rb +13 -0
  110. data/lib/Apologist/types/cta_match_request.rb +11 -0
  111. data/lib/Apologist/types/error.rb +11 -0
  112. data/lib/Apologist/types/success_response.rb +11 -0
  113. data/lib/Apologist/types/tag_ref.rb +11 -0
  114. data/lib/Apologist/types/user.rb +23 -0
  115. data/lib/Apologist/types/user_flag.rb +18 -0
  116. data/lib/Apologist/types/webhook_agent_ref.rb +11 -0
  117. data/lib/Apologist/types/webhook_cta.rb +13 -0
  118. data/lib/Apologist/types/webhook_evaluation.rb +14 -0
  119. data/lib/Apologist/types/webhook_event_info.rb +13 -0
  120. data/lib/Apologist/types/webhook_event_info_key.rb +28 -0
  121. data/lib/Apologist/types/webhook_named_ref.rb +11 -0
  122. data/lib/Apologist/types/webhook_notification_ref.rb +12 -0
  123. data/lib/Apologist/types/webhook_payload.rb +30 -0
  124. data/lib/Apologist/users/client.rb +193 -0
  125. data/lib/Apologist/users/types/get_user_request.rb +11 -0
  126. data/lib/Apologist/users/types/get_user_response.rb +11 -0
  127. data/lib/Apologist/users/types/list_user_flags_request.rb +13 -0
  128. data/lib/Apologist/users/types/list_user_flags_response.rb +17 -0
  129. data/lib/Apologist/users/types/list_users_request.rb +23 -0
  130. data/lib/Apologist/users/types/list_users_response.rb +17 -0
  131. data/lib/Apologist/users/types/update_user_response.rb +11 -0
  132. data/lib/Apologist/users/types/user_update_request.rb +17 -0
  133. data/lib/Apologist/users/types/user_update_request_tags_item.rb +15 -0
  134. data/lib/Apologist/version.rb +5 -0
  135. data/lib/Apologist.rb +131 -0
  136. data/reference.md +2927 -0
  137. metadata +183 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: eea4d5fd424e0680b422036a9fed82c0b81387bf6afd4dc22b70277ab2d2eeb9
4
+ data.tar.gz: ed6d8332ad50a4057390d5cf7ffdca9b9109ad1d738c0e726e27661394749a9a
5
+ SHA512:
6
+ metadata.gz: 2098c0cb04ef3bf967d13fd2bbd9d8581107db8c368a9ef72621a753039870a12227569e29437a56525e874fcfed00d1339120a96538c81f8de09dd219e00205
7
+ data.tar.gz: 8b988a293d1fccdeee7c7ce392f1d67018e81dc962127e8af6b6f9d34c92a4016eec4c99a659281d19503dc3b3e7413cdff1371c0fb6d3537d152ae655e6f672
@@ -0,0 +1,13 @@
1
+ {
2
+ "cliVersion": "5.72.1",
3
+ "generatorName": "fernapi/fern-ruby-sdk",
4
+ "generatorVersion": "1.20.2",
5
+ "generatorConfig": {
6
+ "moduleName": "Apologist",
7
+ "clientModuleName": "AgentClient"
8
+ },
9
+ "originGitCommit": "48763009ddb15e043da173498c3cc160c5c5dc45",
10
+ "originGitCommitIsDirty": true,
11
+ "invokedBy": "manual",
12
+ "sdkVersion": "0.0.5"
13
+ }
data/.fernignore ADDED
@@ -0,0 +1,2 @@
1
+ custom.gemspec.rb
2
+ .rubocop.yml
data/.rubocop.yml ADDED
@@ -0,0 +1,108 @@
1
+ plugins:
2
+ - rubocop-minitest
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.3
6
+ NewCops: enable
7
+
8
+ Style/StringLiterals:
9
+ EnforcedStyle: double_quotes
10
+
11
+ Style/StringLiteralsInInterpolation:
12
+ EnforcedStyle: double_quotes
13
+
14
+ Style/AccessModifierDeclarations:
15
+ Enabled: false
16
+
17
+ Lint/ConstantDefinitionInBlock:
18
+ Enabled: false
19
+
20
+ Metrics/AbcSize:
21
+ Enabled: false
22
+
23
+ Metrics/BlockLength:
24
+ Enabled: false
25
+
26
+ Metrics/ClassLength:
27
+ Enabled: false
28
+
29
+ Metrics/MethodLength:
30
+ Enabled: false
31
+
32
+ Metrics/ParameterLists:
33
+ Enabled: false
34
+
35
+ Metrics/PerceivedComplexity:
36
+ Enabled: false
37
+
38
+ Metrics/CyclomaticComplexity:
39
+ Enabled: false
40
+
41
+ Metrics/ModuleLength:
42
+ Enabled: false
43
+
44
+ Layout/LineLength:
45
+ Enabled: false
46
+
47
+ # Fern generates lib/Apologist.rb to match the module/gem entrypoint name.
48
+ Naming/FileName:
49
+ Exclude:
50
+ - "lib/Apologist.rb"
51
+
52
+ Naming/VariableNumber:
53
+ EnforcedStyle: normalcase
54
+ Severity: warning
55
+
56
+ Style/Documentation:
57
+ Enabled: false
58
+
59
+ Style/Lambda:
60
+ EnforcedStyle: literal
61
+
62
+ Minitest/MultipleAssertions:
63
+ Enabled: false
64
+
65
+ Minitest/UselessAssertion:
66
+ Enabled: false
67
+
68
+ # Dynamic snippets are code samples for documentation, not standalone Ruby files.
69
+ Style/FrozenStringLiteralComment:
70
+ Exclude:
71
+ - "dynamic-snippets/**/*"
72
+
73
+ # Indent hash elements 2 spaces from the start of the enclosing line rather than
74
+ # aligning with the preceding paren or bracket. Generated code nests hashes inside
75
+ # arrays and method calls; the "consistent" style is more readable there.
76
+ Layout/FirstHashElementIndentation:
77
+ EnforcedStyle: consistent
78
+ Exclude:
79
+ - "dynamic-snippets/**/*"
80
+
81
+ # Match Layout/FirstHashElementIndentation: indent the first argument 2 spaces
82
+ # from the start of the method call's line, regardless of parenthesis position.
83
+ # Dynamic snippets are code samples, not standalone Ruby files; exclude them to
84
+ # keep this config symmetric with Layout/FirstHashElementIndentation above.
85
+ Layout/FirstArgumentIndentation:
86
+ EnforcedStyle: consistent
87
+ Exclude:
88
+ - "dynamic-snippets/**/*"
89
+
90
+ # The generator emits non-idiomatic class names (e.g. Get_With_Query, JSON_)
91
+ # derived from IR type names whose wire form contains underscores or digits.
92
+ # Rubocop never auto-corrected these (naming cops have no autocorrecter), so
93
+ # disabling the cop keeps CI green without changing customer output. Fixing at
94
+ # source would rename public types across every existing SDK and therefore
95
+ # requires a ruby-v2 major-version bump with a generator migration.
96
+ Naming/ClassAndModuleCamelCase:
97
+ Enabled: false
98
+
99
+ # Integer literals are emitted unformatted (e.g. 1000000, not 1_000_000).
100
+ # Rubocop has an autocorrecter for this cop, but the only caller of integer
101
+ # emission is the dynamic-snippets path, which feeds customer-facing surfaces:
102
+ # (1) snippet markdown in reference docs, (2) dynamic-snippets/*.rb sample
103
+ # files. Neither is rubocop-gated (markdown isn't Ruby, dynamic-snippets/**/*
104
+ # is excluded above), so formatting integers there would change docs/dashboard
105
+ # output without any rubocop benefit. Disabling the cop keeps integers raw
106
+ # everywhere and avoids customer-visible diffs.
107
+ Style/NumericLiterals:
108
+ Enabled: false
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,120 @@
1
+ # Contributing
2
+
3
+ Thanks for your interest in contributing to this SDK! This document provides guidelines for contributing to the project.
4
+
5
+ ## Getting Started
6
+
7
+ ### Prerequisites
8
+
9
+ - Ruby 3.0+
10
+ - Bundler
11
+
12
+ ### Installation
13
+
14
+ Install the project dependencies:
15
+
16
+ ```bash
17
+ bundle install
18
+ ```
19
+
20
+ ### Building
21
+
22
+ Build the gem:
23
+
24
+ ```bash
25
+ gem build *.gemspec
26
+ ```
27
+
28
+ ### Testing
29
+
30
+ Run the test suite:
31
+
32
+ ```bash
33
+ bundle exec rspec
34
+ ```
35
+
36
+ ### Linting and Formatting
37
+
38
+ Check code style:
39
+
40
+ ```bash
41
+ bundle exec rubocop
42
+ ```
43
+
44
+ Fix code style issues:
45
+
46
+ ```bash
47
+ bundle exec rubocop -a
48
+ ```
49
+
50
+ ## About Generated Code
51
+
52
+ **Important**: Most files in this SDK are automatically generated by [Fern](https://buildwithfern.com) from the API definition. Direct modifications to generated files will be overwritten the next time the SDK is generated.
53
+
54
+ ### Generated Files
55
+
56
+ The following directories contain generated code:
57
+ - `lib/` - API client classes and types
58
+ - Most Ruby files in the project
59
+
60
+ ### How to Customize
61
+
62
+ If you need to customize the SDK, you have two options:
63
+
64
+ #### Option 1: Use `.fernignore`
65
+
66
+ For custom code that should persist across SDK regenerations:
67
+
68
+ 1. Create a `.fernignore` file in the project root
69
+ 2. Add file patterns for files you want to preserve (similar to `.gitignore` syntax)
70
+ 3. Add your custom code to those files
71
+
72
+ Files listed in `.fernignore` will not be overwritten when the SDK is regenerated.
73
+
74
+ For more information, see the [Fern documentation on custom code](https://buildwithfern.com/learn/sdks/overview/custom-code).
75
+
76
+ #### Option 2: Contribute to the Generator
77
+
78
+ If you want to change how code is generated for all users of this SDK:
79
+
80
+ 1. The Ruby SDK generator lives in the [Fern repository](https://github.com/fern-api/fern)
81
+ 2. Generator code is located at `generators/ruby-v2/`
82
+ 3. Follow the [Fern contributing guidelines](https://github.com/fern-api/fern/blob/main/CONTRIBUTING.md)
83
+ 4. Submit a pull request with your changes to the generator
84
+
85
+ This approach is best for:
86
+ - Bug fixes in generated code
87
+ - New features that would benefit all users
88
+ - Improvements to code generation patterns
89
+
90
+ ## Making Changes
91
+
92
+ ### Workflow
93
+
94
+ 1. Create a new branch for your changes
95
+ 2. Make your modifications
96
+ 3. Run tests to ensure nothing breaks: `bundle exec rspec`
97
+ 4. Run linting: `bundle exec rubocop`
98
+ 5. Build the gem: `gem build *.gemspec`
99
+ 6. Commit your changes with a clear commit message
100
+ 7. Push your branch and create a pull request
101
+
102
+ ### Commit Messages
103
+
104
+ Write clear, descriptive commit messages that explain what changed and why.
105
+
106
+ ### Code Style
107
+
108
+ This project uses RuboCop for code formatting. Run `bundle exec rubocop` before committing to ensure your code meets the project's style guidelines.
109
+
110
+ ## Questions or Issues?
111
+
112
+ If you have questions or run into issues:
113
+
114
+ 1. Check the [Fern documentation](https://buildwithfern.com)
115
+ 2. Search existing [GitHub issues](https://github.com/fern-api/fern/issues)
116
+ 3. Open a new issue if your question hasn't been addressed
117
+
118
+ ## License
119
+
120
+ By contributing to this project, you agree that your contributions will be licensed under the same license as the project.
data/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # ApologistAi Ruby Library
2
+
3
+ [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=ApologistAi%2FRuby)
4
+
5
+ The ApologistAi Ruby library provides convenient access to the ApologistAi APIs from Ruby.
6
+
7
+ ## Table of Contents
8
+
9
+ - [Reference](#reference)
10
+ - [Usage](#usage)
11
+ - [Environments](#environments)
12
+ - [Errors](#errors)
13
+ - [Advanced](#advanced)
14
+ - [Retries](#retries)
15
+ - [Timeouts](#timeouts)
16
+ - [Additional Headers](#additional-headers)
17
+ - [Additional Query Parameters](#additional-query-parameters)
18
+ - [Contributing](#contributing)
19
+
20
+ ## Reference
21
+
22
+ A full reference for this library is available [here](./reference.md).
23
+
24
+ ## Usage
25
+
26
+ Instantiate and use the client with the following:
27
+
28
+ ```ruby
29
+ require "apologist"
30
+
31
+ client = Apologist::AgentClient.new(api_key: "<value>")
32
+
33
+ client.chat.create_chat_completion(request: {
34
+ key: "value"
35
+ })
36
+ ```
37
+
38
+ ## Environments
39
+
40
+ This SDK allows you to configure different environments or custom URLs for API requests. You can either use the predefined environments or specify your own custom URL.
41
+ ### Environments
42
+ ```ruby
43
+ require "Apologist"
44
+
45
+ Apologist = Apologist::AgentClient.new(
46
+ base_url: Apologist::Environment::DEFAULT
47
+ )
48
+ ```
49
+
50
+ ### Custom URL
51
+ ```ruby
52
+ require "Apologist"
53
+
54
+ client = Apologist::AgentClient.new(
55
+ base_url: "https://example.com"
56
+ )
57
+ ```
58
+
59
+ ## Errors
60
+
61
+ Failed API calls will raise errors that can be rescued from granularly.
62
+
63
+ ```ruby
64
+ require "Apologist"
65
+
66
+ client = Apologist::AgentClient.new(
67
+ base_url: "https://example.com"
68
+ )
69
+
70
+ begin
71
+ result = client.chat.create_chat_completion
72
+ rescue Apologist::Errors::TimeoutError
73
+ puts "API didn't respond before our timeout elapsed"
74
+ rescue Apologist::Errors::ServiceUnavailableError
75
+ puts "API returned status 503, is probably overloaded, try again later"
76
+ rescue Apologist::Errors::ServerError
77
+ puts "API returned some other 5xx status, this is probably a bug"
78
+ rescue Apologist::Errors::ResponseError => e
79
+ puts "API returned an unexpected status other than 5xx: #{e.code} #{e.message}"
80
+ rescue Apologist::Errors::ApiError => e
81
+ puts "Some other error occurred when calling the API: #{e.message}"
82
+ end
83
+ ```
84
+
85
+ ## Advanced
86
+
87
+ ### Retries
88
+
89
+ The SDK is instrumented with automatic retries. A request will be retried as long as the request is deemed
90
+ retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
91
+
92
+ A request is deemed retryable when any of the following HTTP status codes is returned:
93
+
94
+ - [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
95
+ - [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
96
+ - [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) (Internal Server Error)
97
+
98
+ The `retryStatusCodes` configuration controls which [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#server_error_responses) status codes are retried:
99
+
100
+ - `legacy` (default): Retries `408`, `429`, `500`, `502`, `503`, `504`, `521`, `522`, `524`
101
+ - `recommended`: Retries `408`, `429`, `502`, `503`, `504` only (excludes `500 Internal Server Error` to avoid retrying non-idempotent failures)
102
+
103
+ Use the `max_retries` option to configure this behavior.
104
+
105
+ ```ruby
106
+ require "Apologist"
107
+
108
+ client = Apologist::AgentClient.new(
109
+ base_url: "https://example.com",
110
+ max_retries: 3 # Configure max retries (default is 2)
111
+ )
112
+ ```
113
+
114
+ ### Timeouts
115
+
116
+ The SDK defaults to a 60 second timeout. Use the `timeout` option to configure this behavior.
117
+
118
+ ```ruby
119
+ require "Apologist"
120
+
121
+ response = client.chat.create_chat_completion(
122
+ ...,
123
+ timeout: 30 # 30 second timeout
124
+ )
125
+ ```
126
+
127
+ ### Additional Headers
128
+
129
+ If you would like to send additional headers as part of the request, use the `additional_headers` request option.
130
+
131
+ ```ruby
132
+ require "Apologist"
133
+
134
+ response = client.chat.create_chat_completion(
135
+ ...,
136
+ request_options: {
137
+ additional_headers: {
138
+ "X-Custom-Header" => "custom-value"
139
+ }
140
+ }
141
+ )
142
+ ```
143
+
144
+ ### Additional Query Parameters
145
+
146
+ If you would like to send additional query parameters as part of the request, use the `additional_query_parameters` request option.
147
+
148
+ ```ruby
149
+ require "Apologist"
150
+
151
+ response = client.chat.create_chat_completion(
152
+ ...,
153
+ request_options: {
154
+ additional_query_parameters: {
155
+ "custom_param" => "custom-value"
156
+ }
157
+ }
158
+ )
159
+ ```
160
+
161
+ ## Contributing
162
+
163
+ While we value open-source contributions to this SDK, this library is generated programmatically.
164
+ Additions made directly to this library would have to be moved over to our generation code,
165
+ otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
166
+ a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
167
+ an issue first to discuss with us!
168
+
169
+ On the other hand, contributions to the README are always very welcome!
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "minitest/test_task"
5
+
6
+ Minitest::TestTask.create
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[test]
13
+
14
+ task lint: %i[rubocop]
15
+
16
+ # Run only the custom test file
17
+ Minitest::TestTask.create(:customtest) do |t|
18
+ t.libs << "test"
19
+ t.test_globs = ["test/custom.test.rb"]
20
+ end
data/custom.gemspec.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Custom gemspec configuration file
4
+ # This file is automatically loaded by the main gemspec file. The 'spec' variable is available
5
+ # in this context from the main gemspec file. You can modify this file to add custom metadata,
6
+ # dependencies, or other gemspec configurations. If you do make changes to this file, you will
7
+ # need to add it to the .fernignore file to prevent your changes from being overwritten.
8
+
9
+ def add_custom_gemspec_data(spec)
10
+ spec.authors = ["Apologist"]
11
+ spec.email = ["support@apologist.ai"]
12
+ spec.homepage = "https://github.com/apologist-project/apg-sdk-ruby"
13
+ spec.license = "MIT"
14
+ spec.metadata["homepage_uri"] = "https://docs.apologist.ai"
15
+ spec.metadata["source_code_uri"] = "https://github.com/apologist-project/apg-sdk-ruby"
16
+ spec.metadata["documentation_uri"] = "https://docs.apologist.ai"
17
+ end
@@ -0,0 +1,160 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apologist
4
+ module Benchmarks
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 runs for a benchmark, scoped to the requesting agent. Each run carries nested
14
+ # evaluators, questions, and a flat evaluations array.
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 [String] :id
24
+ # @option params [Integer, nil] :page
25
+ # @option params [Integer, nil] :per_page
26
+ # @option params [String, nil] :min_timestamp
27
+ # @option params [String, nil] :max_timestamp
28
+ # @option params [String, nil] :min_duration
29
+ # @option params [String, nil] :max_duration
30
+ # @option params [String, nil] :min_score
31
+ # @option params [String, nil] :max_score
32
+ # @option params [String, nil] :passed
33
+ # @option params [String, nil] :min_responses
34
+ # @option params [String, nil] :max_responses
35
+ #
36
+ # @example
37
+ # client.benchmarks.list_benchmark_runs(id: "id")
38
+ #
39
+ # @return [Apologist::Benchmarks::Types::ListBenchmarkRunsResponse]
40
+ def list_benchmark_runs(request_options: {}, **params)
41
+ params = Apologist::Internal::Types::Utils.normalize_keys(params)
42
+ query_params = {}
43
+ query_params["page"] = params[:page] if params.key?(:page)
44
+ query_params["per_page"] = params[:per_page] if params.key?(:per_page)
45
+ query_params["min_timestamp"] = params[:min_timestamp] if params.key?(:min_timestamp)
46
+ query_params["max_timestamp"] = params[:max_timestamp] if params.key?(:max_timestamp)
47
+ query_params["min_duration"] = params[:min_duration] if params.key?(:min_duration)
48
+ query_params["max_duration"] = params[:max_duration] if params.key?(:max_duration)
49
+ query_params["min_score"] = params[:min_score] if params.key?(:min_score)
50
+ query_params["max_score"] = params[:max_score] if params.key?(:max_score)
51
+ query_params["passed"] = params[:passed] if params.key?(:passed)
52
+ query_params["min_responses"] = params[:min_responses] if params.key?(:min_responses)
53
+ query_params["max_responses"] = params[:max_responses] if params.key?(:max_responses)
54
+
55
+ request = Apologist::Internal::JSON::Request.new(
56
+ base_url: request_options[:base_url],
57
+ method: "GET",
58
+ path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs",
59
+ query: query_params,
60
+ request_options: request_options
61
+ )
62
+ begin
63
+ response = @client.send(request)
64
+ rescue Net::HTTPRequestTimeout
65
+ raise Apologist::Errors::TimeoutError
66
+ end
67
+ code = response.code.to_i
68
+ if code.between?(200, 299)
69
+ Apologist::Benchmarks::Types::ListBenchmarkRunsResponse.load(response.body)
70
+ else
71
+ error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
72
+ raise error_class.new(response.body, code: code)
73
+ end
74
+ end
75
+
76
+ # Executes a benchmark run and returns the aggregated result with nested evaluators, questions, and a flat
77
+ # evaluations array.
78
+ #
79
+ # @param request_options [Hash]
80
+ # @param params [Apologist::Benchmarks::Types::BenchmarkRunRequest]
81
+ # @option request_options [String] :base_url
82
+ # @option request_options [Hash{String => Object}] :additional_headers
83
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
84
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
85
+ # @option request_options [Integer] :timeout_in_seconds
86
+ # @option params [String] :id
87
+ #
88
+ # @example
89
+ # client.benchmarks.run_benchmark(id: "id")
90
+ #
91
+ # @return [Hash[String, Object]]
92
+ def run_benchmark(request_options: {}, **params)
93
+ params = Apologist::Internal::Types::Utils.normalize_keys(params)
94
+ request_data = Apologist::Benchmarks::Types::BenchmarkRunRequest.new(params).to_h
95
+ non_body_param_names = %w[id]
96
+ body = request_data.except(*non_body_param_names)
97
+
98
+ request = Apologist::Internal::JSON::Request.new(
99
+ base_url: request_options[:base_url],
100
+ method: "POST",
101
+ path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs",
102
+ body: body,
103
+ request_options: request_options
104
+ )
105
+ begin
106
+ response = @client.send(request)
107
+ rescue Net::HTTPRequestTimeout
108
+ raise Apologist::Errors::TimeoutError
109
+ end
110
+ code = response.code.to_i
111
+ return if code.between?(200, 299)
112
+
113
+ error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
114
+ raise error_class.new(response.body, code: code)
115
+ end
116
+
117
+ # Returns a single benchmark run by id or UUID, scoped to the requesting agent, including nested evaluators,
118
+ # questions, and evaluations.
119
+ #
120
+ # @param request_options [Hash]
121
+ # @param params [Hash]
122
+ # @option request_options [String] :base_url
123
+ # @option request_options [Hash{String => Object}] :additional_headers
124
+ # @option request_options [Hash{String => Object}] :additional_query_parameters
125
+ # @option request_options [Hash{String => Object}] :additional_body_parameters
126
+ # @option request_options [Integer] :timeout_in_seconds
127
+ # @option params [String] :id
128
+ # @option params [String] :run_id
129
+ #
130
+ # @example
131
+ # client.benchmarks.get_benchmark_run(
132
+ # id: "id",
133
+ # run_id: "runId"
134
+ # )
135
+ #
136
+ # @return [Apologist::Benchmarks::Types::GetBenchmarkRunResponse]
137
+ def get_benchmark_run(request_options: {}, **params)
138
+ params = Apologist::Internal::Types::Utils.normalize_keys(params)
139
+ request = Apologist::Internal::JSON::Request.new(
140
+ base_url: request_options[:base_url],
141
+ method: "GET",
142
+ path: "benchmarks/#{URI.encode_uri_component(params[:id].to_s)}/runs/#{URI.encode_uri_component(params[:run_id].to_s)}",
143
+ request_options: request_options
144
+ )
145
+ begin
146
+ response = @client.send(request)
147
+ rescue Net::HTTPRequestTimeout
148
+ raise Apologist::Errors::TimeoutError
149
+ end
150
+ code = response.code.to_i
151
+ if code.between?(200, 299)
152
+ Apologist::Benchmarks::Types::GetBenchmarkRunResponse.load(response.body)
153
+ else
154
+ error_class = Apologist::Errors::ResponseError.subclass_for_code(code)
155
+ raise error_class.new(response.body, code: code)
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apologist
4
+ module Benchmarks
5
+ module Types
6
+ class BenchmarkRunRequest < Internal::Types::Model
7
+ field :id, -> { String }, optional: false, nullable: false
8
+
9
+ field :content, -> { Apologist::Benchmarks::Types::BenchmarkRunRequestContent }, optional: true, nullable: false
10
+
11
+ field :completion_id, -> { String }, optional: true, nullable: false
12
+
13
+ field :source_id, -> { Integer }, optional: true, nullable: false
14
+
15
+ field :model, -> { String }, optional: true, nullable: false
16
+
17
+ field :num_responses, -> { Integer }, optional: true, nullable: false
18
+
19
+ field :use_question_variants, -> { Internal::Types::Boolean }, optional: true, nullable: false
20
+
21
+ field :reasoning_effort, -> { Apologist::Benchmarks::Types::BenchmarkRunRequestReasoningEffort }, optional: true, nullable: false
22
+
23
+ field :verbosity, -> { Apologist::Benchmarks::Types::BenchmarkRunRequestVerbosity }, optional: true, nullable: false
24
+
25
+ field :score_threshold, -> { Integer }, optional: true, nullable: false
26
+
27
+ field :value_threshold, -> { Integer }, optional: true, nullable: false
28
+
29
+ field :temperature, -> { Integer }, optional: true, nullable: false
30
+
31
+ field :top_p, -> { Integer }, optional: true, nullable: false
32
+
33
+ field :frequency_penalty, -> { Integer }, optional: true, nullable: false
34
+
35
+ field :presence_penalty, -> { Integer }, optional: true, nullable: false
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Apologist
4
+ module Benchmarks
5
+ module Types
6
+ # Content to evaluate. Required when `source_id` is supplied.
7
+ class BenchmarkRunRequestContent < Internal::Types::Model
8
+ extend Apologist::Internal::Types::Union
9
+
10
+ member -> { String }
11
+
12
+ member -> { Internal::Types::Array[Object] }
13
+ end
14
+ end
15
+ end
16
+ end