openlayer 0.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 (212) hide show
  1. checksums.yaml +7 -0
  2. data/.ignore +2 -0
  3. data/CHANGELOG.md +15 -0
  4. data/README.md +314 -0
  5. data/SECURITY.md +27 -0
  6. data/lib/openlayer/client.rb +82 -0
  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 +5 -0
  74. data/lib/openlayer.rb +100 -0
  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 +269 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 03e34d6b0d068d650d9e5e39b1315f1c914cb89ddfb286e7a1abca0f6030b2f8
4
+ data.tar.gz: 2ad19647f1f7e8054a7cd188d2b85f2bf34c67e8662445417c4cdf4e7d46725a
5
+ SHA512:
6
+ metadata.gz: 4e2bf45256ea58afa6213ac4f4f7de4f046704ed334efc5b78e556d2b52900b26885e74c82526cdd0a8d2896d973ee858611169d81989f6799ebd96ebad77ed2
7
+ data.tar.gz: 872bd6ca7e84e04aba005064cd38d504acd7e8e259d6027c0f7cd28522d4a7e80fb37123fffbcd07c0e1fabb4b7120d84748620d86f1519efb5841c3c2d2bfc6
data/.ignore ADDED
@@ -0,0 +1,2 @@
1
+ rbi/*
2
+ sig/*
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ # Changelog
2
+
3
+ ## 0.0.2 (2025-10-02)
4
+
5
+ Full Changelog: [v0.0.1...v0.0.2](https://github.com/openlayer-ai/openlayer-ruby/compare/v0.0.1...v0.0.2)
6
+
7
+ ### Bug Fixes
8
+
9
+ * coroutine leaks from connection pool ([c916cc0](https://github.com/openlayer-ai/openlayer-ruby/commit/c916cc0e7726963d08eefec4edca704a26393419))
10
+
11
+
12
+ ### Chores
13
+
14
+ * configure new SDK language ([844cad0](https://github.com/openlayer-ai/openlayer-ruby/commit/844cad0761a069778244da35537b74ae6ceb56b5))
15
+ * update SDK settings ([3185146](https://github.com/openlayer-ai/openlayer-ruby/commit/318514613db1e7f5f63067383d35852413c9b02d))
data/README.md ADDED
@@ -0,0 +1,314 @@
1
+ # Openlayer Ruby API library
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).
12
+
13
+ ## Installation
14
+
15
+ To use this gem, install via Bundler by adding the following to your application's `Gemfile`:
16
+
17
+ <!-- x-release-please-start-version -->
18
+
19
+ ```ruby
20
+ gem "openlayer", "~> 0.0.2"
21
+ ```
22
+
23
+ <!-- x-release-please-end -->
24
+
25
+ ## Usage
26
+
27
+ ```ruby
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}
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"}
211
+ )
212
+ ```
213
+
214
+ ### Concurrency & connection pooling
215
+
216
+ The `Openlayer::Client` instances are threadsafe, but are only are fork-safe when there are no in-flight HTTP requests.
217
+
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:
229
+
230
+ ```ruby
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
+ )
242
+ ```
243
+
244
+ Or, equivalently:
245
+
246
+ ```ruby
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
+ ```
273
+
274
+ ### Enums
275
+
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:
277
+
278
+ ```ruby
279
+ # :"llm-base"
280
+ puts(Openlayer::ProjectCreateParams::TaskType::LLM_BASE)
281
+
282
+ # Revealed type: `T.all(Openlayer::ProjectCreateParams::TaskType, Symbol)`
283
+ T.reveal_type(Openlayer::ProjectCreateParams::TaskType::LLM_BASE)
284
+ ```
285
+
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
+ ```
301
+
302
+ ## Versioning
303
+
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.
305
+
306
+ This package considers improvements to the (non-runtime) `*.rbi` and `*.rbs` type definitions to be non-breaking changes.
307
+
308
+ ## Requirements
309
+
310
+ Ruby 3.2.0 or higher.
311
+
312
+ ## Contributing
313
+
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.
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openlayer
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
7
+
8
+ # Default per-request timeout.
9
+ DEFAULT_TIMEOUT_IN_SECONDS = 60.0
10
+
11
+ # Default initial retry delay in seconds.
12
+ # Overall delay is calculated using exponential backoff + jitter.
13
+ DEFAULT_INITIAL_RETRY_DELAY = 0.5
14
+
15
+ # Default max retry delay in seconds.
16
+ DEFAULT_MAX_RETRY_DELAY = 8.0
17
+
18
+ # @return [String, nil]
19
+ attr_reader :api_key
20
+
21
+ # @return [Openlayer::Resources::Projects]
22
+ attr_reader :projects
23
+
24
+ # @return [Openlayer::Resources::Commits]
25
+ attr_reader :commits
26
+
27
+ # @return [Openlayer::Resources::InferencePipelines]
28
+ attr_reader :inference_pipelines
29
+
30
+ # @return [Openlayer::Resources::Storage]
31
+ attr_reader :storage
32
+
33
+ # @api private
34
+ #
35
+ # @return [Hash{String=>String}]
36
+ private def auth_headers
37
+ return {} if @api_key.nil?
38
+
39
+ {"authorization" => "Bearer #{@api_key}"}
40
+ end
41
+
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)
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Openlayer
4
+ module Errors
5
+ class Error < StandardError
6
+ # @!attribute cause
7
+ #
8
+ # @return [StandardError, nil]
9
+ end
10
+
11
+ class ConversionError < Openlayer::Errors::Error
12
+ # @return [StandardError, nil]
13
+ def cause = @cause.nil? ? super : @cause
14
+
15
+ # @api private
16
+ #
17
+ # @param on [Class<StandardError>]
18
+ # @param method [Symbol]
19
+ # @param target [Object]
20
+ # @param value [Object]
21
+ # @param cause [StandardError, nil]
22
+ def initialize(on:, method:, target:, value:, cause: nil)
23
+ cls = on.name.split("::").last
24
+
25
+ message = [
26
+ "Failed to parse #{cls}.#{method} from #{value.class} to #{target.inspect}.",
27
+ "To get the unparsed API response, use #{cls}[#{method.inspect}].",
28
+ cause && "Cause: #{cause.message}"
29
+ ].filter(&:itself).join(" ")
30
+
31
+ @cause = cause
32
+ super(message)
33
+ end
34
+ end
35
+
36
+ class APIError < Openlayer::Errors::Error
37
+ # @return [URI::Generic]
38
+ attr_accessor :url
39
+
40
+ # @return [Integer, nil]
41
+ attr_accessor :status
42
+
43
+ # @return [Hash{String=>String}, nil]
44
+ attr_accessor :headers
45
+
46
+ # @return [Object, nil]
47
+ attr_accessor :body
48
+
49
+ # @api private
50
+ #
51
+ # @param url [URI::Generic]
52
+ # @param status [Integer, nil]
53
+ # @param headers [Hash{String=>String}, nil]
54
+ # @param body [Object, nil]
55
+ # @param request [nil]
56
+ # @param response [nil]
57
+ # @param message [String, nil]
58
+ def initialize(url:, status: nil, headers: nil, body: nil, request: nil, response: nil, message: nil)
59
+ @url = url
60
+ @status = status
61
+ @headers = headers
62
+ @body = body
63
+ @request = request
64
+ @response = response
65
+ super(message)
66
+ end
67
+ end
68
+
69
+ class APIConnectionError < Openlayer::Errors::APIError
70
+ # @!attribute status
71
+ #
72
+ # @return [nil]
73
+
74
+ # @!attribute body
75
+ #
76
+ # @return [nil]
77
+
78
+ # @api private
79
+ #
80
+ # @param url [URI::Generic]
81
+ # @param status [nil]
82
+ # @param headers [Hash{String=>String}, nil]
83
+ # @param body [nil]
84
+ # @param request [nil]
85
+ # @param response [nil]
86
+ # @param message [String, nil]
87
+ def initialize(
88
+ url:,
89
+ status: nil,
90
+ headers: nil,
91
+ body: nil,
92
+ request: nil,
93
+ response: nil,
94
+ message: "Connection error."
95
+ )
96
+ super
97
+ end
98
+ end
99
+
100
+ class APITimeoutError < Openlayer::Errors::APIConnectionError
101
+ # @api private
102
+ #
103
+ # @param url [URI::Generic]
104
+ # @param status [nil]
105
+ # @param headers [Hash{String=>String}, nil]
106
+ # @param body [nil]
107
+ # @param request [nil]
108
+ # @param response [nil]
109
+ # @param message [String, nil]
110
+ def initialize(
111
+ url:,
112
+ status: nil,
113
+ headers: nil,
114
+ body: nil,
115
+ request: nil,
116
+ response: nil,
117
+ message: "Request timed out."
118
+ )
119
+ super
120
+ end
121
+ end
122
+
123
+ class APIStatusError < Openlayer::Errors::APIError
124
+ # @api private
125
+ #
126
+ # @param url [URI::Generic]
127
+ # @param status [Integer]
128
+ # @param headers [Hash{String=>String}, nil]
129
+ # @param body [Object, nil]
130
+ # @param request [nil]
131
+ # @param response [nil]
132
+ # @param message [String, nil]
133
+ #
134
+ # @return [self]
135
+ def self.for(url:, status:, headers:, body:, request:, response:, message: nil)
136
+ kwargs =
137
+ {
138
+ url: url,
139
+ status: status,
140
+ headers: headers,
141
+ body: body,
142
+ request: request,
143
+ response: response,
144
+ message: message
145
+ }
146
+
147
+ case status
148
+ in 400
149
+ Openlayer::Errors::BadRequestError.new(**kwargs)
150
+ in 401
151
+ Openlayer::Errors::AuthenticationError.new(**kwargs)
152
+ in 403
153
+ Openlayer::Errors::PermissionDeniedError.new(**kwargs)
154
+ in 404
155
+ Openlayer::Errors::NotFoundError.new(**kwargs)
156
+ in 409
157
+ Openlayer::Errors::ConflictError.new(**kwargs)
158
+ in 422
159
+ Openlayer::Errors::UnprocessableEntityError.new(**kwargs)
160
+ in 429
161
+ Openlayer::Errors::RateLimitError.new(**kwargs)
162
+ in (500..)
163
+ Openlayer::Errors::InternalServerError.new(**kwargs)
164
+ else
165
+ Openlayer::Errors::APIStatusError.new(**kwargs)
166
+ end
167
+ end
168
+
169
+ # @!parse
170
+ # # @return [Integer]
171
+ # attr_accessor :status
172
+
173
+ # @api private
174
+ #
175
+ # @param url [URI::Generic]
176
+ # @param status [Integer]
177
+ # @param headers [Hash{String=>String}, nil]
178
+ # @param body [Object, nil]
179
+ # @param request [nil]
180
+ # @param response [nil]
181
+ # @param message [String, nil]
182
+ def initialize(url:, status:, headers:, body:, request:, response:, message: nil)
183
+ message ||= {url: url.to_s, status: status, body: body}
184
+ super(
185
+ url: url,
186
+ status: status,
187
+ headers: headers,
188
+ body: body,
189
+ request: request,
190
+ response: response,
191
+ message: message&.to_s
192
+ )
193
+ end
194
+ end
195
+
196
+ class BadRequestError < Openlayer::Errors::APIStatusError
197
+ HTTP_STATUS = 400
198
+ end
199
+
200
+ class AuthenticationError < Openlayer::Errors::APIStatusError
201
+ HTTP_STATUS = 401
202
+ end
203
+
204
+ class PermissionDeniedError < Openlayer::Errors::APIStatusError
205
+ HTTP_STATUS = 403
206
+ end
207
+
208
+ class NotFoundError < Openlayer::Errors::APIStatusError
209
+ HTTP_STATUS = 404
210
+ end
211
+
212
+ class ConflictError < Openlayer::Errors::APIStatusError
213
+ HTTP_STATUS = 409
214
+ end
215
+
216
+ class UnprocessableEntityError < Openlayer::Errors::APIStatusError
217
+ HTTP_STATUS = 422
218
+ end
219
+
220
+ class RateLimitError < Openlayer::Errors::APIStatusError
221
+ HTTP_STATUS = 429
222
+ end
223
+
224
+ class InternalServerError < Openlayer::Errors::APIStatusError
225
+ HTTP_STATUS = (500..)
226
+ end
227
+ end
228
+ end