es_cli 0.1.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 (485) hide show
  1. checksums.yaml +7 -0
  2. data/.bundle/config +2 -0
  3. data/LICENSE.txt +21 -0
  4. data/README.md +39 -0
  5. data/Rakefile +12 -0
  6. data/exe/es +8 -0
  7. data/lib/es_cli/cli.rb +247 -0
  8. data/lib/es_cli/version.rb +5 -0
  9. data/lib/es_cli.rb +11 -0
  10. data/readme.org +78 -0
  11. data/sig/es_cli.rbs +4 -0
  12. data/vendor/bundle/ruby/3.1.0/bin/rake +29 -0
  13. data/vendor/bundle/ruby/3.1.0/bin/thor +29 -0
  14. data/vendor/bundle/ruby/3.1.0/cache/event_stream_parser-1.0.0.gem +0 -0
  15. data/vendor/bundle/ruby/3.1.0/cache/faraday-2.12.2.gem +0 -0
  16. data/vendor/bundle/ruby/3.1.0/cache/faraday-multipart-1.1.0.gem +0 -0
  17. data/vendor/bundle/ruby/3.1.0/cache/faraday-net_http-3.4.0.gem +0 -0
  18. data/vendor/bundle/ruby/3.1.0/cache/json-2.9.1.gem +0 -0
  19. data/vendor/bundle/ruby/3.1.0/cache/logger-1.6.5.gem +0 -0
  20. data/vendor/bundle/ruby/3.1.0/cache/multipart-post-2.4.1.gem +0 -0
  21. data/vendor/bundle/ruby/3.1.0/cache/net-http-0.6.0.gem +0 -0
  22. data/vendor/bundle/ruby/3.1.0/cache/power_assert-2.0.5.gem +0 -0
  23. data/vendor/bundle/ruby/3.1.0/cache/rake-13.2.1.gem +0 -0
  24. data/vendor/bundle/ruby/3.1.0/cache/ruby-openai-7.3.1.gem +0 -0
  25. data/vendor/bundle/ruby/3.1.0/cache/test-unit-3.6.7.gem +0 -0
  26. data/vendor/bundle/ruby/3.1.0/cache/thor-1.3.2.gem +0 -0
  27. data/vendor/bundle/ruby/3.1.0/cache/uri-1.0.2.gem +0 -0
  28. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/gem.build_complete +0 -0
  29. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/gem_make.out +22 -0
  30. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/json/ext/generator.bundle +0 -0
  31. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/json/ext/parser.bundle +0 -0
  32. data/vendor/bundle/ruby/3.1.0/extensions/arm64-darwin-23/3.1.0/json-2.9.1/mkmf.log +208 -0
  33. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/LICENSE.md +21 -0
  34. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/README.md +99 -0
  35. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/lib/event_stream_parser/version.rb +5 -0
  36. data/vendor/bundle/ruby/3.1.0/gems/event_stream_parser-1.0.0/lib/event_stream_parser.rb +222 -0
  37. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/CHANGELOG.md +574 -0
  38. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/LICENSE.md +20 -0
  39. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/README.md +67 -0
  40. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/Rakefile +12 -0
  41. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/examples/client_spec.rb +119 -0
  42. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/examples/client_test.rb +144 -0
  43. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter/test.rb +311 -0
  44. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter.rb +101 -0
  45. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/adapter_registry.rb +30 -0
  46. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/connection.rb +564 -0
  47. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/encoders/flat_params_encoder.rb +105 -0
  48. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/encoders/nested_params_encoder.rb +183 -0
  49. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/error.rb +165 -0
  50. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/logging/formatter.rb +118 -0
  51. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/methods.rb +6 -0
  52. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/middleware.rb +72 -0
  53. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/middleware_registry.rb +83 -0
  54. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/connection_options.rb +23 -0
  55. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/env.rb +204 -0
  56. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/proxy_options.rb +36 -0
  57. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/request_options.rb +23 -0
  58. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options/ssl_options.rb +73 -0
  59. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/options.rb +219 -0
  60. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/parameters.rb +5 -0
  61. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/rack_builder.rb +251 -0
  62. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/authorization.rb +54 -0
  63. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/instrumentation.rb +58 -0
  64. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/json.rb +70 -0
  65. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request/url_encoded.rb +60 -0
  66. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/request.rb +139 -0
  67. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/json.rb +74 -0
  68. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/logger.rb +37 -0
  69. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response/raise_error.rb +83 -0
  70. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/response.rb +91 -0
  71. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils/headers.rb +150 -0
  72. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils/params_hash.rb +61 -0
  73. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/utils.rb +121 -0
  74. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday/version.rb +5 -0
  75. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/lib/faraday.rb +157 -0
  76. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/external_adapters/faraday_specs_setup.rb +14 -0
  77. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter/test_spec.rb +442 -0
  78. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter_registry_spec.rb +28 -0
  79. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/adapter_spec.rb +55 -0
  80. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/connection_spec.rb +808 -0
  81. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/error_spec.rb +93 -0
  82. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/middleware_registry_spec.rb +31 -0
  83. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/middleware_spec.rb +213 -0
  84. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/env_spec.rb +76 -0
  85. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/options_spec.rb +297 -0
  86. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/proxy_options_spec.rb +52 -0
  87. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/options/request_options_spec.rb +19 -0
  88. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/params_encoders/flat_spec.rb +42 -0
  89. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/params_encoders/nested_spec.rb +151 -0
  90. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/rack_builder_spec.rb +317 -0
  91. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/authorization_spec.rb +118 -0
  92. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/instrumentation_spec.rb +74 -0
  93. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/json_spec.rb +199 -0
  94. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request/url_encoded_spec.rb +93 -0
  95. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/request_spec.rb +110 -0
  96. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/json_spec.rb +206 -0
  97. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/logger_spec.rb +278 -0
  98. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response/raise_error_spec.rb +275 -0
  99. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/response_spec.rb +77 -0
  100. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/utils/headers_spec.rb +109 -0
  101. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday/utils_spec.rb +119 -0
  102. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/faraday_spec.rb +43 -0
  103. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/spec_helper.rb +133 -0
  104. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/disabling_stub.rb +14 -0
  105. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/fake_safe_buffer.rb +15 -0
  106. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/faraday_middleware_subclasses.rb +18 -0
  107. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/helper_methods.rb +96 -0
  108. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/adapter.rb +105 -0
  109. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/params_encoder.rb +18 -0
  110. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/shared_examples/request_method.rb +263 -0
  111. data/vendor/bundle/ruby/3.1.0/gems/faraday-2.12.2/spec/support/streaming_response_checker.rb +35 -0
  112. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/CHANGELOG.md +54 -0
  113. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/LICENSE.md +21 -0
  114. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/README.md +170 -0
  115. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/file_part.rb +130 -0
  116. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/middleware.rb +134 -0
  117. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/param_part.rb +55 -0
  118. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart/version.rb +16 -0
  119. data/vendor/bundle/ruby/3.1.0/gems/faraday-multipart-1.1.0/lib/faraday/multipart.rb +26 -0
  120. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/LICENSE.md +21 -0
  121. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/README.md +57 -0
  122. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/adapter/net_http.rb +206 -0
  123. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/net_http/version.rb +7 -0
  124. data/vendor/bundle/ruby/3.1.0/gems/faraday-net_http-3.4.0/lib/faraday/net_http.rb +10 -0
  125. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/BSDL +22 -0
  126. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/CHANGES.md +572 -0
  127. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/COPYING +56 -0
  128. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/LEGAL +60 -0
  129. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/README.md +195 -0
  130. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/fbuffer/fbuffer.h +214 -0
  131. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/.sitearchdir.-.json.-.ext.time +0 -0
  132. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/Makefile +269 -0
  133. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/extconf.rb +10 -0
  134. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.bundle +0 -0
  135. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.c +1691 -0
  136. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/generator/generator.o +0 -0
  137. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/.sitearchdir.-.json.-.ext.time +0 -0
  138. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/Makefile +269 -0
  139. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/extconf.rb +12 -0
  140. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.bundle +0 -0
  141. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.c +3238 -0
  142. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.o +0 -0
  143. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/ext/json/ext/parser/parser.rl +1465 -0
  144. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/json.gemspec +64 -0
  145. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/bigdecimal.rb +58 -0
  146. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/complex.rb +51 -0
  147. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/core.rb +12 -0
  148. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/date.rb +54 -0
  149. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/date_time.rb +67 -0
  150. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/exception.rb +49 -0
  151. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/ostruct.rb +54 -0
  152. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/range.rb +54 -0
  153. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/rational.rb +49 -0
  154. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/regexp.rb +48 -0
  155. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/set.rb +48 -0
  156. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/struct.rb +52 -0
  157. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/symbol.rb +47 -0
  158. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/add/time.rb +52 -0
  159. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/common.rb +896 -0
  160. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/generator/state.rb +116 -0
  161. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/generator.bundle +0 -0
  162. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext/parser.bundle +0 -0
  163. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/ext.rb +23 -0
  164. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/generic_object.rb +75 -0
  165. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/truffle_ruby/generator.rb +629 -0
  166. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json/version.rb +5 -0
  167. data/vendor/bundle/ruby/3.1.0/gems/json-2.9.1/lib/json.rb +587 -0
  168. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/dependabot.yml +6 -0
  169. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/workflows/push_gem.yml +46 -0
  170. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.github/workflows/test.yml +32 -0
  171. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/.gitignore +11 -0
  172. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/BSDL +22 -0
  173. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/COPYING +56 -0
  174. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/Gemfile +10 -0
  175. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/README.md +104 -0
  176. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/Rakefile +30 -0
  177. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/bin/console +14 -0
  178. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/bin/setup +8 -0
  179. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/errors.rb +9 -0
  180. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/formatter.rb +36 -0
  181. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/log_device.rb +241 -0
  182. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/period.rb +47 -0
  183. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/severity.rb +38 -0
  184. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger/version.rb +5 -0
  185. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/lib/logger.rb +761 -0
  186. data/vendor/bundle/ruby/3.1.0/gems/logger-1.6.5/logger.gemspec +28 -0
  187. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/changelog.md +14 -0
  188. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/composite_io.rb +17 -0
  189. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/composite_read_io.rb +91 -0
  190. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/multipartable.rb +70 -0
  191. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/parts.rb +148 -0
  192. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/upload_io.rb +64 -0
  193. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post/version.rb +11 -0
  194. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart/post.rb +8 -0
  195. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipart_post.rb +11 -0
  196. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/multipartable.rb +19 -0
  197. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/net/http/post/multipart.rb +28 -0
  198. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/lib/parts.rb +25 -0
  199. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/license.md +58 -0
  200. data/vendor/bundle/ruby/3.1.0/gems/multipart-post-2.4.1/readme.md +170 -0
  201. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/BSDL +22 -0
  202. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/COPYING +56 -0
  203. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/Gemfile +8 -0
  204. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/README.md +93 -0
  205. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/Rakefile +10 -0
  206. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/bin/console +14 -0
  207. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/bin/setup +8 -0
  208. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/doc/net-http/examples.rdoc +31 -0
  209. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/doc/net-http/included_getters.rdoc +3 -0
  210. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/exceptions.rb +34 -0
  211. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/generic_request.rb +414 -0
  212. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/header.rb +981 -0
  213. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/proxy_delta.rb +17 -0
  214. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/request.rb +88 -0
  215. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/requests.rb +430 -0
  216. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/response.rb +738 -0
  217. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/responses.rb +1174 -0
  218. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http/status.rb +84 -0
  219. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/http.rb +2580 -0
  220. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/lib/net/https.rb +23 -0
  221. data/vendor/bundle/ruby/3.1.0/gems/net-http-0.6.0/net-http.gemspec +39 -0
  222. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.github/dependabot.yml +6 -0
  223. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.github/workflows/ci.yml +46 -0
  224. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/.gitignore +9 -0
  225. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/BSDL +22 -0
  226. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/COPYING +57 -0
  227. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/Gemfile +19 -0
  228. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/LEGAL +4 -0
  229. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/README.md +98 -0
  230. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/Rakefile +59 -0
  231. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/colorize.rb +7 -0
  232. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/configuration.rb +46 -0
  233. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/context.rb +233 -0
  234. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/enable_tracepoint_events.rb +62 -0
  235. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/inspector.rb +66 -0
  236. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/parser.rb +251 -0
  237. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert/version.rb +3 -0
  238. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/lib/power_assert.rb +93 -0
  239. data/vendor/bundle/ruby/3.1.0/gems/power_assert-2.0.5/power_assert.gemspec +24 -0
  240. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/History.rdoc +2403 -0
  241. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/MIT-LICENSE +21 -0
  242. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/README.rdoc +155 -0
  243. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/command_line_usage.rdoc +158 -0
  244. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/Rakefile1 +38 -0
  245. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/Rakefile2 +35 -0
  246. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/a.c +6 -0
  247. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/b.c +6 -0
  248. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/example/main.c +11 -0
  249. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/glossary.rdoc +42 -0
  250. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/jamis.rb +592 -0
  251. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/proto_rake.rdoc +127 -0
  252. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rake.1 +156 -0
  253. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rakefile.rdoc +622 -0
  254. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/doc/rational.rdoc +151 -0
  255. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/exe/rake +27 -0
  256. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/application.rb +861 -0
  257. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/backtrace.rb +25 -0
  258. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/clean.rb +78 -0
  259. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/cloneable.rb +17 -0
  260. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/cpu_counter.rb +107 -0
  261. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/default_loader.rb +15 -0
  262. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/dsl_definition.rb +196 -0
  263. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/early_time.rb +22 -0
  264. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/ext/core.rb +26 -0
  265. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/ext/string.rb +176 -0
  266. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_creation_task.rb +25 -0
  267. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_list.rb +435 -0
  268. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_task.rb +58 -0
  269. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_utils.rb +132 -0
  270. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/file_utils_ext.rb +134 -0
  271. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/invocation_chain.rb +57 -0
  272. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/invocation_exception_mixin.rb +17 -0
  273. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/late_time.rb +18 -0
  274. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/linked_list.rb +112 -0
  275. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/loaders/makefile.rb +54 -0
  276. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/multi_task.rb +14 -0
  277. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/name_space.rb +38 -0
  278. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/packagetask.rb +222 -0
  279. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/phony.rb +16 -0
  280. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/private_reader.rb +21 -0
  281. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/promise.rb +100 -0
  282. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/pseudo_status.rb +30 -0
  283. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rake_module.rb +67 -0
  284. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rake_test_loader.rb +27 -0
  285. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/rule_recursion_overflow_error.rb +20 -0
  286. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/scope.rb +43 -0
  287. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task.rb +434 -0
  288. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_argument_error.rb +8 -0
  289. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_arguments.rb +109 -0
  290. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/task_manager.rb +331 -0
  291. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/tasklib.rb +12 -0
  292. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/testtask.rb +189 -0
  293. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/thread_history_display.rb +49 -0
  294. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/thread_pool.rb +163 -0
  295. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/trace_output.rb +23 -0
  296. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/version.rb +10 -0
  297. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake/win32.rb +51 -0
  298. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/lib/rake.rb +70 -0
  299. data/vendor/bundle/ruby/3.1.0/gems/rake-13.2.1/rake.gemspec +101 -0
  300. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.circleci/config.yml +46 -0
  301. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/Dockerfile +16 -0
  302. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/devcontainer.json +36 -0
  303. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.devcontainer/docker-compose.yml +19 -0
  304. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/FUNDING.yml +13 -0
  305. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  306. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  307. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.github/dependabot.yml +15 -0
  308. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.gitignore +69 -0
  309. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.rspec +3 -0
  310. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/.rubocop.yml +31 -0
  311. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CHANGELOG.md +467 -0
  312. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CODE_OF_CONDUCT.md +74 -0
  313. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/CONTRIBUTING.md +3 -0
  314. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Gemfile +12 -0
  315. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Gemfile.lock +92 -0
  316. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/LICENSE.txt +21 -0
  317. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/README.md +1381 -0
  318. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/Rakefile +19 -0
  319. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/bin/console +14 -0
  320. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/bin/setup +8 -0
  321. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/assistants.rb +29 -0
  322. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/audio.rb +19 -0
  323. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/batches.rb +23 -0
  324. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/client.rb +122 -0
  325. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/compatibility.rb +10 -0
  326. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/files.rb +75 -0
  327. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/finetunes.rb +27 -0
  328. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/http.rb +134 -0
  329. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/http_headers.rb +36 -0
  330. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/images.rb +27 -0
  331. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/messages.rb +27 -0
  332. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/models.rb +15 -0
  333. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/run_steps.rb +15 -0
  334. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/runs.rb +37 -0
  335. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/threads.rb +23 -0
  336. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_store_file_batches.rb +29 -0
  337. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_store_files.rb +23 -0
  338. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/vector_stores.rb +27 -0
  339. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai/version.rb +3 -0
  340. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/openai.rb +92 -0
  341. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/lib/ruby/openai.rb +2 -0
  342. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/pull_request_template.md +5 -0
  343. data/vendor/bundle/ruby/3.1.0/gems/ruby-openai-7.3.1/ruby-openai.gemspec +32 -0
  344. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/BSDL +24 -0
  345. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/COPYING +64 -0
  346. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/PSFL +271 -0
  347. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/README.md +108 -0
  348. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/Rakefile +74 -0
  349. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/getting-started.md +246 -0
  350. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/how-to.md +90 -0
  351. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/doc/text/news.md +1853 -0
  352. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/assertion-failed-error.rb +60 -0
  353. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/assertions.rb +2541 -0
  354. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/attribute-matcher.rb +26 -0
  355. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/attribute.rb +228 -0
  356. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/auto-runner-loader.rb +17 -0
  357. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/autorunner.rb +629 -0
  358. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/code-snippet-fetcher.rb +58 -0
  359. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/descendant.rb +20 -0
  360. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/dir.rb +110 -0
  361. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/load.rb +201 -0
  362. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/objectspace.rb +35 -0
  363. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector/xml.rb +249 -0
  364. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/collector.rb +104 -0
  365. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/color-scheme.rb +225 -0
  366. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/color.rb +134 -0
  367. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/data-sets.rb +127 -0
  368. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/data.rb +371 -0
  369. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/diff.rb +745 -0
  370. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/error.rb +158 -0
  371. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/exception-handler.rb +82 -0
  372. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/failure.rb +169 -0
  373. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/fault-location-detector.rb +104 -0
  374. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/fixture.rb +304 -0
  375. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/notification.rb +138 -0
  376. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/omission.rb +198 -0
  377. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/pending.rb +155 -0
  378. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/priority.rb +194 -0
  379. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/console.rb +86 -0
  380. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/emacs.rb +8 -0
  381. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/runner/xml.rb +15 -0
  382. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/sub-test-result.rb +59 -0
  383. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-creator.rb +103 -0
  384. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-runner.rb +128 -0
  385. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/test-suite-thread-runner.rb +69 -0
  386. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testcase.rb +963 -0
  387. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testresult.rb +132 -0
  388. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/testsuite.rb +108 -0
  389. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/console/outputlevel.rb +15 -0
  390. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/console/testrunner.rb +891 -0
  391. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  392. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunner.rb +53 -0
  393. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunnermediator.rb +119 -0
  394. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  395. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/ui/xml/testrunner.rb +224 -0
  396. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/backtracefilter.rb +59 -0
  397. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/memory-usage.rb +47 -0
  398. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/method-owner-finder.rb +28 -0
  399. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/observable.rb +86 -0
  400. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/output.rb +32 -0
  401. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/util/procwrapper.rb +48 -0
  402. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/version.rb +5 -0
  403. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit/warning.rb +3 -0
  404. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test/unit.rb +521 -0
  405. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/lib/test-unit.rb +19 -0
  406. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/adder.rb +13 -0
  407. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/subtracter.rb +12 -0
  408. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_adder.rb +20 -0
  409. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_subtracter.rb +20 -0
  410. data/vendor/bundle/ruby/3.1.0/gems/test-unit-3.6.7/sample/test_user.rb +23 -0
  411. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/.document +5 -0
  412. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/CONTRIBUTING.md +15 -0
  413. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/LICENSE.md +20 -0
  414. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/README.md +45 -0
  415. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/bin/thor +6 -0
  416. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/create_file.rb +105 -0
  417. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/create_link.rb +61 -0
  418. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/directory.rb +108 -0
  419. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/empty_directory.rb +143 -0
  420. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/file_manipulation.rb +371 -0
  421. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions/inject_into_file.rb +130 -0
  422. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/actions.rb +340 -0
  423. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/base.rb +825 -0
  424. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/command.rb +151 -0
  425. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/core_ext/hash_with_indifferent_access.rb +107 -0
  426. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/error.rb +106 -0
  427. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/group.rb +292 -0
  428. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/invocation.rb +178 -0
  429. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor/basic.rb +37 -0
  430. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor/readline.rb +88 -0
  431. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/line_editor.rb +17 -0
  432. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/nested_context.rb +29 -0
  433. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/argument.rb +86 -0
  434. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/arguments.rb +195 -0
  435. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/option.rb +178 -0
  436. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser/options.rb +294 -0
  437. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/parser.rb +4 -0
  438. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/rake_compat.rb +72 -0
  439. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/runner.rb +335 -0
  440. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/basic.rb +388 -0
  441. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/color.rb +115 -0
  442. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/column_printer.rb +29 -0
  443. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/html.rb +84 -0
  444. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/lcs_diff.rb +49 -0
  445. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/table_printer.rb +118 -0
  446. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/terminal.rb +42 -0
  447. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell/wrapped_printer.rb +38 -0
  448. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/shell.rb +81 -0
  449. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/util.rb +285 -0
  450. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor/version.rb +3 -0
  451. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/lib/thor.rb +674 -0
  452. data/vendor/bundle/ruby/3.1.0/gems/thor-1.3.2/thor.gemspec +33 -0
  453. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/BSDL +22 -0
  454. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/COPYING +56 -0
  455. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/README.md +55 -0
  456. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/common.rb +876 -0
  457. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/file.rb +100 -0
  458. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ftp.rb +267 -0
  459. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/generic.rb +1578 -0
  460. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/http.rb +125 -0
  461. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/https.rb +23 -0
  462. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ldap.rb +261 -0
  463. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ldaps.rb +22 -0
  464. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/mailto.rb +293 -0
  465. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/rfc2396_parser.rb +546 -0
  466. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/rfc3986_parser.rb +206 -0
  467. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/version.rb +6 -0
  468. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/ws.rb +83 -0
  469. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri/wss.rb +23 -0
  470. data/vendor/bundle/ruby/3.1.0/gems/uri-1.0.2/lib/uri.rb +104 -0
  471. data/vendor/bundle/ruby/3.1.0/specifications/event_stream_parser-1.0.0.gemspec +23 -0
  472. data/vendor/bundle/ruby/3.1.0/specifications/faraday-2.12.2.gemspec +0 -0
  473. data/vendor/bundle/ruby/3.1.0/specifications/faraday-multipart-1.1.0.gemspec +32 -0
  474. data/vendor/bundle/ruby/3.1.0/specifications/faraday-net_http-3.4.0.gemspec +32 -0
  475. data/vendor/bundle/ruby/3.1.0/specifications/json-2.9.1.gemspec +0 -0
  476. data/vendor/bundle/ruby/3.1.0/specifications/logger-1.6.5.gemspec +22 -0
  477. data/vendor/bundle/ruby/3.1.0/specifications/multipart-post-2.4.1.gemspec +21 -0
  478. data/vendor/bundle/ruby/3.1.0/specifications/net-http-0.6.0.gemspec +33 -0
  479. data/vendor/bundle/ruby/3.1.0/specifications/power_assert-2.0.5.gemspec +24 -0
  480. data/vendor/bundle/ruby/3.1.0/specifications/rake-13.2.1.gemspec +26 -0
  481. data/vendor/bundle/ruby/3.1.0/specifications/ruby-openai-7.3.1.gemspec +36 -0
  482. data/vendor/bundle/ruby/3.1.0/specifications/test-unit-3.6.7.gemspec +31 -0
  483. data/vendor/bundle/ruby/3.1.0/specifications/thor-1.3.2.gemspec +34 -0
  484. data/vendor/bundle/ruby/3.1.0/specifications/uri-1.0.2.gemspec +23 -0
  485. metadata +560 -0
