openlayer 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (230) hide show
  1. checksums.yaml +4 -4
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +280 -39
  5. data/SECURITY.md +27 -0
  6. data/lib/openlayer/client.rb +64 -59
  7. data/lib/openlayer/errors.rb +228 -0
  8. data/lib/openlayer/file_part.rb +58 -0
  9. data/lib/openlayer/internal/transport/base_client.rb +567 -0
  10. data/lib/openlayer/internal/transport/pooled_net_requester.rb +198 -0
  11. data/lib/openlayer/internal/type/array_of.rb +168 -0
  12. data/lib/openlayer/internal/type/base_model.rb +531 -0
  13. data/lib/openlayer/internal/type/base_page.rb +55 -0
  14. data/lib/openlayer/internal/type/boolean.rb +77 -0
  15. data/lib/openlayer/internal/type/converter.rb +327 -0
  16. data/lib/openlayer/internal/type/enum.rb +131 -0
  17. data/lib/openlayer/internal/type/file_input.rb +111 -0
  18. data/lib/openlayer/internal/type/hash_of.rb +188 -0
  19. data/lib/openlayer/internal/type/request_parameters.rb +42 -0
  20. data/lib/openlayer/internal/type/union.rb +237 -0
  21. data/lib/openlayer/internal/type/unknown.rb +81 -0
  22. data/lib/openlayer/internal/util.rb +915 -0
  23. data/lib/openlayer/internal.rb +20 -0
  24. data/lib/openlayer/models/commit_retrieve_params.rb +14 -0
  25. data/lib/openlayer/models/commit_retrieve_response.rb +275 -0
  26. data/lib/openlayer/models/commits/test_result_list_params.rb +91 -0
  27. data/lib/openlayer/models/commits/test_result_list_response.rb +566 -0
  28. data/lib/openlayer/models/inference_pipeline_delete_params.rb +14 -0
  29. data/lib/openlayer/models/inference_pipeline_retrieve_params.rb +33 -0
  30. data/lib/openlayer/models/inference_pipeline_retrieve_response.rb +605 -0
  31. data/lib/openlayer/models/inference_pipeline_update_params.rb +42 -0
  32. data/lib/openlayer/models/inference_pipeline_update_response.rb +605 -0
  33. data/lib/openlayer/models/inference_pipelines/data_stream_params.rb +463 -0
  34. data/lib/openlayer/models/inference_pipelines/data_stream_response.rb +28 -0
  35. data/lib/openlayer/models/inference_pipelines/row_update_params.rb +90 -0
  36. data/lib/openlayer/models/inference_pipelines/row_update_response.rb +28 -0
  37. data/lib/openlayer/models/inference_pipelines/test_result_list_params.rb +83 -0
  38. data/lib/openlayer/models/inference_pipelines/test_result_list_response.rb +568 -0
  39. data/lib/openlayer/models/project_create_params.rb +51 -0
  40. data/lib/openlayer/models/project_create_response.rb +262 -0
  41. data/lib/openlayer/models/project_list_params.rb +59 -0
  42. data/lib/openlayer/models/project_list_response.rb +274 -0
  43. data/lib/openlayer/models/projects/commit_create_params.rb +61 -0
  44. data/lib/openlayer/models/projects/commit_create_response.rb +277 -0
  45. data/lib/openlayer/models/projects/commit_list_params.rb +32 -0
  46. data/lib/openlayer/models/projects/commit_list_response.rb +288 -0
  47. data/lib/openlayer/models/projects/inference_pipeline_create_params.rb +229 -0
  48. data/lib/openlayer/models/projects/inference_pipeline_create_response.rb +612 -0
  49. data/lib/openlayer/models/projects/inference_pipeline_list_params.rb +40 -0
  50. data/lib/openlayer/models/projects/inference_pipeline_list_response.rb +623 -0
  51. data/lib/openlayer/models/projects/test_create_params.rb +367 -0
  52. data/lib/openlayer/models/projects/test_create_response.rb +438 -0
  53. data/lib/openlayer/models/projects/test_list_params.rb +91 -0
  54. data/lib/openlayer/models/projects/test_list_response.rb +452 -0
  55. data/lib/openlayer/models/projects/test_update_params.rb +262 -0
  56. data/lib/openlayer/models/projects/test_update_response.rb +24 -0
  57. data/lib/openlayer/models/storage/presigned_url_create_params.rb +24 -0
  58. data/lib/openlayer/models/storage/presigned_url_create_response.rb +35 -0
  59. data/lib/openlayer/models.rb +61 -0
  60. data/lib/openlayer/request_options.rb +77 -0
  61. data/lib/openlayer/resources/commits/test_results.rb +51 -0
  62. data/lib/openlayer/resources/commits.rb +38 -0
  63. data/lib/openlayer/resources/inference_pipelines/data.rb +46 -0
  64. data/lib/openlayer/resources/inference_pipelines/rows.rb +46 -0
  65. data/lib/openlayer/resources/inference_pipelines/test_results.rb +49 -0
  66. data/lib/openlayer/resources/inference_pipelines.rb +101 -0
  67. data/lib/openlayer/resources/projects/commits.rb +72 -0
  68. data/lib/openlayer/resources/projects/inference_pipelines.rb +74 -0
  69. data/lib/openlayer/resources/projects/tests.rb +135 -0
  70. data/lib/openlayer/resources/projects.rb +80 -0
  71. data/lib/openlayer/resources/storage/presigned_url.rb +38 -0
  72. data/lib/openlayer/resources/storage.rb +18 -0
  73. data/lib/openlayer/version.rb +1 -1
  74. data/lib/openlayer.rb +96 -12
  75. data/manifest.yaml +15 -0
  76. data/rbi/openlayer/client.rbi +58 -0
  77. data/rbi/openlayer/errors.rbi +205 -0
  78. data/rbi/openlayer/file_part.rbi +37 -0
  79. data/rbi/openlayer/internal/transport/base_client.rbi +293 -0
  80. data/rbi/openlayer/internal/transport/pooled_net_requester.rbi +79 -0
  81. data/rbi/openlayer/internal/type/array_of.rbi +104 -0
  82. data/rbi/openlayer/internal/type/base_model.rbi +304 -0
  83. data/rbi/openlayer/internal/type/base_page.rbi +42 -0
  84. data/rbi/openlayer/internal/type/boolean.rbi +58 -0
  85. data/rbi/openlayer/internal/type/converter.rbi +216 -0
  86. data/rbi/openlayer/internal/type/enum.rbi +82 -0
  87. data/rbi/openlayer/internal/type/file_input.rbi +59 -0
  88. data/rbi/openlayer/internal/type/hash_of.rbi +104 -0
  89. data/rbi/openlayer/internal/type/request_parameters.rbi +29 -0
  90. data/rbi/openlayer/internal/type/union.rbi +128 -0
  91. data/rbi/openlayer/internal/type/unknown.rbi +58 -0
  92. data/rbi/openlayer/internal/util.rbi +487 -0
  93. data/rbi/openlayer/internal.rbi +18 -0
  94. data/rbi/openlayer/models/commit_retrieve_params.rbi +27 -0
  95. data/rbi/openlayer/models/commit_retrieve_response.rbi +393 -0
  96. data/rbi/openlayer/models/commits/test_result_list_params.rbi +214 -0
  97. data/rbi/openlayer/models/commits/test_result_list_response.rbi +1256 -0
  98. data/rbi/openlayer/models/inference_pipeline_delete_params.rbi +30 -0
  99. data/rbi/openlayer/models/inference_pipeline_retrieve_params.rbi +101 -0
  100. data/rbi/openlayer/models/inference_pipeline_retrieve_response.rbi +1022 -0
  101. data/rbi/openlayer/models/inference_pipeline_update_params.rbi +67 -0
  102. data/rbi/openlayer/models/inference_pipeline_update_response.rbi +1018 -0
  103. data/rbi/openlayer/models/inference_pipelines/data_stream_params.rbi +750 -0
  104. data/rbi/openlayer/models/inference_pipelines/data_stream_response.rbi +73 -0
  105. data/rbi/openlayer/models/inference_pipelines/row_update_params.rbi +153 -0
  106. data/rbi/openlayer/models/inference_pipelines/row_update_response.rbi +73 -0
  107. data/rbi/openlayer/models/inference_pipelines/test_result_list_params.rbi +216 -0
  108. data/rbi/openlayer/models/inference_pipelines/test_result_list_response.rbi +1258 -0
  109. data/rbi/openlayer/models/project_create_params.rbi +99 -0
  110. data/rbi/openlayer/models/project_create_response.rbi +401 -0
  111. data/rbi/openlayer/models/project_list_params.rbi +121 -0
  112. data/rbi/openlayer/models/project_list_response.rbi +442 -0
  113. data/rbi/openlayer/models/projects/commit_create_params.rbi +125 -0
  114. data/rbi/openlayer/models/projects/commit_create_response.rbi +409 -0
  115. data/rbi/openlayer/models/projects/commit_list_params.rbi +62 -0
  116. data/rbi/openlayer/models/projects/commit_list_response.rbi +454 -0
  117. data/rbi/openlayer/models/projects/inference_pipeline_create_params.rbi +560 -0
  118. data/rbi/openlayer/models/projects/inference_pipeline_create_response.rbi +1027 -0
  119. data/rbi/openlayer/models/projects/inference_pipeline_list_params.rbi +73 -0
  120. data/rbi/openlayer/models/projects/inference_pipeline_list_response.rbi +1070 -0
  121. data/rbi/openlayer/models/projects/test_create_params.rbi +940 -0
  122. data/rbi/openlayer/models/projects/test_create_response.rbi +1026 -0
  123. data/rbi/openlayer/models/projects/test_list_params.rbi +165 -0
  124. data/rbi/openlayer/models/projects/test_list_response.rbi +1067 -0
  125. data/rbi/openlayer/models/projects/test_update_params.rbi +699 -0
  126. data/rbi/openlayer/models/projects/test_update_response.rbi +43 -0
  127. data/rbi/openlayer/models/storage/presigned_url_create_params.rbi +45 -0
  128. data/rbi/openlayer/models/storage/presigned_url_create_response.rbi +55 -0
  129. data/rbi/openlayer/models.rbi +26 -0
  130. data/rbi/openlayer/request_options.rbi +59 -0
  131. data/rbi/openlayer/resources/commits/test_results.rbi +45 -0
  132. data/rbi/openlayer/resources/commits.rbi +29 -0
  133. data/rbi/openlayer/resources/inference_pipelines/data.rbi +41 -0
  134. data/rbi/openlayer/resources/inference_pipelines/rows.rbi +40 -0
  135. data/rbi/openlayer/resources/inference_pipelines/test_results.rbi +46 -0
  136. data/rbi/openlayer/resources/inference_pipelines.rbi +79 -0
  137. data/rbi/openlayer/resources/projects/commits.rbi +60 -0
  138. data/rbi/openlayer/resources/projects/inference_pipelines.rbi +69 -0
  139. data/rbi/openlayer/resources/projects/tests.rbi +123 -0
  140. data/rbi/openlayer/resources/projects.rbi +64 -0
  141. data/rbi/openlayer/resources/storage/presigned_url.rbi +28 -0
  142. data/rbi/openlayer/resources/storage.rbi +15 -0
  143. data/rbi/openlayer/version.rbi +5 -0
  144. data/sig/openlayer/client.rbs +32 -0
  145. data/sig/openlayer/errors.rbs +117 -0
  146. data/sig/openlayer/file_part.rbs +21 -0
  147. data/sig/openlayer/internal/transport/base_client.rbs +131 -0
  148. data/sig/openlayer/internal/transport/pooled_net_requester.rbs +45 -0
  149. data/sig/openlayer/internal/type/array_of.rbs +48 -0
  150. data/sig/openlayer/internal/type/base_model.rbs +102 -0
  151. data/sig/openlayer/internal/type/base_page.rbs +24 -0
  152. data/sig/openlayer/internal/type/boolean.rbs +26 -0
  153. data/sig/openlayer/internal/type/converter.rbs +79 -0
  154. data/sig/openlayer/internal/type/enum.rbs +32 -0
  155. data/sig/openlayer/internal/type/file_input.rbs +25 -0
  156. data/sig/openlayer/internal/type/hash_of.rbs +48 -0
  157. data/sig/openlayer/internal/type/request_parameters.rbs +19 -0
  158. data/sig/openlayer/internal/type/union.rbs +52 -0
  159. data/sig/openlayer/internal/type/unknown.rbs +26 -0
  160. data/sig/openlayer/internal/util.rbs +185 -0
  161. data/sig/openlayer/internal.rbs +9 -0
  162. data/sig/openlayer/models/commit_retrieve_params.rbs +15 -0
  163. data/sig/openlayer/models/commit_retrieve_response.rbs +209 -0
  164. data/sig/openlayer/models/commits/test_result_list_params.rbs +91 -0
  165. data/sig/openlayer/models/commits/test_result_list_response.rbs +529 -0
  166. data/sig/openlayer/models/inference_pipeline_delete_params.rbs +15 -0
  167. data/sig/openlayer/models/inference_pipeline_retrieve_params.rbs +41 -0
  168. data/sig/openlayer/models/inference_pipeline_retrieve_response.rbs +493 -0
  169. data/sig/openlayer/models/inference_pipeline_update_params.rbs +34 -0
  170. data/sig/openlayer/models/inference_pipeline_update_response.rbs +493 -0
  171. data/sig/openlayer/models/inference_pipelines/data_stream_params.rbs +386 -0
  172. data/sig/openlayer/models/inference_pipelines/data_stream_response.rbs +32 -0
  173. data/sig/openlayer/models/inference_pipelines/row_update_params.rbs +75 -0
  174. data/sig/openlayer/models/inference_pipelines/row_update_response.rbs +32 -0
  175. data/sig/openlayer/models/inference_pipelines/test_result_list_params.rbs +84 -0
  176. data/sig/openlayer/models/inference_pipelines/test_result_list_response.rbs +529 -0
  177. data/sig/openlayer/models/project_create_params.rbs +53 -0
  178. data/sig/openlayer/models/project_create_response.rbs +210 -0
  179. data/sig/openlayer/models/project_list_params.rbs +68 -0
  180. data/sig/openlayer/models/project_list_response.rbs +225 -0
  181. data/sig/openlayer/models/projects/commit_create_params.rbs +82 -0
  182. data/sig/openlayer/models/projects/commit_create_response.rbs +211 -0
  183. data/sig/openlayer/models/projects/commit_list_params.rbs +34 -0
  184. data/sig/openlayer/models/projects/commit_list_response.rbs +228 -0
  185. data/sig/openlayer/models/projects/inference_pipeline_create_params.rbs +308 -0
  186. data/sig/openlayer/models/projects/inference_pipeline_create_response.rbs +495 -0
  187. data/sig/openlayer/models/projects/inference_pipeline_list_params.rbs +40 -0
  188. data/sig/openlayer/models/projects/inference_pipeline_list_response.rbs +512 -0
  189. data/sig/openlayer/models/projects/test_create_params.rbs +388 -0
  190. data/sig/openlayer/models/projects/test_create_response.rbs +427 -0
  191. data/sig/openlayer/models/projects/test_list_params.rbs +85 -0
  192. data/sig/openlayer/models/projects/test_list_response.rbs +442 -0
  193. data/sig/openlayer/models/projects/test_update_params.rbs +275 -0
  194. data/sig/openlayer/models/projects/test_update_response.rbs +25 -0
  195. data/sig/openlayer/models/storage/presigned_url_create_params.rbs +25 -0
  196. data/sig/openlayer/models/storage/presigned_url_create_response.rbs +22 -0
  197. data/sig/openlayer/models.rbs +21 -0
  198. data/sig/openlayer/request_options.rbs +34 -0
  199. data/sig/openlayer/resources/commits/test_results.rbs +19 -0
  200. data/sig/openlayer/resources/commits.rbs +14 -0
  201. data/sig/openlayer/resources/inference_pipelines/data.rbs +16 -0
  202. data/sig/openlayer/resources/inference_pipelines/rows.rbs +17 -0
  203. data/sig/openlayer/resources/inference_pipelines/test_results.rbs +18 -0
  204. data/sig/openlayer/resources/inference_pipelines.rbs +32 -0
  205. data/sig/openlayer/resources/projects/commits.rbs +25 -0
  206. data/sig/openlayer/resources/projects/inference_pipelines.rbs +26 -0
  207. data/sig/openlayer/resources/projects/tests.rbs +45 -0
  208. data/sig/openlayer/resources/projects.rbs +28 -0
  209. data/sig/openlayer/resources/storage/presigned_url.rbs +14 -0
  210. data/sig/openlayer/resources/storage.rbs +9 -0
  211. data/sig/openlayer/version.rbs +3 -0
  212. metadata +223 -91
  213. data/.env +0 -0
  214. data/.rspec +0 -3
  215. data/.rubocop.yml +0 -13
  216. data/LICENSE +0 -21
  217. data/Rakefile +0 -12
  218. data/examples/staging/.DS_Store +0 -0
  219. data/examples/staging/commit.yaml +0 -2
  220. data/examples/staging/model/model_config.yaml +0 -12
  221. data/examples/staging/validation/dataset_config.yaml +0 -12
  222. data/lib/openlayer/error.rb +0 -5
  223. data/lib/openlayer/inference_pipeline.rb +0 -36
  224. data/lib/openlayer/object.rb +0 -28
  225. data/lib/openlayer/objects/project.rb +0 -185
  226. data/lib/openlayer/objects/project_version.rb +0 -89
  227. data/lib/openlayer/services/s3_presigned_client.rb +0 -47
  228. data/lib/openlayer/services/tar_file_helper.rb +0 -55
  229. data/openlayer.gemspec +0 -45
  230. data/sig/openlayer.rbs +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9124105239930d01d444266033af79f2e1d2a7e6048b587e13dc6cfa1d00a0c3
