1
0

service-openai.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. [[infer-service-openai]]
  2. === OpenAI {infer} service
  3. Creates an {infer} endpoint to perform an {infer} task with the `openai` service.
  4. [discrete]
  5. [[infer-service-openai-api-request]]
  6. ==== {api-request-title}
  7. `PUT /_inference/<task_type>/<inference_id>`
  8. [discrete]
  9. [[infer-service-openai-api-path-params]]
  10. ==== {api-path-parms-title}
  11. `<inference_id>`::
  12. (Required, string)
  13. include::inference-shared.asciidoc[tag=inference-id]
  14. `<task_type>`::
  15. (Required, string)
  16. include::inference-shared.asciidoc[tag=task-type]
  17. +
  18. --
  19. Available task types:
  20. * `completion`,
  21. * `text_embedding`.
  22. --
  23. [discrete]
  24. [[infer-service-openai-api-request-body]]
  25. ==== {api-request-body-title}
  26. `service`::
  27. (Required, string)
  28. The type of service supported for the specified task type. In this case,
  29. `openai`.
  30. `service_settings`::
  31. (Required, object)
  32. include::inference-shared.asciidoc[tag=service-settings]
  33. +
  34. --
  35. These settings are specific to the `openai` service.
  36. --
  37. `api_key`:::
  38. (Required, string)
  39. A valid API key of your OpenAI account.
  40. You can find your OpenAI API keys in your OpenAI account under the
  41. https://platform.openai.com/api-keys[API keys section].
  42. +
  43. --
  44. include::inference-shared.asciidoc[tag=api-key-admonition]
  45. --
  46. `model_id`:::
  47. (Required, string)
  48. The name of the model to use for the {infer} task.
  49. Refer to the
  50. https://platform.openai.com/docs/guides/embeddings/what-are-embeddings[OpenAI documentation]
  51. for the list of available text embedding models.
  52. `organization_id`:::
  53. (Optional, string)
  54. The unique identifier of your organization.
  55. You can find the Organization ID in your OpenAI account under
  56. https://platform.openai.com/account/organization[**Settings** > **Organizations**].
  57. `url`:::
  58. (Optional, string)
  59. The URL endpoint to use for the requests.
  60. Can be changed for testing purposes.
  61. Defaults to `https://api.openai.com/v1/embeddings`.
  62. `rate_limit`:::
  63. (Optional, object)
  64. The `openai` service sets a default number of requests allowed per minute depending on the task type.
  65. For `text_embedding` it is set to `3000`.
  66. For `completion` it is set to `500`.
  67. This helps to minimize the number of rate limit errors returned from OpenAI.
  68. To modify this, set the `requests_per_minute` setting of this object in your service settings:
  69. +
  70. --
  71. include::inference-shared.asciidoc[tag=request-per-minute-example]
  72. More information about the rate limits for OpenAI can be found in your https://platform.openai.com/account/limits[Account limits].
  73. --
  74. `task_settings`::
  75. (Optional, object)
  76. include::inference-shared.asciidoc[tag=task-settings]
  77. +
  78. .`task_settings` for the `completion` task type
  79. [%collapsible%closed]
  80. =====
  81. `user`:::
  82. (Optional, string)
  83. Specifies the user issuing the request, which can be used for abuse detection.
  84. =====
  85. +
  86. .`task_settings` for the `text_embedding` task type
  87. [%collapsible%closed]
  88. =====
  89. `user`:::
  90. (optional, string)
  91. Specifies the user issuing the request, which can be used for abuse detection.
  92. =====
  93. [discrete]
  94. [[inference-example-openai]]
  95. ==== OpenAI service example
  96. The following example shows how to create an {infer} endpoint called
  97. `openai-embeddings` to perform a `text_embedding` task type.
  98. [source,console]
  99. ------------------------------------------------------------
  100. PUT _inference/text_embedding/openai-embeddings
  101. {
  102. "service": "openai",
  103. "service_settings": {
  104. "api_key": "<api_key>",
  105. "model_id": "text-embedding-ada-002"
  106. }
  107. }
  108. ------------------------------------------------------------
  109. // TEST[skip:TBD]
  110. The next example shows how to create an {infer} endpoint called
  111. `openai-completion` to perform a `completion` task type.
  112. [source,console]
  113. ------------------------------------------------------------
  114. PUT _inference/completion/openai-completion
  115. {
  116. "service": "openai",
  117. "service_settings": {
  118. "api_key": "<api_key>",
  119. "model_id": "gpt-3.5-turbo"
  120. }
  121. }
  122. ------------------------------------------------------------
  123. // TEST[skip:TBD]