@@ -0,0 +1,1381 @@
1
+ # Ruby OpenAI
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/ruby-openai.svg)](https://rubygems.org/gems/ruby-openai)
4
+ [![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/alexrudall/ruby-openai/blob/main/LICENSE.txt)
5
+ [![CircleCI Build Status](https://circleci.com/gh/alexrudall/ruby-openai.svg?style=shield)](https://circleci.com/gh/alexrudall/ruby-openai)
6
+
7
+ Use the [OpenAI API](https://openai.com/blog/openai-api/) with Ruby! 🤖❤️
8
+
9
+ Stream text with GPT-4o, transcribe and translate audio with Whisper, or create images with DALL·E...
10
+
11
+ [📚 Rails AI (FREE Book)](https://railsai.com) | [🎮 Ruby AI Builders Discord](https://discord.gg/k4Uc224xVD) | [🐦 X](https://x.com/alexrudall) | [🧠 Anthropic Gem](https://github.com/alexrudall/anthropic) | [🚂 Midjourney Gem](https://github.com/alexrudall/midjourney)
12
+
13
+ ## Contents
14
+
15
+ - [Ruby OpenAI](#ruby-openai)
16
+ - [Table of Contents](#table-of-contents)
17
+ - [Installation](#installation)
18
+ - [Bundler](#bundler)
19
+ - [Gem install](#gem-install)
20
+ - [Usage](#usage)
21
+ - [Quickstart](#quickstart)
22
+ - [With Config](#with-config)
23
+ - [Custom timeout or base URI](#custom-timeout-or-base-uri)
24
+ - [Extra Headers per Client](#extra-headers-per-client)
25
+ - [Logging](#logging)
26
+ - [Errors](#errors)
27
+ - [Faraday middleware](#faraday-middleware)
28
+ - [Azure](#azure)
29
+ - [Ollama](#ollama)
30
+ - [Groq](#groq)
31
+ - [Counting Tokens](#counting-tokens)
32
+ - [Models](#models)
33
+ - [Chat](#chat)
34
+ - [Streaming Chat](#streaming-chat)
35
+ - [Vision](#vision)
36
+ - [JSON Mode](#json-mode)
37
+ - [Functions](#functions)
38
+ - [Completions](#completions)
39
+ - [Embeddings](#embeddings)
40
+ - [Batches](#batches)
41
+ - [Files](#files)
42
+ - [For fine-tuning purposes](#for-fine-tuning-purposes)
43
+ - [For assistant purposes](#for-assistant-purposes)
44
+ - [Finetunes](#finetunes)
45
+ - [Vector Stores](#vector-stores)
46
+ - [Vector Store Files](#vector-store-files)
47
+ - [Vector Store File Batches](#vector-store-file-batches)
48
+ - [Assistants](#assistants)
49
+ - [Threads and Messages](#threads-and-messages)
50
+ - [Runs](#runs)
51
+ - [Create and Run](#create-and-run)
52
+ - [Runs involving function tools](#runs-involving-function-tools)
53
+ - [Exploring chunks used in File Search](#exploring-chunks-used-in-file-search)
54
+ - [Image Generation](#image-generation)
55
+ - [DALL·E 2](#dalle-2)
56
+ - [DALL·E 3](#dalle-3)
57
+ - [Image Edit](#image-edit)
58
+ - [Image Variations](#image-variations)
59
+ - [Moderations](#moderations)
60
+ - [Whisper](#whisper)
61
+ - [Translate](#translate)
62
+ - [Transcribe](#transcribe)
63
+ - [Speech](#speech)
64
+ - [Errors](#errors-1)
65
+ - [Development](#development)
66
+ - [Release](#release)
67
+ - [Contributing](#contributing)
68
+ - [License](#license)
69
+ - [Code of Conduct](#code-of-conduct)
70
+
71
+ ## Installation
72
+
73
+ ### Bundler
74
+
75
+ Add this line to your application's Gemfile:
76
+
77
+ ```ruby
78
+ gem "ruby-openai"
79
+ ```
80
+
81
+ And then execute:
82
+
83
+ ```bash
84
+ $ bundle install
85
+ ```
86
+
87
+ ### Gem install
88
+
89
+ Or install with:
90
+
91
+ ```bash
92
+ $ gem install ruby-openai
93
+ ```
94
+
95
+ and require with:
96
+
97
+ ```ruby
98
+ require "openai"
99
+ ```
100
+
101
+ ## Usage
102
+
103
+ - Get your API key from [https://platform.openai.com/account/api-keys](https://platform.openai.com/account/api-keys)
104
+ - If you belong to multiple organizations, you can get your Organization ID from [https://platform.openai.com/account/org-settings](https://platform.openai.com/account/org-settings)
105
+
106
+ ### Quickstart
107
+
108
+ For a quick test you can pass your token directly to a new client:
109
+
110
+ ```ruby
111
+ client = OpenAI::Client.new(
112
+ access_token: "access_token_goes_here",
113
+ log_errors: true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production because it could leak private data to your logs.
114
+ )
115
+ ```
116
+
117
+ ### With Config
118
+
119
+ For a more robust setup, you can configure the gem with your API keys, for example in an `openai.rb` initializer file. Never hardcode secrets into your codebase - instead use something like [dotenv](https://github.com/motdotla/dotenv) to pass the keys safely into your environments.
120
+
121
+ ```ruby
122
+ OpenAI.configure do |config|
123
+ config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN")
124
+ config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional
125
+ config.log_errors = true # Highly recommended in development, so you can see what errors OpenAI is returning. Not recommended in production because it could leak private data to your logs.
126
+ end
127
+ ```
128
+
129
+ Then you can create a client like this:
130
+
131
+ ```ruby
132
+ client = OpenAI::Client.new
133
+ ```
134
+
135
+ You can still override the config defaults when making new clients; any options not included will fall back to any global config set with OpenAI.configure. e.g. in this example the organization_id, request_timeout, etc. will fallback to any set globally using OpenAI.configure, with only the access_token overridden:
136
+
137
+ ```ruby
138
+ client = OpenAI::Client.new(access_token: "access_token_goes_here")
139
+ ```
140
+
141
+ #### Custom timeout or base URI
142
+
143
+ - The default timeout for any request using this library is 120 seconds. You can change that by passing a number of seconds to the `request_timeout` when initializing the client.
144
+ - You can also change the base URI used for all requests, eg. to use observability tools like [Helicone](https://docs.helicone.ai/quickstart/integrate-in-one-line-of-code) or [Velvet](https://docs.usevelvet.com/docs/getting-started)
145
+ - You can also add arbitrary other headers e.g. for [openai-caching-proxy-worker](https://github.com/6/openai-caching-proxy-worker), eg.:
146
+
147
+ ```ruby
148
+ client = OpenAI::Client.new(
149
+ access_token: "access_token_goes_here",
150
+ uri_base: "https://oai.hconeai.com/",
151
+ request_timeout: 240,
152
+ extra_headers: {
153
+ "X-Proxy-TTL" => "43200", # For https://github.com/6/openai-caching-proxy-worker#specifying-a-cache-ttl
154
+ "X-Proxy-Refresh": "true", # For https://github.com/6/openai-caching-proxy-worker#refreshing-the-cache
155
+ "Helicone-Auth": "Bearer HELICONE_API_KEY", # For https://docs.helicone.ai/getting-started/integration-method/openai-proxy
156
+ "helicone-stream-force-format" => "true", # Use this with Helicone otherwise streaming drops chunks # https://github.com/alexrudall/ruby-openai/issues/251
157
+ }
158
+ )
159
+ ```
160
+
161
+ or when configuring the gem:
162
+
163
+ ```ruby
164
+ OpenAI.configure do |config|
165
+ config.access_token = ENV.fetch("OPENAI_ACCESS_TOKEN")
166
+ config.log_errors = true # Optional
167
+ config.organization_id = ENV.fetch("OPENAI_ORGANIZATION_ID") # Optional
168
+ config.uri_base = "https://oai.hconeai.com/" # Optional
169
+ config.request_timeout = 240 # Optional
170
+ config.extra_headers = {
171
+ "X-Proxy-TTL" => "43200", # For https://github.com/6/openai-caching-proxy-worker#specifying-a-cache-ttl
172
+ "X-Proxy-Refresh": "true", # For https://github.com/6/openai-caching-proxy-worker#refreshing-the-cache
173
+ "Helicone-Auth": "Bearer HELICONE_API_KEY" # For https://docs.helicone.ai/getting-started/integration-method/openai-proxy
174
+ } # Optional
175
+ end
176
+ ```
177
+
178
+ #### Extra Headers per Client
179
+
180
+ You can dynamically pass headers per client object, which will be merged with any headers set globally with OpenAI.configure:
181
+
182
+ ```ruby
183
+ client = OpenAI::Client.new(access_token: "access_token_goes_here")
184
+ client.add_headers("X-Proxy-TTL" => "43200")
185
+ ```
186
+
187
+ #### Logging
188
+
189
+ ##### Errors
190
+
191
+ By default, `ruby-openai` does not log any `Faraday::Error`s encountered while executing a network request to avoid leaking data (e.g. 400s, 500s, SSL errors and more - see [here](https://www.rubydoc.info/github/lostisland/faraday/Faraday/Error) for a complete list of subclasses of `Faraday::Error` and what can cause them).
192
+
193
+ If you would like to enable this functionality, you can set `log_errors` to `true` when configuring the client:
194
+
195
+ ```ruby
196
+ client = OpenAI::Client.new(log_errors: true)
197
+ ```
198
+
199
+ ##### Faraday middleware
200
+
201
+ You can pass [Faraday middleware](https://lostisland.github.io/faraday/#/middleware/index) to the client in a block, eg. to enable verbose logging with Ruby's [Logger](https://ruby-doc.org/3.2.2/stdlibs/logger/Logger.html):
202
+
203
+ ```ruby
204
+ client = OpenAI::Client.new do |f|
205
+ f.response :logger, Logger.new($stdout), bodies: true
206
+ end
207
+ ```
208
+
209
+ #### Azure
210
+
211
+ To use the [Azure OpenAI Service](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/) API, you can configure the gem like this:
212
+
213
+ ```ruby
214
+ OpenAI.configure do |config|
215
+ config.access_token = ENV.fetch("AZURE_OPENAI_API_KEY")
216
+ config.uri_base = ENV.fetch("AZURE_OPENAI_URI")
217
+ config.api_type = :azure
218
+ config.api_version = "2023-03-15-preview"
219
+ end
220
+ ```
221
+
222
+ where `AZURE_OPENAI_URI` is e.g. `https://custom-domain.openai.azure.com/openai/deployments/gpt-35-turbo`
223
+
224
+ #### Ollama
225
+
226
+ Ollama allows you to run open-source LLMs, such as Llama 3, locally. It [offers chat compatibility](https://github.com/ollama/ollama/blob/main/docs/openai.md) with the OpenAI API.
227
+
228
+ You can download Ollama [here](https://ollama.com/). On macOS you can install and run Ollama like this:
229
+
230
+ ```bash
231
+ brew install ollama
232
+ ollama serve
233
+ ollama pull llama3:latest # In new terminal tab.
234
+ ```
235
+
236
+ Create a client using your Ollama server and the pulled model, and stream a conversation for free:
237
+
238
+ ```ruby
239
+ client = OpenAI::Client.new(
240
+ uri_base: "http://localhost:11434"
241
+ )
242
+
243
+ client.chat(
244
+ parameters: {
245
+ model: "llama3", # Required.
246
+ messages: [{ role: "user", content: "Hello!"}], # Required.
247
+ temperature: 0.7,
248
+ stream: proc do |chunk, _bytesize|
249
+ print chunk.dig("choices", 0, "delta", "content")
250
+ end
251
+ })
252
+
253
+ # => Hi! It's nice to meet you. Is there something I can help you with, or would you like to chat?
254
+ ```
255
+
256
+ #### Groq
257
+
258
+ [Groq API Chat](https://console.groq.com/docs/quickstart) is broadly compatible with the OpenAI API, with a [few minor differences](https://console.groq.com/docs/openai). Get an access token from [here](https://console.groq.com/keys), then:
259
+
260
+ ```ruby
261
+ client = OpenAI::Client.new(
262
+ access_token: "groq_access_token_goes_here",
263
+ uri_base: "https://api.groq.com/openai"
264
+ )
265
+
266
+ client.chat(
267
+ parameters: {
268
+ model: "llama3-8b-8192", # Required.
269
+ messages: [{ role: "user", content: "Hello!"}], # Required.
270
+ temperature: 0.7,
271
+ stream: proc do |chunk, _bytesize|
272
+ print chunk.dig("choices", 0, "delta", "content")
273
+ end
274
+ })
275
+ ```
276
+
277
+ ### Counting Tokens
278
+
279
+ OpenAI parses prompt text into [tokens](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them), which are words or portions of words. (These tokens are unrelated to your API access_token.) Counting tokens can help you estimate your [costs](https://openai.com/pricing). It can also help you ensure your prompt text size is within the max-token limits of your model's context window, and choose an appropriate [`max_tokens`](https://platform.openai.com/docs/api-reference/chat/create#chat/create-max_tokens) completion parameter so your response will fit as well.
280
+
281
+ To estimate the token-count of your text:
282
+
283
+ ```ruby
284
+ OpenAI.rough_token_count("Your text")
285
+ ```
286
+
287
+ If you need a more accurate count, try [tiktoken_ruby](https://github.com/IAPark/tiktoken_ruby).
288
+
289
+ ### Models
290
+
291
+ There are different models that can be used to generate text. For a full list and to retrieve information about a single model:
292
+
293
+ ```ruby
294
+ client.models.list
295
+ client.models.retrieve(id: "gpt-4o")
296
+ ```
297
+
298
+ ### Chat
299
+
300
+ GPT is a model that can be used to generate text in a conversational style. You can use it to [generate a response](https://platform.openai.com/docs/api-reference/chat/create) to a sequence of [messages](https://platform.openai.com/docs/guides/chat/introduction):
301
+
302
+ ```ruby
303
+ response = client.chat(
304
+ parameters: {
305
+ model: "gpt-4o", # Required.
306
+ messages: [{ role: "user", content: "Hello!"}], # Required.
307
+ temperature: 0.7,
308
+ })
309
+ puts response.dig("choices", 0, "message", "content")
310
+ # => "Hello! How may I assist you today?"
311
+ ```
312
+
313
+ #### Streaming Chat
314
+
315
+ [Quick guide to streaming Chat with Rails 7 and Hotwire](https://gist.github.com/alexrudall/cb5ee1e109353ef358adb4e66631799d)
316
+
317
+ You can stream from the API in realtime, which can be much faster and used to create a more engaging user experience. Pass a [Proc](https://ruby-doc.org/core-2.6/Proc.html) (or any object with a `#call` method) to the `stream` parameter to receive the stream of completion chunks as they are generated. Each time one or more chunks is received, the proc will be called once with each chunk, parsed as a Hash. If OpenAI returns an error, `ruby-openai` will raise a Faraday error.
318
+
319
+ ```ruby
320
+ client.chat(
321
+ parameters: {
322
+ model: "gpt-4o", # Required.
323
+ messages: [{ role: "user", content: "Describe a character called Anna!"}], # Required.
324
+ temperature: 0.7,
325
+ stream: proc do |chunk, _bytesize|
326
+ print chunk.dig("choices", 0, "delta", "content")
327
+ end
328
+ })
329
+ # => "Anna is a young woman in her mid-twenties, with wavy chestnut hair that falls to her shoulders..."
330
+ ```
331
+
332
+ Note: In order to get usage information, you can provide the [`stream_options` parameter](https://platform.openai.com/docs/api-reference/chat/create#chat-create-stream_options) and OpenAI will provide a final chunk with the usage. Here is an example:
333
+
334
+ ```ruby
335
+ stream_proc = proc { |chunk, _bytesize| puts "--------------"; puts chunk.inspect; }
336
+ client.chat(
337
+ parameters: {
338
+ model: "gpt-4o",
339
+ stream: stream_proc,
340
+ stream_options: { include_usage: true },
341
+ messages: [{ role: "user", content: "Hello!"}],
342
+ })
343
+ # => --------------
344
+ # => {"id"=>"chatcmpl-7bbq05PiZqlHxjV1j7OHnKKDURKaf", "object"=>"chat.completion.chunk", "created"=>1718750612, "model"=>"gpt-4o-2024-05-13", "system_fingerprint"=>"fp_9cb5d38cf7", "choices"=>[{"index"=>0, "delta"=>{"role"=>"assistant", "content"=>""}, "logprobs"=>nil, "finish_reason"=>nil}], "usage"=>nil}
345
+ # => --------------
346
+ # => {"id"=>"chatcmpl-7bbq05PiZqlHxjV1j7OHnKKDURKaf", "object"=>"chat.completion.chunk", "created"=>1718750612, "model"=>"gpt-4o-2024-05-13", "system_fingerprint"=>"fp_9cb5d38cf7", "choices"=>[{"index"=>0, "delta"=>{"content"=>"Hello"}, "logprobs"=>nil, "finish_reason"=>nil}], "usage"=>nil}
347
+ # => --------------
348
+ # => ... more content chunks
349
+ # => --------------
350
+ # => {"id"=>"chatcmpl-7bbq05PiZqlHxjV1j7OHnKKDURKaf", "object"=>"chat.completion.chunk", "created"=>1718750612, "model"=>"gpt-4o-2024-05-13", "system_fingerprint"=>"fp_9cb5d38cf7", "choices"=>[{"index"=>0, "delta"=>{}, "logprobs"=>nil, "finish_reason"=>"stop"}], "usage"=>nil}
351
+ # => --------------
352
+ # => {"id"=>"chatcmpl-7bbq05PiZqlHxjV1j7OHnKKDURKaf", "object"=>"chat.completion.chunk", "created"=>1718750612, "model"=>"gpt-4o-2024-05-13", "system_fingerprint"=>"fp_9cb5d38cf7", "choices"=>[], "usage"=>{"prompt_tokens"=>9, "completion_tokens"=>9, "total_tokens"=>18}}
353
+ ```
354
+
355
+ #### Vision
356
+
357
+ You can use the GPT-4 Vision model to generate a description of an image:
358
+
359
+ ```ruby
360
+ messages = [
361
+ { "type": "text", "text": "What’s in this image?"},
362
+ { "type": "image_url",
363
+ "image_url": {
364
+ "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
365
+ },
366
+ }
367
+ ]
368
+ response = client.chat(
369
+ parameters: {
370
+ model: "gpt-4-vision-preview", # Required.
371
+ messages: [{ role: "user", content: messages}], # Required.
372
+ })
373
+ puts response.dig("choices", 0, "message", "content")
374
+ # => "The image depicts a serene natural landscape featuring a long wooden boardwalk extending straight ahead"
375
+ ```
376
+
377
+ #### JSON Mode
378
+
379
+ You can set the response_format to ask for responses in JSON:
380
+
381
+ ```ruby
382
+ response = client.chat(
383
+ parameters: {
384
+ model: "gpt-4o",
385
+ response_format: { type: "json_object" },
386
+ messages: [{ role: "user", content: "Hello! Give me some JSON please."}],
387
+ temperature: 0.7,
388
+ })
389
+ puts response.dig("choices", 0, "message", "content")
390
+ {
391
+ "name": "John",
392
+ "age": 30,
393
+ "city": "New York",
394
+ "hobbies": ["reading", "traveling", "hiking"],
395
+ "isStudent": false
396
+ }
397
+ ```
398
+
399
+ You can stream it as well!
400
+
401
+ ```ruby
402
+ response = client.chat(
403
+ parameters: {
404
+ model: "gpt-4o",
405
+ messages: [{ role: "user", content: "Can I have some JSON please?"}],
406
+ response_format: { type: "json_object" },
407
+ stream: proc do |chunk, _bytesize|
408
+ print chunk.dig("choices", 0, "delta", "content")
409
+ end
410
+ })
411
+ {
412
+ "message": "Sure, please let me know what specific JSON data you are looking for.",
413
+ "JSON_data": {
414
+ "example_1": {
415
+ "key_1": "value_1",
416
+ "key_2": "value_2",
417
+ "key_3": "value_3"
418
+ },
419
+ "example_2": {
420
+ "key_4": "value_4",
421
+ "key_5": "value_5",
422
+ "key_6": "value_6"
423
+ }
424
+ }
425
+ }
426
+ ```
427
+
428
+ ### Functions
429
+
430
+ You can describe and pass in functions and the model will intelligently choose to output a JSON object containing arguments to call them - eg., to use your method `get_current_weather` to get the weather in a given location. Note that tool_choice is optional, but if you exclude it, the model will choose whether to use the function or not ([see here](https://platform.openai.com/docs/api-reference/chat/create#chat-create-tool_choice)).
431
+
432
+ ```ruby
433
+
434
+ def get_current_weather(location:, unit: "fahrenheit")
435
+ # Here you could use a weather api to fetch the weather.
436
+ "The weather in #{location} is nice 🌞 #{unit}"
437
+ end
438
+
439
+ messages = [
440
+ {
441
+ "role": "user",
442
+ "content": "What is the weather like in San Francisco?",
443
+ },
444
+ ]
445
+
446
+ response =
447
+ client.chat(
448
+ parameters: {
449
+ model: "gpt-4o",
450
+ messages: messages, # Defined above because we'll use it again
451
+ tools: [
452
+ {
453
+ type: "function",
454
+ function: {
455
+ name: "get_current_weather",
456
+ description: "Get the current weather in a given location",
457
+ parameters: { # Format: https://json-schema.org/understanding-json-schema
458
+ type: :object,
459
+ properties: {
460
+ location: {
461
+ type: :string,
462
+ description: "The city and state, e.g. San Francisco, CA",
463
+ },
464
+ unit: {
465
+ type: "string",
466
+ enum: %w[celsius fahrenheit],
467
+ },
468
+ },
469
+ required: ["location"],
470
+ },
471
+ },
472
+ }
473
+ ],
474
+ tool_choice: "required" # Optional, defaults to "auto"
475
+ # Can also put "none" or specific functions, see docs
476
+ },
477
+ )
478
+
479
+ message = response.dig("choices", 0, "message")
480
+
481
+ if message["role"] == "assistant" && message["tool_calls"]
482
+ message["tool_calls"].each do |tool_call|
483
+ tool_call_id = tool_call.dig("id")
484
+ function_name = tool_call.dig("function", "name")
485
+ function_args = JSON.parse(
486
+ tool_call.dig("function", "arguments"),
487
+ { symbolize_names: true },
488
+ )
489
+ function_response = case function_name
490
+ when "get_current_weather"
491
+ get_current_weather(**function_args) # => "The weather is nice 🌞"
492
+ else
493
+ # decide how to handle
494
+ end
495
+
496
+ # For a subsequent message with the role "tool", OpenAI requires the preceding message to have a tool_calls argument.
497
+ messages << message
498
+
499
+ messages << {
500
+ tool_call_id: tool_call_id,
501
+ role: "tool",
502
+ name: function_name,
503
+ content: function_response
504
+ } # Extend the conversation with the results of the functions
505
+ end
506
+
507
+ second_response = client.chat(
508
+ parameters: {
509
+ model: "gpt-4o",
510
+ messages: messages
511
+ })
512
+
513
+ puts second_response.dig("choices", 0, "message", "content")
514
+
515
+ # At this point, the model has decided to call functions, you've called the functions
516
+ # and provided the response back, and the model has considered this and responded.
517
+ end
518
+ # => "It looks like the weather is nice and sunny in San Francisco! If you're planning to go out, it should be a pleasant day."
519
+ ```
520
+
521
+ ### Completions
522
+
523
+ Hit the OpenAI API for a completion using other GPT-3 models:
524
+
525
+ ```ruby
526
+ response = client.completions(
527
+ parameters: {
528
+ model: "gpt-4o",
529
+ prompt: "Once upon a time",
530
+ max_tokens: 5
531
+ })
532
+ puts response["choices"].map { |c| c["text"] }
533
+ # => [", there lived a great"]
534
+ ```
535
+
536
+ ### Embeddings
537
+
538
+ You can use the embeddings endpoint to get a vector of numbers representing an input. You can then compare these vectors for different inputs to efficiently check how similar the inputs are.
539
+
540
+ ```ruby
541
+ response = client.embeddings(
542
+ parameters: {
543
+ model: "text-embedding-ada-002",
544
+ input: "The food was delicious and the waiter..."
545
+ }
546
+ )
547
+
548
+ puts response.dig("data", 0, "embedding")
549
+ # => Vector representation of your embedding
550
+ ```
551
+
552
+ ### Batches
553
+
554
+ The Batches endpoint allows you to create and manage large batches of API requests to run asynchronously. Currently, the supported endpoints for batches are `/v1/chat/completions` (Chat Completions API) and `/v1/embeddings` (Embeddings API).
555
+
556
+ To use the Batches endpoint, you need to first upload a JSONL file containing the batch requests using the Files endpoint. The file must be uploaded with the purpose set to `batch`. Each line in the JSONL file represents a single request and should have the following format:
557
+
558
+ ```json
559
+ {
560
+ "custom_id": "request-1",
561
+ "method": "POST",
562
+ "url": "/v1/chat/completions",
563
+ "body": {
564
+ "model": "gpt-4o",
565
+ "messages": [
566
+ { "role": "system", "content": "You are a helpful assistant." },
567
+ { "role": "user", "content": "What is 2+2?" }
568
+ ]
569
+ }
570
+ }
571
+ ```
572
+
573
+ Once you have uploaded the JSONL file, you can create a new batch by providing the file ID, endpoint, and completion window:
574
+
575
+ ```ruby
576
+ response = client.batches.create(
577
+ parameters: {
578
+ input_file_id: "file-abc123",
579
+ endpoint: "/v1/chat/completions",
580
+ completion_window: "24h"
581
+ }
582
+ )
583
+ batch_id = response["id"]
584
+ ```
585
+
586
+ You can retrieve information about a specific batch using its ID:
587
+
588
+ ```ruby
589
+ batch = client.batches.retrieve(id: batch_id)
590
+ ```
591
+
592
+ To cancel a batch that is in progress:
593
+
594
+ ```ruby
595
+ client.batches.cancel(id: batch_id)
596
+ ```
597
+
598
+ You can also list all the batches:
599
+
600
+ ```ruby
601
+ client.batches.list
602
+ ```
603
+
604
+ Once the batch["completed_at"] is present, you can fetch the output or error files:
605
+
606
+ ```ruby
607
+ batch = client.batches.retrieve(id: batch_id)
608
+ output_file_id = batch["output_file_id"]
609
+ output_response = client.files.content(id: output_file_id)
610
+ error_file_id = batch["error_file_id"]
611
+ error_response = client.files.content(id: error_file_id)
612
+ ```
613
+
614
+ These files are in JSONL format, with each line representing the output or error for a single request. The lines can be in any order:
615
+
616
+ ```json
617
+ {
618
+ "id": "response-1",
619
+ "custom_id": "request-1",
620
+ "response": {
621
+ "id": "chatcmpl-abc123",
622
+ "object": "chat.completion",
623
+ "created": 1677858242,
624
+ "model": "gpt-4o",
625
+ "choices": [
626
+ {
627
+ "index": 0,
628
+ "message": {
629
+ "role": "assistant",
630
+ "content": "2+2 equals 4."
631
+ }
632
+ }
633
+ ]
634
+ }
635
+ }
636
+ ```
637
+
638
+ If a request fails with a non-HTTP error, the error object will contain more information about the cause of the failure.
639
+
640
+ ### Files
641
+
642
+ #### For fine-tuning purposes
643
+
644
+ Put your data in a `.jsonl` file like this:
645
+
646
+ ```json
647
+ {"prompt":"Overjoyed with my new phone! ->", "completion":" positive"}
648
+ {"prompt":"@lakers disappoint for a third straight night ->", "completion":" negative"}
649
+ ```
650
+
651
+ and pass the path (or a StringIO object) to `client.files.upload` to upload it to OpenAI, and then interact with it:
652
+
653
+ ```ruby
654
+ client.files.upload(parameters: { file: "path/to/sentiment.jsonl", purpose: "fine-tune" })
655
+ client.files.list
656
+ client.files.retrieve(id: "file-123")
657
+ client.files.content(id: "file-123")
658
+ client.files.delete(id: "file-123")
659
+ ```
660
+
661
+ #### For assistant purposes
662
+
663
+ You can send a file path:
664
+
665
+ ```ruby
666
+ client.files.upload(parameters: { file: "path/to/file.pdf", purpose: "assistants" })
667
+ ```
668
+
669
+ or a File object
670
+
671
+ ```ruby
672
+ my_file = File.open("path/to/file.pdf", "rb")
673
+ client.files.upload(parameters: { file: my_file, purpose: "assistants" })
674
+ ```
675
+
676
+ See supported file types on [API documentation](https://platform.openai.com/docs/assistants/tools/file-search/supported-files).
677
+
678
+ ### Finetunes
679
+
680
+ Upload your fine-tuning data in a `.jsonl` file as above and get its ID:
681
+
682
+ ```ruby
683
+ response = client.files.upload(parameters: { file: "path/to/sarcasm.jsonl", purpose: "fine-tune" })
684
+ file_id = JSON.parse(response.body)["id"]
685
+ ```
686
+
687
+ You can then use this file ID to create a fine tuning job:
688
+
689
+ ```ruby
690
+ response = client.finetunes.create(
691
+ parameters: {
692
+ training_file: file_id,
693
+ model: "gpt-4o"
694
+ })
695
+ fine_tune_id = response["id"]
696
+ ```
697
+
698
+ That will give you the fine-tune ID. If you made a mistake you can cancel the fine-tune model before it is processed:
699
+
700
+ ```ruby
701
+ client.finetunes.cancel(id: fine_tune_id)
702
+ ```
703
+
704
+ You may need to wait a short time for processing to complete. Once processed, you can use list or retrieve to get the name of the fine-tuned model:
705
+
706
+ ```ruby
707
+ client.finetunes.list
708
+ response = client.finetunes.retrieve(id: fine_tune_id)
709
+ fine_tuned_model = response["fine_tuned_model"]
710
+ ```
711
+
712
+ This fine-tuned model name can then be used in chat completions:
713
+
714
+ ```ruby
715
+ response = client.chat(
716
+ parameters: {
717
+ model: fine_tuned_model,
718
+ messages: [{ role: "user", content: "I love Mondays!"}]
719
+ }
720
+ )
721
+ response.dig("choices", 0, "message", "content")
722
+ ```
723
+
724
+ You can also capture the events for a job:
725
+
726
+ ```
727
+ client.finetunes.list_events(id: fine_tune_id)
728
+ ```
729
+
730
+ ### Vector Stores
731
+
732
+ Vector Store objects give the File Search tool the ability to search your files.
733
+
734
+ You can create a new vector store:
735
+
736
+ ```ruby
737
+ response = client.vector_stores.create(
738
+ parameters: {
739
+ name: "my vector store",
740
+ file_ids: ["file-abc123", "file-def456"]
741
+ }
742
+ )
743
+
744
+ vector_store_id = response["id"]
745
+ ```
746
+
747
+ Given a `vector_store_id` you can `retrieve` the current field values:
748
+
749
+ ```ruby
750
+ client.vector_stores.retrieve(id: vector_store_id)
751
+ ```
752
+
753
+ You can get a `list` of all vector stores currently available under the organization:
754
+
755
+ ```ruby
756
+ client.vector_stores.list
757
+ ```
758
+
759
+ You can modify an existing vector store, except for the `file_ids`:
760
+
761
+ ```ruby
762
+ response = client.vector_stores.modify(
763
+ id: vector_store_id,
764
+ parameters: {
765
+ name: "Modified Test Vector Store",
766
+ }
767
+ )
768
+ ```
769
+
770
+ You can delete vector stores:
771
+
772
+ ```ruby
773
+ client.vector_stores.delete(id: vector_store_id)
774
+ ```
775
+
776
+ ### Vector Store Files
777
+
778
+ Vector store files represent files inside a vector store.
779
+
780
+ You can create a new vector store file by attaching a File to a vector store.
781
+
782
+ ```ruby
783
+ response = client.vector_store_files.create(
784
+ vector_store_id: "vector-store-abc123",
785
+ parameters: {
786
+ file_id: "file-abc123"
787
+ }
788
+ )
789
+
790
+ vector_store_file_id = response["id"]
791
+ ```
792
+
793
+ Given a `vector_store_file_id` you can `retrieve` the current field values:
794
+
795
+ ```ruby
796
+ client.vector_store_files.retrieve(
797
+ vector_store_id: "vector-store-abc123",
798
+ id: vector_store_file_id
799
+ )
800
+ ```
801
+
802
+ You can get a `list` of all vector store files currently available under the vector store:
803
+
804
+ ```ruby
805
+ client.vector_store_files.list(vector_store_id: "vector-store-abc123")
806
+ ```
807
+
808
+ You can delete a vector store file:
809
+
810
+ ```ruby
811
+ client.vector_store_files.delete(
812
+ vector_store_id: "vector-store-abc123",
813
+ id: vector_store_file_id
814
+ )
815
+ ```
816
+
817
+ Note: This will remove the file from the vector store but the file itself will not be deleted. To delete the file, use the delete file endpoint.
818
+
819
+ ### Vector Store File Batches
820
+
821
+ Vector store file batches represent operations to add multiple files to a vector store.
822
+
823
+ You can create a new vector store file batch by attaching multiple Files to a vector store.
824
+
825
+ ```ruby
826
+ response = client.vector_store_file_batches.create(
827
+ vector_store_id: "vector-store-abc123",
828
+ parameters: {
829
+ file_ids: ["file-abc123", "file-def456"]
830
+ }
831
+ )
832
+
833
+ file_batch_id = response["id"]
834
+ ```
835
+
836
+ Given a `file_batch_id` you can `retrieve` the current field values:
837
+
838
+ ```ruby
839
+ client.vector_store_file_batches.retrieve(
840
+ vector_store_id: "vector-store-abc123",
841
+ id: file_batch_id
842
+ )
843
+ ```
844
+
845
+ You can get a `list` of all vector store files in a batch currently available under the vector store:
846
+
847
+ ```ruby
848
+ client.vector_store_file_batches.list(
849
+ vector_store_id: "vector-store-abc123",
850
+ id: file_batch_id
851
+ )
852
+ ```
853
+
854
+ You can cancel a vector store file batch (This attempts to cancel the processing of files in this batch as soon as possible):
855
+
856
+ ```ruby
857
+ client.vector_store_file_batches.cancel(
858
+ vector_store_id: "vector-store-abc123",
859
+ id: file_batch_id
860
+ )
861
+ ```
862
+
863
+ ### Assistants
864
+
865
+ Assistants are stateful actors that can have many conversations and use tools to perform tasks (see [Assistant Overview](https://platform.openai.com/docs/assistants/overview)).
866
+
867
+ To create a new assistant:
868
+
869
+ ```ruby
870
+ response = client.assistants.create(
871
+ parameters: {
872
+ model: "gpt-4o",
873
+ name: "OpenAI-Ruby test assistant",
874
+ description: nil,
875
+ instructions: "You are a Ruby dev bot. When asked a question, write and run Ruby code to answer the question",
876
+ tools: [
877
+ { type: "code_interpreter" },
878
+ { type: "file_search" }
879
+ ],
880
+ tool_resources: {
881
+ code_interpreter: {
882
+ file_ids: [] # See Files section above for how to upload files
883
+ },
884
+ file_search: {
885
+ vector_store_ids: [] # See Vector Stores section above for how to add vector stores
886
+ }
887
+ },
888
+ "metadata": { my_internal_version_id: "1.0.0" }
889
+ })
890
+ assistant_id = response["id"]
891
+ ```
892
+
893
+ Given an `assistant_id` you can `retrieve` the current field values:
894
+
895
+ ```ruby
896
+ client.assistants.retrieve(id: assistant_id)
897
+ ```
898
+
899
+ You can get a `list` of all assistants currently available under the organization:
900
+
901
+ ```ruby
902
+ client.assistants.list
903
+ ```
904
+
905
+ You can modify an existing assistant using the assistant's id (see [API documentation](https://platform.openai.com/docs/api-reference/assistants/modifyAssistant)):
906
+
907
+ ```ruby
908
+ response = client.assistants.modify(
909
+ id: assistant_id,
910
+ parameters: {
911
+ name: "Modified Test Assistant for OpenAI-Ruby",
912
+ metadata: { my_internal_version_id: '1.0.1' }
913
+ })
914
+ ```
915
+
916
+ You can delete assistants:
917
+
918
+ ```
919
+ client.assistants.delete(id: assistant_id)
920
+ ```
921
+
922
+ ### Threads and Messages
923
+
924
+ Once you have created an assistant as described above, you need to prepare a `Thread` of `Messages` for the assistant to work on (see [introduction on Assistants](https://platform.openai.com/docs/assistants/how-it-works)). For example, as an initial setup you could do:
925
+
926
+ ```ruby
927
+ # Create thread
928
+ response = client.threads.create # Note: Once you create a thread, there is no way to list it
929
+ # or recover it currently (as of 2023-12-10). So hold onto the `id`
930
+ thread_id = response["id"]
931
+
932
+ # Add initial message from user (see https://platform.openai.com/docs/api-reference/messages/createMessage)
933
+ message_id = client.messages.create(
934
+ thread_id: thread_id,
935
+ parameters: {
936
+ role: "user", # Required for manually created messages
937
+ content: "Can you help me write an API library to interact with the OpenAI API please?"
938
+ })["id"]
939
+
940
+ # Retrieve individual message
941
+ message = client.messages.retrieve(thread_id: thread_id, id: message_id)
942
+
943
+ # Review all messages on the thread
944
+ messages = client.messages.list(thread_id: thread_id)
945
+ ```
946
+
947
+ To clean up after a thread is no longer needed:
948
+
949
+ ```ruby
950
+ # To delete the thread (and all associated messages):
951
+ client.threads.delete(id: thread_id)
952
+
953
+ client.messages.retrieve(thread_id: thread_id, id: message_id) # -> Fails after thread is deleted
954
+ ```
955
+
956
+ ### Runs
957
+
958
+ To submit a thread to be evaluated with the model of an assistant, create a `Run` as follows:
959
+
960
+ ```ruby
961
+ # Create run (will use instruction/model/tools from Assistant's definition)
962
+ response = client.runs.create(thread_id: thread_id,
963
+ parameters: {
964
+ assistant_id: assistant_id,
965
+ max_prompt_tokens: 256,
966
+ max_completion_tokens: 16
967
+ })
968
+ run_id = response['id']
969
+ ```
970
+
971
+ You can stream the message chunks as they come through:
972
+
973
+ ```ruby
974
+ client.runs.create(thread_id: thread_id,
975
+ parameters: {
976
+ assistant_id: assistant_id,
977
+ max_prompt_tokens: 256,
978
+ max_completion_tokens: 16,
979
+ stream: proc do |chunk, _bytesize|
980
+ print chunk.dig("delta", "content", 0, "text", "value") if chunk["object"] == "thread.message.delta"
981
+ end
982
+ })
983
+ ```
984
+
985
+ To get the status of a Run:
986
+
987
+ ```
988
+ response = client.runs.retrieve(id: run_id, thread_id: thread_id)
989
+ status = response['status']
990
+ ```
991
+
992
+ The `status` response can include the following strings `queued`, `in_progress`, `requires_action`, `cancelling`, `cancelled`, `failed`, `completed`, or `expired` which you can handle as follows:
993
+
994
+ ```ruby
995
+ while true do
996
+ response = client.runs.retrieve(id: run_id, thread_id: thread_id)
997
+ status = response['status']
998
+
999
+ case status
1000
+ when 'queued', 'in_progress', 'cancelling'
1001
+ puts 'Sleeping'
1002
+ sleep 1 # Wait one second and poll again
1003
+ when 'completed'
1004
+ break # Exit loop and report result to user
1005
+ when 'requires_action'
1006
+ # Handle tool calls (see below)
1007
+ when 'cancelled', 'failed', 'expired'
1008
+ puts response['last_error'].inspect
1009
+ break # or `exit`
1010
+ else
1011
+ puts "Unknown status response: #{status}"
1012
+ end
1013
+ end
1014
+ ```
1015
+
1016
+ If the `status` response indicates that the `run` is `completed`, the associated `thread` will have one or more new `messages` attached:
1017
+
1018
+ ```ruby
1019
+ # Either retrieve all messages in bulk again, or...
1020
+ messages = client.messages.list(thread_id: thread_id, parameters: { order: 'asc' })
1021
+
1022
+ # Alternatively retrieve the `run steps` for the run which link to the messages:
1023
+ run_steps = client.run_steps.list(thread_id: thread_id, run_id: run_id, parameters: { order: 'asc' })
1024
+ new_message_ids = run_steps['data'].filter_map { |step|
1025
+ if step['type'] == 'message_creation'
1026
+ step.dig('step_details', "message_creation", "message_id")
1027
+ end # Ignore tool calls, because they don't create new messages.
1028
+ }
1029
+
1030
+ # Retrieve the individual messages
1031
+ new_messages = new_message_ids.map { |msg_id|
1032
+ client.messages.retrieve(id: msg_id, thread_id: thread_id)
1033
+ }
1034
+
1035
+ # Find the actual response text in the content array of the messages
1036
+ new_messages.each { |msg|
1037
+ msg['content'].each { |content_item|
1038
+ case content_item['type']
1039
+ when 'text'
1040
+ puts content_item.dig('text', 'value')
1041
+ # Also handle annotations
1042
+ when 'image_file'
1043
+ # Use File endpoint to retrieve file contents via id
1044
+ id = content_item.dig('image_file', 'file_id')
1045
+ end
1046
+ }
1047
+ }
1048
+ ```
1049
+
1050
+ You can also update the metadata on messages, including messages that come from the assistant.
1051
+
1052
+ ```ruby
1053
+ metadata = {
1054
+ user_id: "abc123"
1055
+ }
1056
+ message = client.messages.modify(id: message_id, thread_id: thread_id, parameters: { metadata: metadata })
1057
+ ```
1058
+
1059
+ At any time you can list all runs which have been performed on a particular thread or are currently running:
1060
+
1061
+ ```ruby
1062
+ client.runs.list(thread_id: thread_id, parameters: { order: "asc", limit: 3 })
1063
+ ```
1064
+
1065
+ #### Create and Run
1066
+
1067
+ You can also create a thread and run in one call like this:
1068
+
1069
+ ```ruby
1070
+ response = client.runs.create_thread_and_run(parameters: { assistant_id: assistant_id })
1071
+ run_id = response['id']
1072
+ thread_id = response['thread_id']
1073
+ ```
1074
+
1075
+ #### Runs involving function tools
1076
+
1077
+ In case you are allowing the assistant to access `function` tools (they are defined in the same way as functions during chat completion), you might get a status code of `requires_action` when the assistant wants you to evaluate one or more function tools:
1078
+
1079
+ ```ruby
1080
+ def get_current_weather(location:, unit: "celsius")
1081
+ # Your function code goes here
1082
+ if location =~ /San Francisco/i
1083
+ return unit == "celsius" ? "The weather is nice 🌞 at 27°C" : "The weather is nice 🌞 at 80°F"
1084
+ else
1085
+ return unit == "celsius" ? "The weather is icy 🥶 at -5°C" : "The weather is icy 🥶 at 23°F"
1086
+ end
1087
+ end
1088
+
1089
+ if status == 'requires_action'
1090
+
1091
+ tools_to_call = response.dig('required_action', 'submit_tool_outputs', 'tool_calls')
1092
+
1093
+ my_tool_outputs = tools_to_call.map { |tool|
1094
+ # Call the functions based on the tool's name
1095
+ function_name = tool.dig('function', 'name')
1096
+ arguments = JSON.parse(
1097
+ tool.dig("function", "arguments"),
1098
+ { symbolize_names: true },
1099
+ )
1100
+
1101
+ tool_output = case function_name
1102
+ when "get_current_weather"
1103
+ get_current_weather(**arguments)
1104
+ end
1105
+
1106
+ { tool_call_id: tool['id'], output: tool_output }
1107
+ }
1108
+
1109
+ client.runs.submit_tool_outputs(thread_id: thread_id, run_id: run_id, parameters: { tool_outputs: my_tool_outputs })
1110
+ end
1111
+ ```
1112
+
1113
+ Note that you have 10 minutes to submit your tool output before the run expires.
1114
+
1115
+ #### Exploring chunks used in File Search
1116
+
1117
+ Take a deep breath. You might need a drink for this one.
1118
+
1119
+ It's possible for OpenAI to share what chunks it used in its internal RAG Pipeline to create its filesearch results.
1120
+
1121
+ An example spec can be found [here](https://github.com/alexrudall/ruby-openai/blob/main/spec/openai/client/assistant_file_search_spec.rb) that does this, just so you know it's possible.
1122
+
1123
+ Here's how to get the chunks used in a file search. In this example I'm using [this file](https://css4.pub/2015/textbook/somatosensory.pdf):
1124
+
1125
+ ```
1126
+ require "openai"
1127
+
1128
+ # Make a client
1129
+ client = OpenAI::Client.new(
1130
+ access_token: "access_token_goes_here",
1131
+ log_errors: true # Don't do this in production.
1132
+ )
1133
+
1134
+ # Upload your file(s)
1135
+ file_id = client.files.upload(
1136
+ parameters: {
1137
+ file: "path/to/somatosensory.pdf",
1138
+ purpose: "assistants"
1139
+ }
1140
+ )["id"]
1141
+
1142
+ # Create a vector store to store the vectorised file(s)
1143
+ vector_store_id = client.vector_stores.create(parameters: {})["id"]
1144
+
1145
+ # Vectorise the file(s)
1146
+ vector_store_file_id = client.vector_store_files.create(
1147
+ vector_store_id: vector_store_id,
1148
+ parameters: { file_id: file_id }
1149
+ )["id"]
1150
+
1151
+ # Check that the file is vectorised (wait for status to be "completed")
1152
+ client.vector_store_files.retrieve(vector_store_id: vector_store_id, id: vector_store_file_id)["status"]
1153
+
1154
+ # Create an assistant, referencing the vector store
1155
+ assistant_id = client.assistants.create(
1156
+ parameters: {
1157
+ model: "gpt-4o",
1158
+ name: "Answer finder",
1159
+ instructions: "You are a file search tool. Find the answer in the given files, please.",
1160
+ tools: [
1161
+ { type: "file_search" }
1162
+ ],
1163
+ tool_resources: {
1164
+ file_search: {
1165
+ vector_store_ids: [vector_store_id]
1166
+ }
1167
+ }
1168
+ }
1169
+ )["id"]
1170
+
1171
+ # Create a thread with your question
1172
+ thread_id = client.threads.create(parameters: {
1173
+ messages: [
1174
+ { role: "user",
1175
+ content: "Find the description of a nociceptor." }
1176
+ ]
1177
+ })["id"]
1178
+
1179
+ # Run the thread to generate the response. Include the "GIVE ME THE CHUNKS" incantation.
1180
+ run_id = client.runs.create(
1181
+ thread_id: thread_id,
1182
+ parameters: {
1183
+ assistant_id: assistant_id
1184
+ },
1185
+ query_parameters: { include: ["step_details.tool_calls[*].file_search.results[*].content"] } # incantation
1186
+ )["id"]
1187
+
1188
+ # Get the steps that happened in the run
1189
+ steps = client.run_steps.list(
1190
+ thread_id: thread_id,
1191
+ run_id: run_id,
1192
+ parameters: { order: "asc" }
1193
+ )
1194
+
1195
+ # Retrieve all the steps. Include the "GIVE ME THE CHUNKS" incantation again.
1196
+ steps = steps["data"].map do |step|
1197
+ client.run_steps.retrieve(
1198
+ thread_id: thread_id,
1199
+ run_id: run_id,
1200
+ id: step["id"],
1201
+ parameters: { include: ["step_details.tool_calls[*].file_search.results[*].content"] } # incantation
1202
+ )
1203
+ end
1204
+
1205
+ # Now we've got the chunk info, buried deep. Loop through the steps and find chunks if included:
1206
+ chunks = steps.flat_map do |step|
1207
+ included_results = step.dig("step_details", "tool_calls", 0, "file_search", "results")
1208
+
1209
+ next if included_results.nil? || included_results.empty?
1210
+
1211
+ included_results.flat_map do |result|
1212
+ result["content"].map do |content|
1213
+ content["text"]
1214
+ end
1215
+ end
1216
+ end.compact
1217
+
1218
+ # The first chunk will be the closest match to the prompt. Finally, if you want to view the completed message(s):
1219
+ client.messages.list(thread_id: thread_id)
1220
+ ```
1221
+
1222
+ ### Image Generation
1223
+
1224
+ Generate images using DALL·E 2 or DALL·E 3!
1225
+
1226
+ #### DALL·E 2
1227
+
1228
+ For DALL·E 2 the size of any generated images must be one of `256x256`, `512x512` or `1024x1024` - if not specified the image will default to `1024x1024`.
1229
+
1230
+ ```ruby
1231
+ response = client.images.generate(parameters: { prompt: "A baby sea otter cooking pasta wearing a hat of some sort", size: "256x256" })
1232
+ puts response.dig("data", 0, "url")
1233
+ # => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
1234
+ ```
1235
+
1236
+ ![Ruby](https://i.ibb.co/6y4HJFx/img-d-Tx-Rf-RHj-SO5-Gho-Cbd8o-LJvw3.png)
1237
+
1238
+ #### DALL·E 3
1239
+
1240
+ For DALL·E 3 the size of any generated images must be one of `1024x1024`, `1024x1792` or `1792x1024`. Additionally the quality of the image can be specified to either `standard` or `hd`.
1241
+
1242
+ ```ruby
1243
+ response = client.images.generate(parameters: { prompt: "A springer spaniel cooking pasta wearing a hat of some sort", model: "dall-e-3", size: "1024x1792", quality: "standard" })
1244
+ puts response.dig("data", 0, "url")
1245
+ # => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
1246
+ ```
1247
+
1248
+ ![Ruby](https://i.ibb.co/z2tCKv9/img-Goio0l-S0i81-NUNa-BIx-Eh-CT6-L.png)
1249
+
1250
+ ### Image Edit
1251
+
1252
+ Fill in the transparent part of an image, or upload a mask with transparent sections to indicate the parts of an image that can be changed according to your prompt...
1253
+
1254
+ ```ruby
1255
+ response = client.images.edit(parameters: { prompt: "A solid red Ruby on a blue background", image: "image.png", mask: "mask.png" })
1256
+ puts response.dig("data", 0, "url")
1257
+ # => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
1258
+ ```
1259
+
1260
+ ![Ruby](https://i.ibb.co/sWVh3BX/dalle-ruby.png)
1261
+
1262
+ ### Image Variations
1263
+
1264
+ Create n variations of an image.
1265
+
1266
+ ```ruby
1267
+ response = client.images.variations(parameters: { image: "image.png", n: 2 })
1268
+ puts response.dig("data", 0, "url")
1269
+ # => "https://oaidalleapiprodscus.blob.core.windows.net/private/org-Rf437IxKhh..."
1270
+ ```
1271
+
1272
+ ![Ruby](https://i.ibb.co/TWJLP2y/img-miu-Wk-Nl0-QNy-Xtj-Lerc3c0l-NW.png)
1273
+ ![Ruby](https://i.ibb.co/ScBhDGB/img-a9-Be-Rz-Au-Xwd-AV0-ERLUTSTGdi.png)
1274
+
1275
+ ### Moderations
1276
+
1277
+ Pass a string to check if it violates OpenAI's Content Policy:
1278
+
1279
+ ```ruby
1280
+ response = client.moderations(parameters: { input: "I'm worried about that." })
1281
+ puts response.dig("results", 0, "category_scores", "hate")
1282
+ # => 5.505014632944949e-05
1283
+ ```
1284
+
1285
+ ### Whisper
1286
+
1287
+ Whisper is a speech to text model that can be used to generate text based on audio files:
1288
+
1289
+ #### Translate
1290
+
1291
+ The translations API takes as input the audio file in any of the supported languages and transcribes the audio into English.
1292
+
1293
+ ```ruby
1294
+ response = client.audio.translate(
1295
+ parameters: {
1296
+ model: "whisper-1",
1297
+ file: File.open("path_to_file", "rb"),
1298
+ })
1299
+ puts response["text"]
1300
+ # => "Translation of the text"
1301
+ ```
1302
+
1303
+ #### Transcribe
1304
+
1305
+ The transcriptions API takes as input the audio file you want to transcribe and returns the text in the desired output file format.
1306
+
1307
+ You can pass the language of the audio file to improve transcription quality. Supported languages are listed [here](https://github.com/openai/whisper#available-models-and-languages). You need to provide the language as an ISO-639-1 code, eg. "en" for English or "ne" for Nepali. You can look up the codes [here](https://en.wikipedia.org/wiki/List_of_ISO_639_language_codes).
1308
+
1309
+ ```ruby
1310
+ response = client.audio.transcribe(
1311
+ parameters: {
1312
+ model: "whisper-1",
1313
+ file: File.open("path_to_file", "rb"),
1314
+ language: "en" # Optional
1315
+ })
1316
+ puts response["text"]
1317
+ # => "Transcription of the text"
1318
+ ```
1319
+
1320
+ #### Speech
1321
+
1322
+ The speech API takes as input the text and a voice and returns the content of an audio file you can listen to.
1323
+
1324
+ ```ruby
1325
+ response = client.audio.speech(
1326
+ parameters: {
1327
+ model: "tts-1",
1328
+ input: "This is a speech test!",
1329
+ voice: "alloy",
1330
+ response_format: "mp3", # Optional
1331
+ speed: 1.0 # Optional
1332
+ }
1333
+ )
1334
+ File.binwrite('demo.mp3', response)
1335
+ # => mp3 file that plays: "This is a speech test!"
1336
+ ```
1337
+
1338
+ ### Errors
1339
+
1340
+ HTTP errors can be caught like this:
1341
+
1342
+ ```
1343
+ begin
1344
+ OpenAI::Client.new.models.retrieve(id: "gpt-4o")
1345
+ rescue Faraday::Error => e
1346
+ raise "Got a Faraday error: #{e}"
1347
+ end
1348
+ ```
1349
+
1350
+ ## Development
1351
+
1352
+ After checking out the repo, run `bin/setup` to install dependencies. You can run `bin/console` for an interactive prompt that will allow you to experiment.
1353
+
1354
+ To install this gem onto your local machine, run `bundle exec rake install`.
1355
+
1356
+ To run all tests, execute the command `bundle exec rake`, which will also run the linter (Rubocop). This repository uses [VCR](https://github.com/vcr/vcr) to log API requests.
1357
+
1358
+ > [!WARNING]
1359
+ > If you have an `OPENAI_ACCESS_TOKEN` in your `ENV`, running the specs will use this to run the specs against the actual API, which will be slow and cost you money - 2 cents or more! Remove it from your environment with `unset` or similar if you just want to run the specs against the stored VCR responses.
1360
+
1361
+ ## Release
1362
+
1363
+ First run the specs without VCR so they actually hit the API. This will cost 2 cents or more. Set OPENAI_ACCESS_TOKEN in your environment or pass it in like this:
1364
+
1365
+ ```
1366
+ OPENAI_ACCESS_TOKEN=123abc bundle exec rspec
1367
+ ```
1368
+
1369
+ Then update the version number in `version.rb`, update `CHANGELOG.md`, run `bundle install` to update Gemfile.lock, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
1370
+
1371
+ ## Contributing
1372
+
1373
+ Bug reports and pull requests are welcome on GitHub at <https://github.com/alexrudall/ruby-openai>. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/alexrudall/ruby-openai/blob/main/CODE_OF_CONDUCT.md).
1374
+
1375
+ ## License
1376
+
1377
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
1378
+
1379
+ ## Code of Conduct
1380
+
1381
+ Everyone interacting in the Ruby OpenAI project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/alexrudall/ruby-openai/blob/main/CODE_OF_CONDUCT.md).