4
- data.tar.gz: 869c8e6a79e351d2b5047272558e4b33fb7e794276731cfbe4e246410804d57b
3
+ metadata.gz: 697a21d4d40c619479976e24865b8d944ff8937614f74c4e35542a3c13674241
4
+ data.tar.gz: 8ca429adee40471cb39fa618f1fcf9b4a08df9cedb9c19095510c975f7e3d762
5
5
  SHA512:
6
- metadata.gz: aaa1a3ec31f4dd6ef75ba1f3acd5d50cb49318ac899dd3ec0442ddbe332abebe1ff6c39b042f4cc9ec66b05bd59790baf4bcf2ebe26f601b36d823e228940f0a
7
- data.tar.gz: 7d76c46e8c8b5d468a16421dc9d859c6768cdb1981afcd72b73cbfcfa307d3bdce1cd37f16066f4b46d7ab248ab1aef2cfe6f79ae20cee2ec0a72fc71fe667ed
6
+ metadata.gz: 8b3b455c4a3188442002783b8060fe880f50a9915f61c3b6f6bac7611d28c637798507610852f97df9a4dcfffa2b47b080165089a3feae8509c45a115688fc04
7
+ data.tar.gz: 04ef2610d79655ac61a2a450b82b772aaf98251bf52a44a74084bc70c4e9a5614f36d214f8553ee742e299ab29cd3282ce33857580670d5ef4dfc583e45f6117
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,23 @@
1
+ # Changelog
2
+
3
+ ## 0.4.0 (2025-10-02)
4
+
5
+ Full Changelog: [v0.0.2...v0.4.0](https://github.com/openlayer-ai/openlayer-ruby/compare/v0.0.2...v0.4.0)
6
+
7
+ ### Chores
8
+
9
+ * update readme ([102f6fb](https://github.com/openlayer-ai/openlayer-ruby/commit/102f6fb531cc81b046d27550788d508015c3674c))
10
+
11
+ ## 0.0.2 (2025-10-02)
12
+
13
+ Full Changelog: [v0.0.1...v0.0.2](https://github.com/openlayer-ai/openlayer-ruby/compare/v0.0.1...v0.0.2)
14
+
15
+ ### Bug Fixes
16
+
17
+ * coroutine leaks from connection pool ([c916cc0](https://github.com/openlayer-ai/openlayer-ruby/commit/c916cc0e7726963d08eefec4edca704a26393419))
18
+
19
+
20
+ ### Chores
21
+
22
+ * configure new SDK language ([844cad0](https://github.com/openlayer-ai/openlayer-ruby/commit/844cad0761a069778244da35537b74ae6ceb56b5))
23
+ * update SDK settings ([3185146](https://github.com/openlayer-ai/openlayer-ruby/commit/318514613db1e7f5f63067383d35852413c9b02d))
data/README.md CHANGED
@@ -1,73 +1,314 @@
1
- # Openlayer
2
- Openlayer is a Ruby gem that provides a wrapper for the Openlayer HTTP API. It allows you to connect to Openlayer and interact with its features. Please note that this gem is currently in the early stages of development.
1
+ # Openlayer Ruby API library
3
2
 
3
+ The Openlayer Ruby library provides convenient access to the Openlayer REST API from any Ruby 3.2.0+ application. It ships with comprehensive types & docstrings in Yard, RBS, and RBI – [see below](https://github.com/openlayer-ai/openlayer-ruby#Sorbet) for usage with Sorbet. The standard library's `net/http` is used as the HTTP transport, with connection pooling via the `connection_pool` gem.
4
+
5
+ It is generated with [Stainless](https://www.stainless.com/).
6
+
7
+ ## Documentation
8
+
9
+ Documentation for releases of this gem can be found [on RubyDoc](https://gemdocs.org/gems/openlayer).
10
+
11
+ The REST API documentation can be found on [openlayer.com](https://openlayer.com/docs/api-reference/rest/overview).
4
12
 
5
13
  ## Installation
6
- Install the gem and add to the application's Gemfile by executing:
7
14
 
8
- $ bundle add openlayer
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
9
16
 
10
- If bundler is not being used to manage dependencies, install the gem by executing:
17
+ <!-- x-release-please-start-version -->
11
18
 
12
- $ gem install openlayer
19
+ ```ruby
20
+ gem "openlayer", "~> 0.4.0"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
13
24
 
14
25
  ## Usage
15
26
 
16
- ### Inference Monitoring Mode
17
27
  ```ruby
18
- client = Openlayer::Client.new(api_key: "YOUR_OPENLAYER_API_KEY")
19
- inference_pipeline = client.inference_pipeline("YOUR_INFERENCE_PIPELINE_ID")
20
- inference_pipeline.stream_data(
21
- {
22
- rows: [...],
23
- config: {...}
28
+ require "bundler/setup"
29
+ require "openlayer"
30
+
31
+ openlayer = Openlayer::Client.new(
32
+ api_key: ENV["OPENLAYER_API_KEY"] # This is the default and can be omitted
33
+ )
34
+
35
+ response = openlayer.inference_pipelines.data.stream(
36
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
37
+ config: {
38
+ inputVariableNames: ["user_query"],
39
+ outputColumnName: "output",
40
+ numOfTokenColumnName: "tokens",
41
+ costColumnName: "cost",
42
+ timestampColumnName: "timestamp"
43
+ },
44
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}]
45
+ )
46
+
47
+ puts(response.success)
48
+ ```
49
+
50
+ ### Handling errors
51
+
52
+ When the library is unable to connect to the API, or if the API returns a non-success status code (i.e., 4xx or 5xx response), a subclass of `Openlayer::Errors::APIError` will be thrown:
53
+
54
+ ```ruby
55
+ begin
56
+ data = openlayer.inference_pipelines.data.stream(
57
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
58
+ config: {
59
+ inputVariableNames: ["user_query"],
60
+ outputColumnName: "output",
61
+ numOfTokenColumnName: "tokens",
62
+ costColumnName: "cost",
63
+ timestampColumnName: "timestamp"
64
+ },
65
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}]
66
+ )
67
+ rescue Openlayer::Errors::APIConnectionError => e
68
+ puts("The server could not be reached")
69
+ puts(e.cause) # an underlying Exception, likely raised within `net/http`
70
+ rescue Openlayer::Errors::RateLimitError => e
71
+ puts("A 429 status code was received; we should back off a bit.")
72
+ rescue Openlayer::Errors::APIStatusError => e
73
+ puts("Another non-200-range status code was received")
74
+ puts(e.status)
75
+ end
76
+ ```
77
+
78
+ Error codes are as follows:
79
+
80
+ | Cause | Error Type |
81
+ | ---------------- | -------------------------- |
82
+ | HTTP 400 | `BadRequestError` |
83
+ | HTTP 401 | `AuthenticationError` |
84
+ | HTTP 403 | `PermissionDeniedError` |
85
+ | HTTP 404 | `NotFoundError` |
86
+ | HTTP 409 | `ConflictError` |
87
+ | HTTP 422 | `UnprocessableEntityError` |
88
+ | HTTP 429 | `RateLimitError` |
89
+ | HTTP >= 500 | `InternalServerError` |
90
+ | Other HTTP error | `APIStatusError` |
91
+ | Timeout | `APITimeoutError` |
92
+ | Network error | `APIConnectionError` |
93
+
94
+ ### Retries
95
+
96
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
97
+
98
+ Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, >=500 Internal errors, and timeouts will all be retried by default.
99
+
100
+ You can use the `max_retries` option to configure or disable this:
101
+
102
+ ```ruby
103
+ # Configure the default for all requests:
104
+ openlayer = Openlayer::Client.new(
105
+ max_retries: 0 # default is 2
106
+ )
107
+
108
+ # Or, configure per-request:
109
+ openlayer.inference_pipelines.data.stream(
110
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
111
+ config: {
112
+ inputVariableNames: ["user_query"],
113
+ outputColumnName: "output",
114
+ numOfTokenColumnName: "tokens",
115
+ costColumnName: "cost",
116
+ timestampColumnName: "timestamp"
117
+ },
118
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}],
119
+ request_options: {max_retries: 5}
120
+ )
121
+ ```
122
+
123
+ ### Timeouts
124
+
125
+ By default, requests will time out after 60 seconds. You can use the timeout option to configure or disable this:
126
+
127
+ ```ruby
128
+ # Configure the default for all requests:
129
+ openlayer = Openlayer::Client.new(
130
+ timeout: nil # default is 60
131
+ )
132
+
133
+ # Or, configure per-request:
134
+ openlayer.inference_pipelines.data.stream(
135
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
136
+ config: {
137
+ inputVariableNames: ["user_query"],
138
+ outputColumnName: "output",
139
+ numOfTokenColumnName: "tokens",
140
+ costColumnName: "cost",
141
+ timestampColumnName: "timestamp"
142
+ },
143
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}],
144
+ request_options: {timeout: 5}
145
+ )
146
+ ```
147
+
148
+ On timeout, `Openlayer::Errors::APITimeoutError` is raised.
149
+
150
+ Note that requests that time out are retried by default.
151
+
152
+ ## Advanced concepts
153
+
154
+ ### BaseModel
155
+
156
+ All parameter and response objects inherit from `Openlayer::Internal::Type::BaseModel`, which provides several conveniences, including:
157
+
158
+ 1. All fields, including unknown ones, are accessible with `obj[:prop]` syntax, and can be destructured with `obj => {prop: prop}` or pattern-matching syntax.
159
+
160
+ 2. Structural equivalence for equality; if two API calls return the same values, comparing the responses with == will return true.
161
+
162
+ 3. Both instances and the classes themselves can be pretty-printed.
163
+
164
+ 4. Helpers such as `#to_h`, `#deep_to_h`, `#to_json`, and `#to_yaml`.
165
+
166
+ ### Making custom or undocumented requests
167
+
168
+ #### Undocumented properties
169
+
170
+ You can send undocumented parameters to any endpoint, and read undocumented response properties, like so:
171
+
172
+ Note: the `extra_` parameters of the same name overrides the documented parameters.
173
+
174
+ ```ruby
175
+ response =
176
+ openlayer.inference_pipelines.data.stream(
177
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
178
+ config: {
179
+ inputVariableNames: ["user_query"],
180
+ outputColumnName: "output",
181
+ numOfTokenColumnName: "tokens",
182
+ costColumnName: "cost",
183
+ timestampColumnName: "timestamp"
184
+ },
185
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}],
186
+ request_options: {
187
+ extra_query: {my_query_parameter: value},
188
+ extra_body: {my_body_parameter: value},
189
+ extra_headers: {"my-header": value}
24
190
  }
191
+ )
192
+
193
+ puts(response[:my_undocumented_property])
194
+ ```
195
+
196
+ #### Undocumented request params
197
+
198
+ If you want to explicitly send an extra param, you can do so with the `extra_query`, `extra_body`, and `extra_headers` under the `request_options:` parameter when making a request, as seen in the examples above.
199
+
200
+ #### Undocumented endpoints
201
+
202
+ To make requests to undocumented endpoints while retaining the benefit of auth, retries, and so on, you can make requests using `client.request`, like so:
203
+
204
+ ```ruby
205
+ response = client.request(
206
+ method: :post,
207
+ path: '/undocumented/endpoint',
208
+ query: {"dog": "woof"},
209
+ headers: {"useful-header": "interesting-value"},
210
+ body: {"hello": "world"}
25
211
  )
26
212
  ```
27
213
 
214
+ ### Concurrency & connection pooling
28
215
 
216
+ The `Openlayer::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
29
217
 
30
- ### Projects
31
- #### Load Project
32
- Loads an existing project from the Openlayer platform.
218
+ Each instance of `Openlayer::Client` has its own HTTP connection pool with a default size of 99. As such, we recommend instantiating the client once per application in most settings.
219
+
220
+ When all available connections from the pool are checked out, requests wait for a new connection to become available, with queue time counting towards the request timeout.
221
+
222
+ Unless otherwise specified, other classes in the SDK do not have locks protecting their underlying data structure.
223
+
224
+ ## Sorbet
225
+
226
+ This library provides comprehensive [RBI](https://sorbet.org/docs/rbi) definitions, and has no dependency on sorbet-runtime.
227
+
228
+ You can provide typesafe request parameters like so:
33
229
 
34
230
  ```ruby
35
- client = Openlayer::Client.new(api_key: "YOUR_OPENLAYER_API_KEY")
36
- project = client.load_project(name: "your_project_name")
231
+ openlayer.inference_pipelines.data.stream(
232
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
233
+ config: Openlayer::InferencePipelines::DataStreamParams::Config::LlmData.new(
234
+ input_variable_names: ["user_query"],
235
+ output_column_name: "output",
236
+ num_of_token_column_name: "tokens",
237
+ cost_column_name: "cost",
238
+ timestamp_column_name: "timestamp"
239
+ ),
240
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}]
241
+ )
37
242
  ```
38
243
 
39
- #### Development Mode for CI/CD
244
+ Or, equivalently:
245
+
40
246
  ```ruby
41
- client = Openlayer::Client.new(api_key: "YOUR_OPENLAYER_API_KEY")
42
- project = client.load_project(name: "your_project_name")
247
+ # Hashes work, but are not typesafe:
248
+ openlayer.inference_pipelines.data.stream(
249
+ "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
250
+ config: {
251
+ inputVariableNames: ["user_query"],
252
+ outputColumnName: "output",
253
+ numOfTokenColumnName: "tokens",
254
+ costColumnName: "cost",
255
+ timestampColumnName: "timestamp"
256
+ },
257
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}]
258
+ )
259
+
260
+ # You can also splat a full Params class:
261
+ params = Openlayer::InferencePipelines::DataStreamParams.new(
262
+ config: Openlayer::InferencePipelines::DataStreamParams::Config::LlmData.new(
263
+ input_variable_names: ["user_query"],
264
+ output_column_name: "output",
265
+ num_of_token_column_name: "tokens",
266
+ cost_column_name: "cost",
267
+ timestamp_column_name: "timestamp"
268
+ ),
269
+ rows: [{user_query: "what is the meaning of life?", output: "42", tokens: 7, cost: 0.02, timestamp: 1610000000}]
270
+ )
271
+ openlayer.inference_pipelines.data.stream("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e", **params)
272
+ ```
43
273
 
274
+ ### Enums
44
275
 
45
- project.add_dataset(file_path: "DATASET_FILE_PATH", dataset_config_file_path: "DATASET_CONFIG_FILE_PATH")
46
- project.add_model(model_config_file_path: "MODEL_CONFIG_PATH")
47
- project.commit(message: "This is a commit message")
48
- version = project.push
276
+ Since this library does not depend on `sorbet-runtime`, it cannot provide [`T::Enum`](https://sorbet.org/docs/tenum) instances. Instead, we provide "tagged symbols" instead, which is always a primitive at runtime:
49
277
 
50
- version.wait_for_completion(timeout: 500)
51
- version.print_test_report
278
+ ```ruby
279
+ # :"llm-base"
280
+ puts(Openlayer::ProjectCreateParams::TaskType::LLM_BASE)
52
281
 
53
- if version.failing_test_count > 0:
54
- puts "Failing pipeline due to failing goals."
55
- exit(1)
282
+ # Revealed type: `T.all(Openlayer::ProjectCreateParams::TaskType, Symbol)`
283
+ T.reveal_type(Openlayer::ProjectCreateParams::TaskType::LLM_BASE)
56
284
  ```
57
285
 
58
- - Check the example in `examples/staging` for what the YAMLs look like.
59
- - Check the [Dataset Config](https://docs.openlayer.com/how-to-guides/write-dataset-configs/llm-dataset-config) and the [Model Config](https://docs.openlayer.com/how-to-guides/write-model-configs/llm-config) docs on Openlayer to see additional attributes for the configs.
286
+ Enum parameters have a "relaxed" type, so you can either pass in enum constants or their literal value:
287
+
288
+ ```ruby
289
+ # Using the enum constants preserves the tagged type information:
290
+ openlayer.projects.create(
291
+ task_type: Openlayer::ProjectCreateParams::TaskType::LLM_BASE,
292
+ # …
293
+ )
294
+
295
+ # Literal values are also permissible:
296
+ openlayer.projects.create(
297
+ task_type: :"llm-base",
298
+ # …
299
+ )
300
+ ```
60
301
 
61
- ## Development
302
+ ## Versioning
62
303
 
63
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
304
+ This package follows [SemVer](https://semver.org/spec/v2.0.0.html) conventions. As the library is in initial development and has a major version of `0`, APIs may change at any time.
64
305
 
65
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
306
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
66
307
 
67
- ## Contributing
308
+ ## Requirements
68
309
 
69
- Bug reports and pull requests are welcome on GitHub at https://github.com/TelosLabs/openlayer.
310
+ Ruby 3.2.0 or higher.
70
311
 
71
- ## License
312
+ ## Contributing
72
313
 
73
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
314
+ See [the contributing documentation](https://github.com/openlayer-ai/openlayer-ruby/tree/main/CONTRIBUTING.md)
data/SECURITY.md ADDED
@@ -0,0 +1,27 @@
1
+ # Security Policy
2
+
3
+ ## Reporting Security Issues
4
+
5
+ This SDK is generated by [Stainless Software Inc](http://stainless.com). Stainless takes security seriously, and encourages you to report any security vulnerability promptly so that appropriate action can be taken.
6
+
7
+ To report a security issue, please contact the Stainless team at security@stainless.com.
8
+
9
+ ## Responsible Disclosure
10
+
11
+ We appreciate the efforts of security researchers and individuals who help us maintain the security of
12
+ SDKs we generate. If you believe you have found a security vulnerability, please adhere to responsible
13
+ disclosure practices by allowing us a reasonable amount of time to investigate and address the issue
14
+ before making any information public.
15
+
16
+ ## Reporting Non-SDK Related Security Issues
17
+
18
+ If you encounter security issues that are not directly related to SDKs but pertain to the services
19
+ or products provided by Openlayer, please follow the respective company's security reporting guidelines.
20
+
21
+ ### Openlayer Terms and Policies
22
+
23
+ Please contact support@openlayer.com for any questions or concerns regarding the security of our services.
24
+
25
+ ---
26
+
27
+ Thank you for helping us keep the SDKs and systems they interact with secure.
@@ -1,77 +1,82 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "faraday"
4
- require "faraday/multipart"
5
-
6
3
  module Openlayer
7
- class Client
8
- BASE_URL = "https://api.openlayer.com/v1/"
4
+ class Client < Openlayer::Internal::Transport::BaseClient
5
+ # Default max number of retries to attempt after a failed retryable request.
6
+ DEFAULT_MAX_RETRIES = 2
9
7
 
10
- attr_reader :api_key, :adapter
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
11
10
 
12
- def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
13
- @api_key = api_key
14
- @adapter = adapter
15
- @stubs = stubs
16
- end
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
17
14
 
18
- def inference_pipeline(inference_pipeline_id)
19
- InferencePipeline.new(self, inference_pipeline_id)
20
- end
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
21
17
 
22
- def load_project(name:)
23
- Project.from_response self, connection.get("projects", project_search_params(name: name))
24
- end
18
+ # @return [String, nil]
19
+ attr_reader :api_key
25
20
 
26
- def presigned_url(object_name: nil, workspace_id: nil)
27
- handle_response connection.post(
28
- "storage/presigned-url?objectName=staging", presigned_url_params(object_name: object_name,
29
- workspace_id: workspace_id)
30
- )
31
- end
21
+ # @return [Openlayer::Resources::Projects]
22
+ attr_reader :projects
32
23
 
33
- def load_project_version(id:, payload: {})
34
- ProjectVersion.from_response self, connection.post("projects/#{id}/versions", payload)
35
- end
24
+ # @return [Openlayer::Resources::Commits]
25
+ attr_reader :commits
36
26
 
37
- def connection
38
- @connection ||= Faraday.new do |conn|
39
- conn.url_prefix = BASE_URL
40
- conn.request :authorization, "Bearer", api_key
41
- conn.request :json
42
- conn.response :json, content_type: "application/json"
43
- conn.adapter adapter, @stubs
44
- end
45
- end
27
+ # @return [Openlayer::Resources::InferencePipelines]
28
+ attr_reader :inference_pipelines
46
29
 
47
- private
30
+ # @return [Openlayer::Resources::Storage]
31
+ attr_reader :storage
48
32
 
49
- def project_search_params(name:)
50
- { version: "0.1.0a25", name: name }
51
- end
33
+ # @api private
34
+ #
35
+ # @return [Hash{String=>String}]
36
+ private def auth_headers
37
+ return {} if @api_key.nil?
52
38
 
53
- def presigned_url_params(object_name: nil, workspace_id: nil)
54
- { "objectName": object_name, "workspaceId": workspace_id, version: "0.1.0a25" }.compact
39
+ {"authorization" => "Bearer #{@api_key}"}
55
40
  end
56
41
 
57
- def handle_response(response)
58
- message = response.body["error"]
59
- case response.status
60
- when 200
61
- response.body
62
- when 401
63
- raise Error, message
64
- when 404
65
- raise Error, message
66
- when 422
67
- raise Error, message
68
- when 500
69
- raise Error, message
70
- when 200..299
71
- response.body
72
- else
73
- raise Error, message
74
- end
42
+ # Creates and returns a new client for interacting with the API.
43
+ #
44
+ # @param api_key [String, nil] Defaults to `ENV["OPENLAYER_API_KEY"]`
45
+ #
46
+ # @param base_url [String, nil] Override the default base URL for the API, e.g.,
47
+ # `"https://api.example.com/v2/"`. Defaults to `ENV["OPENLAYER_BASE_URL"]`
48
+ #
49
+ # @param max_retries [Integer] Max number of retries to attempt after a failed retryable request.
50
+ #
51
+ # @param timeout [Float]
52
+ #
53
+ # @param initial_retry_delay [Float]
54
+ #
55
+ # @param max_retry_delay [Float]
56
+ def initialize(
57
+ api_key: ENV["OPENLAYER_API_KEY"],
58
+ base_url: ENV["OPENLAYER_BASE_URL"],
59
+ max_retries: self.class::DEFAULT_MAX_RETRIES,
60
+ timeout: self.class::DEFAULT_TIMEOUT_IN_SECONDS,
61
+ initial_retry_delay: self.class::DEFAULT_INITIAL_RETRY_DELAY,
62
+ max_retry_delay: self.class::DEFAULT_MAX_RETRY_DELAY
63
+ )
64
+ base_url ||= "https://api.openlayer.com/v1"
65
+
66
+ @api_key = api_key&.to_s
67
+
68
+ super(
69
+ base_url: base_url,
70
+ timeout: timeout,
71
+ max_retries: max_retries,
72
+ initial_retry_delay: initial_retry_delay,
73
+ max_retry_delay: max_retry_delay
74
+ )
75
+
76
+ @projects = Openlayer::Resources::Projects.new(client: self)
77
+ @commits = Openlayer::Resources::Commits.new(client: self)
78
+ @inference_pipelines = Openlayer::Resources::InferencePipelines.new(client: self)
79
+ @storage = Openlayer::Resources::Storage.new(client: self)
75
80
  end
76
81
  end
77
82
  end