openai 3.2.1 → 4.0.0-beta.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 (261) hide show
  1. package/.eslintrc.js +10 -0
  2. package/.github/ISSUE_TEMPLATE/bug_report.yml +2 -2
  3. package/.github/ISSUE_TEMPLATE/config.yml +1 -1
  4. package/.github/ISSUE_TEMPLATE/feature_request.yml +2 -2
  5. package/.github/workflows/test.yml +10 -11
  6. package/.prettierignore +1 -0
  7. package/.prettierrc +6 -0
  8. package/.stats.yml +1 -0
  9. package/LICENSE +201 -21
  10. package/README.md +189 -56
  11. package/api.md +157 -0
  12. package/bin/check-test-server +50 -0
  13. package/build +12 -0
  14. package/check-version.ts +18 -0
  15. package/core.ts +814 -0
  16. package/dist/cjs/check-version.d.ts +2 -0
  17. package/dist/cjs/check-version.d.ts.map +1 -0
  18. package/dist/cjs/check-version.js +23 -0
  19. package/dist/cjs/check-version.js.map +1 -0
  20. package/dist/cjs/core.d.ts +232 -0
  21. package/dist/cjs/core.d.ts.map +1 -0
  22. package/dist/cjs/core.js +854 -0
  23. package/dist/cjs/core.js.map +1 -0
  24. package/dist/cjs/error.d.ts +51 -0
  25. package/dist/cjs/error.d.ts.map +1 -0
  26. package/dist/cjs/error.js +131 -0
  27. package/dist/cjs/error.js.map +1 -0
  28. package/dist/cjs/examples/demo.d.ts +3 -0
  29. package/dist/cjs/examples/demo.d.ts.map +1 -0
  30. package/dist/cjs/examples/demo.js +119 -0
  31. package/dist/cjs/examples/demo.js.map +1 -0
  32. package/dist/cjs/examples/errors.d.ts +3 -0
  33. package/dist/cjs/examples/errors.d.ts.map +1 -0
  34. package/dist/cjs/examples/errors.js +100 -0
  35. package/dist/cjs/examples/errors.js.map +1 -0
  36. package/dist/cjs/examples/fine-tunes.d.ts +10 -0
  37. package/dist/cjs/examples/fine-tunes.d.ts.map +1 -0
  38. package/dist/cjs/examples/fine-tunes.js +160 -0
  39. package/dist/cjs/examples/fine-tunes.js.map +1 -0
  40. package/dist/cjs/fetch-polyfill.d.ts +6 -0
  41. package/dist/cjs/fetch-polyfill.d.ts.map +1 -0
  42. package/dist/cjs/fetch-polyfill.js +57 -0
  43. package/dist/cjs/fetch-polyfill.js.map +1 -0
  44. package/dist/cjs/index.d.ts +100 -0
  45. package/dist/cjs/index.d.ts.map +1 -0
  46. package/dist/cjs/index.js +135 -0
  47. package/dist/cjs/index.js.map +1 -0
  48. package/dist/cjs/resource.d.ts +12 -0
  49. package/dist/cjs/resource.d.ts.map +1 -0
  50. package/dist/cjs/resource.js +17 -0
  51. package/dist/cjs/resource.js.map +1 -0
  52. package/dist/cjs/resources/answers.d.ts +150 -0
  53. package/dist/cjs/resources/answers.d.ts.map +1 -0
  54. package/dist/cjs/resources/answers.js +20 -0
  55. package/dist/cjs/resources/answers.js.map +1 -0
  56. package/dist/cjs/resources/audio/audio.d.ts +8 -0
  57. package/dist/cjs/resources/audio/audio.d.ts.map +1 -0
  58. package/dist/cjs/resources/audio/audio.js +16 -0
  59. package/dist/cjs/resources/audio/audio.js.map +1 -0
  60. package/dist/cjs/resources/audio/index.d.ts +3 -0
  61. package/dist/cjs/resources/audio/index.d.ts.map +1 -0
  62. package/dist/cjs/resources/audio/index.js +4 -0
  63. package/dist/cjs/resources/audio/index.js.map +1 -0
  64. package/dist/cjs/resources/audio/transcriptions.d.ts +52 -0
  65. package/dist/cjs/resources/audio/transcriptions.d.ts.map +1 -0
  66. package/dist/cjs/resources/audio/transcriptions.js +19 -0
  67. package/dist/cjs/resources/audio/transcriptions.js.map +1 -0
  68. package/dist/cjs/resources/audio/translations.d.ts +46 -0
  69. package/dist/cjs/resources/audio/translations.d.ts.map +1 -0
  70. package/dist/cjs/resources/audio/translations.js +19 -0
  71. package/dist/cjs/resources/audio/translations.js.map +1 -0
  72. package/dist/cjs/resources/chat/chat.d.ts +6 -0
  73. package/dist/cjs/resources/chat/chat.d.ts.map +1 -0
  74. package/dist/cjs/resources/chat/chat.js +14 -0
  75. package/dist/cjs/resources/chat/chat.js.map +1 -0
  76. package/dist/cjs/resources/chat/completions.d.ts +472 -0
  77. package/dist/cjs/resources/chat/completions.d.ts.map +1 -0
  78. package/dist/cjs/resources/chat/completions.js +18 -0
  79. package/dist/cjs/resources/chat/completions.js.map +1 -0
  80. package/dist/cjs/resources/chat/index.d.ts +2 -0
  81. package/dist/cjs/resources/chat/index.d.ts.map +1 -0
  82. package/dist/cjs/resources/chat/index.js +4 -0
  83. package/dist/cjs/resources/chat/index.js.map +1 -0
  84. package/dist/cjs/resources/classifications.d.ts +142 -0
  85. package/dist/cjs/resources/classifications.d.ts.map +1 -0
  86. package/dist/cjs/resources/classifications.js +24 -0
  87. package/dist/cjs/resources/classifications.js.map +1 -0
  88. package/dist/cjs/resources/completions.d.ts +313 -0
  89. package/dist/cjs/resources/completions.d.ts.map +1 -0
  90. package/dist/cjs/resources/completions.js +18 -0
  91. package/dist/cjs/resources/completions.js.map +1 -0
  92. package/dist/cjs/resources/edits.d.ts +71 -0
  93. package/dist/cjs/resources/edits.d.ts.map +1 -0
  94. package/dist/cjs/resources/edits.js +15 -0
  95. package/dist/cjs/resources/edits.js.map +1 -0
  96. package/dist/cjs/resources/embeddings.d.ts +49 -0
  97. package/dist/cjs/resources/embeddings.d.ts.map +1 -0
  98. package/dist/cjs/resources/embeddings.js +15 -0
  99. package/dist/cjs/resources/embeddings.js.map +1 -0
  100. package/dist/cjs/resources/files.d.ts +69 -0
  101. package/dist/cjs/resources/files.d.ts.map +1 -0
  102. package/dist/cjs/resources/files.js +51 -0
  103. package/dist/cjs/resources/files.js.map +1 -0
  104. package/dist/cjs/resources/fine-tunes.d.ts +216 -0
  105. package/dist/cjs/resources/fine-tunes.d.ts.map +1 -0
  106. package/dist/cjs/resources/fine-tunes.js +52 -0
  107. package/dist/cjs/resources/fine-tunes.js.map +1 -0
  108. package/dist/cjs/resources/images.d.ts +121 -0
  109. package/dist/cjs/resources/images.d.ts.map +1 -0
  110. package/dist/cjs/resources/images.js +34 -0
  111. package/dist/cjs/resources/images.js.map +1 -0
  112. package/dist/cjs/resources/index.d.ts +35 -0
  113. package/dist/cjs/resources/index.d.ts.map +1 -0
  114. package/dist/cjs/resources/index.js +101 -0
  115. package/dist/cjs/resources/index.js.map +1 -0
  116. package/dist/cjs/resources/models.d.ts +34 -0
  117. package/dist/cjs/resources/models.d.ts.map +1 -0
  118. package/dist/cjs/resources/models.js +29 -0
  119. package/dist/cjs/resources/models.js.map +1 -0
  120. package/dist/cjs/resources/moderations.d.ts +59 -0
  121. package/dist/cjs/resources/moderations.d.ts.map +1 -0
  122. package/dist/cjs/resources/moderations.js +15 -0
  123. package/dist/cjs/resources/moderations.js.map +1 -0
  124. package/dist/cjs/streaming.d.ts +13 -0
  125. package/dist/cjs/streaming.d.ts.map +1 -0
  126. package/dist/cjs/streaming.js +287 -0
  127. package/dist/cjs/streaming.js.map +1 -0
  128. package/dist/cjs/tests/api-resources/answers.test.d.ts +2 -0
  129. package/dist/cjs/tests/api-resources/answers.test.d.ts.map +1 -0
  130. package/dist/cjs/tests/api-resources/answers.test.js +279 -0
  131. package/dist/cjs/tests/api-resources/answers.test.js.map +1 -0
  132. package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts +2 -0
  133. package/dist/cjs/tests/api-resources/audio/transcriptions.test.d.ts.map +1 -0
  134. package/dist/cjs/tests/api-resources/audio/transcriptions.test.js +65 -0
  135. package/dist/cjs/tests/api-resources/audio/transcriptions.test.js.map +1 -0
  136. package/dist/cjs/tests/api-resources/audio/translations.test.d.ts +2 -0
  137. package/dist/cjs/tests/api-resources/audio/translations.test.d.ts.map +1 -0
  138. package/dist/cjs/tests/api-resources/audio/translations.test.js +64 -0
  139. package/dist/cjs/tests/api-resources/audio/translations.test.js.map +1 -0
  140. package/dist/cjs/tests/api-resources/chat/completions.test.d.ts +2 -0
  141. package/dist/cjs/tests/api-resources/chat/completions.test.d.ts.map +1 -0
  142. package/dist/cjs/tests/api-resources/chat/completions.test.js +77 -0
  143. package/dist/cjs/tests/api-resources/chat/completions.test.js.map +1 -0
  144. package/dist/cjs/tests/api-resources/classifications.test.d.ts +2 -0
  145. package/dist/cjs/tests/api-resources/classifications.test.d.ts.map +1 -0
  146. package/dist/cjs/tests/api-resources/classifications.test.js +73 -0
  147. package/dist/cjs/tests/api-resources/classifications.test.js.map +1 -0
  148. package/dist/cjs/tests/api-resources/completions.test.d.ts +2 -0
  149. package/dist/cjs/tests/api-resources/completions.test.d.ts.map +1 -0
  150. package/dist/cjs/tests/api-resources/completions.test.js +69 -0
  151. package/dist/cjs/tests/api-resources/completions.test.js.map +1 -0
  152. package/dist/cjs/tests/api-resources/edits.test.d.ts +2 -0
  153. package/dist/cjs/tests/api-resources/edits.test.d.ts.map +1 -0
  154. package/dist/cjs/tests/api-resources/edits.test.js +62 -0
  155. package/dist/cjs/tests/api-resources/edits.test.js.map +1 -0
  156. package/dist/cjs/tests/api-resources/embeddings.test.d.ts +2 -0
  157. package/dist/cjs/tests/api-resources/embeddings.test.d.ts.map +1 -0
  158. package/dist/cjs/tests/api-resources/embeddings.test.js +59 -0
  159. package/dist/cjs/tests/api-resources/embeddings.test.js.map +1 -0
  160. package/dist/cjs/tests/api-resources/files.test.d.ts +2 -0
  161. package/dist/cjs/tests/api-resources/files.test.d.ts.map +1 -0
  162. package/dist/cjs/tests/api-resources/files.test.js +107 -0
  163. package/dist/cjs/tests/api-resources/files.test.js.map +1 -0
  164. package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts +2 -0
  165. package/dist/cjs/tests/api-resources/fine-tunes.test.d.ts.map +1 -0
  166. package/dist/cjs/tests/api-resources/fine-tunes.test.js +115 -0
  167. package/dist/cjs/tests/api-resources/fine-tunes.test.js.map +1 -0
  168. package/dist/cjs/tests/api-resources/images.test.d.ts +2 -0
  169. package/dist/cjs/tests/api-resources/images.test.d.ts.map +1 -0
  170. package/dist/cjs/tests/api-resources/images.test.js +100 -0
  171. package/dist/cjs/tests/api-resources/images.test.js.map +1 -0
  172. package/dist/cjs/tests/api-resources/models.test.d.ts +2 -0
  173. package/dist/cjs/tests/api-resources/models.test.d.ts.map +1 -0
  174. package/dist/cjs/tests/api-resources/models.test.js +77 -0
  175. package/dist/cjs/tests/api-resources/models.test.js.map +1 -0
  176. package/dist/cjs/tests/api-resources/moderations.test.d.ts +2 -0
  177. package/dist/cjs/tests/api-resources/moderations.test.d.ts.map +1 -0
  178. package/dist/cjs/tests/api-resources/moderations.test.js +55 -0
  179. package/dist/cjs/tests/api-resources/moderations.test.js.map +1 -0
  180. package/dist/cjs/tests/form.test.d.ts +2 -0
  181. package/dist/cjs/tests/form.test.d.ts.map +1 -0
  182. package/dist/cjs/tests/form.test.js +61 -0
  183. package/dist/cjs/tests/form.test.js.map +1 -0
  184. package/dist/cjs/tests/index.test.d.ts +2 -0
  185. package/dist/cjs/tests/index.test.d.ts.map +1 -0
  186. package/dist/cjs/tests/index.test.js +75 -0
  187. package/dist/cjs/tests/index.test.js.map +1 -0
  188. package/dist/cjs/tests/responses.test.d.ts +2 -0
  189. package/dist/cjs/tests/responses.test.d.ts.map +1 -0
  190. package/dist/cjs/tests/responses.test.js +60 -0
  191. package/dist/cjs/tests/responses.test.js.map +1 -0
  192. package/dist/cjs/version.d.ts +2 -0
  193. package/dist/cjs/version.d.ts.map +1 -0
  194. package/dist/cjs/version.js +5 -0
  195. package/dist/cjs/version.js.map +1 -0
  196. package/error.ts +125 -0
  197. package/examples/demo.ts +28 -0
  198. package/examples/errors.ts +28 -0
  199. package/examples/fine-tune-data.jsonl +3 -0
  200. package/examples/fine-tunes.ts +37 -0
  201. package/fetch-polyfill.ts +69 -0
  202. package/index.ts +156 -17
  203. package/jest.config.js +8 -0
  204. package/package.json +38 -22
  205. package/resource.ts +24 -0
  206. package/resources/answers.ts +180 -0
  207. package/resources/audio/audio.ts +10 -0
  208. package/resources/audio/index.ts +4 -0
  209. package/resources/audio/transcriptions.ts +64 -0
  210. package/resources/audio/translations.ts +57 -0
  211. package/resources/chat/chat.ts +8 -0
  212. package/resources/chat/completions.ts +559 -0
  213. package/resources/chat/index.ts +3 -0
  214. package/resources/classifications.ts +169 -0
  215. package/resources/completions.ts +371 -0
  216. package/resources/edits.ts +96 -0
  217. package/resources/embeddings.ts +65 -0
  218. package/resources/files.ts +104 -0
  219. package/resources/fine-tunes.ts +277 -0
  220. package/resources/images.ts +153 -0
  221. package/resources/index.ts +36 -0
  222. package/resources/models.ts +53 -0
  223. package/resources/moderations.ts +85 -0
  224. package/streaming.ts +205 -0
  225. package/tests/api-resources/answers.test.ts +242 -0
  226. package/tests/api-resources/audio/transcriptions.test.ts +28 -0
  227. package/tests/api-resources/audio/translations.test.ts +27 -0
  228. package/tests/api-resources/chat/completions.test.ts +40 -0
  229. package/tests/api-resources/classifications.test.ts +36 -0
  230. package/tests/api-resources/completions.test.ts +32 -0
  231. package/tests/api-resources/edits.test.ts +25 -0
  232. package/tests/api-resources/embeddings.test.ts +22 -0
  233. package/tests/api-resources/files.test.ts +64 -0
  234. package/tests/api-resources/fine-tunes.test.ts +78 -0
  235. package/tests/api-resources/images.test.ts +61 -0
  236. package/tests/api-resources/models.test.ts +40 -0
  237. package/tests/api-resources/moderations.test.ts +18 -0
  238. package/tests/form.test.ts +27 -0
  239. package/tests/index.test.ts +76 -0
  240. package/tests/responses.test.ts +25 -0
  241. package/tsconfig.cjs.json +8 -0
  242. package/tsconfig.json +34 -12
  243. package/typings/digest-fetch/index.d.ts +33 -0
  244. package/version.ts +1 -0
  245. package/.openapi-generator/FILES +0 -6
  246. package/.openapi-generator/VERSION +0 -1
  247. package/.openapi-generator-ignore +0 -5
  248. package/api.ts +0 -3997
  249. package/base.ts +0 -72
  250. package/common.ts +0 -150
  251. package/configuration.ts +0 -127
  252. package/dist/api.d.ts +0 -2868
  253. package/dist/api.js +0 -2038
  254. package/dist/base.d.ts +0 -54
  255. package/dist/base.js +0 -59
  256. package/dist/common.d.ts +0 -65
  257. package/dist/common.js +0 -151
  258. package/dist/configuration.d.ts +0 -91
  259. package/dist/configuration.js +0 -54
  260. package/dist/index.d.ts +0 -13
  261. package/dist/index.js +0 -27
package/.eslintrc.js ADDED
@@ -0,0 +1,10 @@
1
+ module.exports = {
2
+ parser: '@typescript-eslint/parser',
3
+ plugins: ['@typescript-eslint', 'unused-imports', 'prettier'],
4
+ rules: {
5
+ 'no-unused-vars': 'off',
6
+ 'prettier/prettier': 'error',
7
+ 'unused-imports/no-unused-imports': 'error',
8
+ },
9
+ root: true,
10
+ };
@@ -1,6 +1,6 @@
1
1
  name: Bug report
2
2
  description: Create a report to help us improve
3
- labels: ["bug"]
3
+ labels: ['bug']
4
4
  body:
5
5
  - type: markdown
6
6
  attributes:
@@ -53,4 +53,4 @@ body:
53
53
  label: Library version
54
54
  placeholder: openai v3.0.1
55
55
  validations:
56
- required: true
56
+ required: true
@@ -4,4 +4,4 @@ contact_links:
4
4
  url: https://help.openai.com/
5
5
  about: |
6
6
  Please only file issues here that you believe represent actual bugs or feature requests for the OpenAI Node library.
7
- If you're having general trouble with the OpenAI API, please visit our help center to get support.
7
+ If you're having general trouble with the OpenAI API, please visit our help center to get support.
@@ -1,6 +1,6 @@
1
1
  name: Feature request
2
2
  description: Suggest an idea for this library
3
- labels: ["feature-request"]
3
+ labels: ['feature-request']
4
4
  body:
5
5
  - type: markdown
6
6
  attributes:
@@ -17,4 +17,4 @@ body:
17
17
  id: context
18
18
  attributes:
19
19
  label: Additional context
20
- description: Add any other context about the feature request here.
20
+ description: Add any other context about the feature request here.
@@ -2,24 +2,23 @@ name: Node.js CI
2
2
 
3
3
  on:
4
4
  push:
5
- branches: [ master ]
5
+ branches: [master]
6
6
  pull_request:
7
- branches: [ master ]
7
+ branches: [master]
8
8
 
9
9
  jobs:
10
10
  build:
11
-
12
11
  runs-on: ubuntu-latest
13
12
 
14
13
  strategy:
15
14
  matrix:
16
15
  node-version: [16.x, 18.x]
17
16
  steps:
18
- - uses: actions/checkout@v3
19
- - name: Use Node.js ${{ matrix.node-version }}
20
- uses: actions/setup-node@v3
21
- with:
22
- node-version: ${{ matrix.node-version }}
23
- cache: 'npm'
24
- - run: npm ci
25
- - run: npm run build
17
+ - uses: actions/checkout@v3
18
+ - name: Use Node.js ${{ matrix.node-version }}
19
+ uses: actions/setup-node@v3
20
+ with:
21
+ node-version: ${{ matrix.node-version }}
22
+ cache: 'npm'
23
+ - run: npm ci
24
+ - run: npm run build
@@ -0,0 +1 @@
1
+ CHANGELOG.md
package/.prettierrc ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "arrowParens": "always",
3
+ "trailingComma": "all",
4
+ "singleQuote": true,
5
+ "printWidth": 110
6
+ }
package/.stats.yml ADDED
@@ -0,0 +1 @@
1
+ configured_endpoints: 25
package/LICENSE CHANGED
@@ -1,21 +1,201 @@
1
- The MIT License
2
-
3
- Copyright (c) OpenAI (https://openai.com)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2023 OpenAI
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,90 +1,223 @@
1
- # OpenAI Node.js Library
1
+ # OpenAI Node API Library
2
2
 
3
- The OpenAI Node.js library provides convenient access to the OpenAI API from Node.js applications. Most of the code in this library is generated from our [OpenAPI specification](https://github.com/openai/openai-openapi).
3
+ [![NPM version](https://img.shields.io/npm/v/openai.svg)](https://npmjs.org/package/openai)
4
4
 
5
- **Important note: this library is meant for server-side usage only, as using it in client-side browser code will expose your secret API key. [See here](https://beta.openai.com/docs/api-reference/authentication) for more details.**
5
+ The OpenAI Node library provides convenient access to the OpenAI REST API from applications written in server-side JavaScript.
6
+ It includes TypeScript definitions for all request params and response fields.
7
+
8
+ > ⚠️ **Important note: this library is meant for server-side usage only, as using it in client-side browser code will expose your secret API key. [See here](https://platform.openai.com/docs/api-reference/authentication) for more details.**
9
+
10
+ ## Documentation
11
+
12
+ To learn how to use the OpenAI API, check out our [API Reference](https://platform.openai.com/docs/api-reference) and [Documentation](https://platform.openai.com/docs).
6
13
 
7
14
  ## Installation
8
15
 
9
- ```bash
10
- $ npm install openai
16
+ ```sh
17
+ npm install --save openai
18
+ # or
19
+ yarn add openai
11
20
  ```
12
21
 
13
22
  ## Usage
14
23
 
15
- The library needs to be configured with your account's secret key, which is available on the [website](https://beta.openai.com/account/api-keys). We recommend setting it as an environment variable. Here's an example of initializing the library with the API key loaded from an environment variable and creating a completion:
24
+ ```js
25
+ import OpenAI from 'openai';
26
+
27
+ const openAI = new OpenAI({
28
+ apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
29
+ });
30
+
31
+ async function main() {
32
+ const completion = await openAI.completions.create({
33
+ model: 'text-davinci-002',
34
+ prompt: 'Say this is a test',
35
+ max_tokens: 6,
36
+ temperature: 0,
37
+ });
38
+
39
+ console.log(completion.choices);
40
+ }
41
+ main().catch(console.error);
42
+ ```
43
+
44
+ ## Streaming Responses
45
+
46
+ We provide support for streaming responses using Server Side Events (SSE).
47
+
48
+ ```ts
49
+ import OpenAI from 'openai';
16
50
 
17
- ```javascript
18
- const { Configuration, OpenAIApi } = require("openai");
51
+ const client = new OpenAI();
19
52
 
20
- const configuration = new Configuration({
21
- apiKey: process.env.OPENAI_API_KEY,
53
+ const stream = await client.completions.create({
54
+ prompt: 'Say this is a test',
55
+ model: 'text-davinci-003',
56
+ stream: true,
22
57
  });
23
- const openai = new OpenAIApi(configuration);
58
+ for await (const part of stream) {
59
+ process.stdout.write(part.choices[0]?.text || '');
60
+ }
61
+ ```
62
+
63
+ If you need to cancel a stream, you can `break` from the loop
64
+ or call `stream.controller.abort()`.
65
+
66
+ ### Usage with TypeScript
24
67
 
25
- const completion = await openai.createCompletion({
26
- model: "text-davinci-003",
27
- prompt: "Hello world",
68
+ Importing, instantiating, and interacting with the library are the same as above.
69
+ If you like, you may reference our types directly:
70
+
71
+ ```ts
72
+ import OpenAI from 'openai';
73
+
74
+ const openAI = new OpenAI({
75
+ apiKey: 'my api key', // defaults to process.env["OPENAI_API_KEY"]
28
76
  });
29
- console.log(completion.data.choices[0].text);
77
+
78
+ async function main() {
79
+ const params: OpenAI.CompletionCreateParams = {
80
+ model: 'text-davinci-002',
81
+ prompt: 'Say this is a test',
82
+ max_tokens: 6,
83
+ temperature: 0,
84
+ };
85
+ const completion: OpenAI.Completion = await openAI.completions.create(params);
86
+ }
87
+ main().catch(console.error);
30
88
  ```
31
89
 
32
- Check out the [full API documentation](https://beta.openai.com/docs/api-reference?lang=node.js) for examples of all the available functions.
90
+ Documentation for each method, request param, and response field are available in docstrings and will appear on hover in most modern editors.
91
+
92
+ ## File Uploads
93
+
94
+ Request parameters that correspond to file uploads can be passed as either a `FormData.Blob` or a `FormData.File` instance.
33
95
 
34
- ### Request options
96
+ We provide a `fileFromPath` helper function to easily create `FormData.File` instances from a given class.
35
97
 
36
- All of the available API request functions additionally contain an optional final parameter where you can pass custom [axios request options](https://axios-http.com/docs/req_config), for example:
98
+ ```ts
99
+ import OpenAI, { fileFromPath } from 'openai';
37
100
 
101
+ const openAI = new OpenAI();
38
102
 
39
- ```javascript
40
- const completion = await openai.createCompletion(
41
- {
42
- model: "text-davinci-003",
43
- prompt: "Hello world",
44
- },
45
- {
46
- timeout: 1000,
47
- headers: {
48
- "Example-Header": "example",
49
- },
50
- }
51
- );
103
+ const file = await fileFromPath('input.jsonl');
104
+ await openAI.files.create({ file: file, purpose: 'fine-tune' });
52
105
  ```
53
106
 
54
- ### Error handling
107
+ ## Handling errors
55
108
 
56
- API requests can potentially return errors due to invalid inputs or other issues. These errors can be handled with a `try...catch` statement, and the error details can be found in either `error.response` or `error.message`:
109
+ When the library is unable to connect to the API,
110
+ or if the API returns a non-success status code (i.e., 4xx or 5xx response),
111
+ a subclass of `APIError` will be thrown:
57
112
 
58
- ```javascript
59
- try {
60
- const completion = await openai.createCompletion({
61
- model: "text-davinci-003",
62
- prompt: "Hello world",
63
- });
64
- console.log(completion.data.choices[0].text);
65
- } catch (error) {
66
- if (error.response) {
67
- console.log(error.response.status);
68
- console.log(error.response.data);
69
- } else {
70
- console.log(error.message);
71
- }
113
+ ```ts
114
+ async function main() {
115
+ const fineTune = await openAI.fineTunes
116
+ .create({ training_file: 'file-XGinujblHPwGLSztz8cPS8XY' })
117
+ .catch((err) => {
118
+ if (err instanceof OpenAI.APIError) {
119
+ console.log(err.status); // 400
120
+ console.log(err.name); // BadRequestError
121
+
122
+ console.log(err.headers); // {server: 'nginx', ...}
123
+ }
124
+ });
72
125
  }
126
+ main().catch(console.error);
73
127
  ```
74
128
 
75
- ### Streaming completions
129
+ Error codes are as followed:
130
+
131
+ | Status Code | Error Type |
132
+ | ----------- | -------------------------- |
133
+ | 400 | `BadRequestError` |
134
+ | 401 | `AuthenticationError` |
135
+ | 403 | `PermissionDeniedError` |
136
+ | 404 | `NotFoundError` |
137
+ | 422 | `UnprocessableEntityError` |
138
+ | 429 | `RateLimitError` |
139
+ | >=500 | `InternalServerError` |
140
+ | N/A | `APIConnectionError` |
141
+
142
+ ### Retries
143
+
144
+ Certain errors will be automatically retried 2 times by default, with a short exponential backoff.
145
+ Connection errors (for example, due to a network connectivity problem), 409 Conflict, 429 Rate Limit,
146
+ and >=500 Internal errors will all be retried by default.
147
+
148
+ You can use the `maxRetries` option to configure or disable this:
149
+
150
+ <!-- prettier-ignore -->
151
+ ```js
152
+ // Configure the default for all requests:
153
+ const openAI = new OpenAI({
154
+ maxRetries: 0, // default is 2
155
+ });
156
+
157
+ // Or, configure per-request:
158
+ openAI.embeddings.create({ model: 'text-similarity-babbage-001',input: 'The food was delicious and the waiter...' }, {
159
+ maxRetries: 5,
160
+ });
161
+ ```
162
+
163
+ ### Timeouts
164
+
165
+ Requests time out after 60 seconds by default. You can configure this with a `timeout` option:
166
+
167
+ <!-- prettier-ignore -->
168
+ ```ts
169
+ // Configure the default for all requests:
170
+ const openAI = new OpenAI({
171
+ timeout: 20 * 1000, // 20 seconds (default is 60s)
172
+ });
173
+
174
+ // Override per-request:
175
+ openAI.edits.create({ model: 'text-davinci-edit-001',input: 'What day of the wek is it?',instruction: 'Fix the spelling mistakes' }, {
176
+ timeout: 5 * 1000,
177
+ });
178
+ ```
179
+
180
+ On timeout, an `APIConnectionTimeoutError` is thrown.
181
+
182
+ Note that requests which time out will be [retried twice by default](#retries).
183
+
184
+ ## Configuring an HTTP(S) Agent (e.g., for proxies)
185
+
186
+ By default, this library uses a stable agent for all http/https requests to reuse TCP connections, eliminating many TCP & TLS handshakes and shaving around 100ms off most requests.
187
+
188
+ If you would like to disable or customize this behavior, for example to use the API behind a proxy, you can pass an `httpAgent` which is used for all requests (be they http or https), for example:
189
+
190
+ <!-- prettier-ignore -->
191
+ ```ts
192
+ import http from 'http';
193
+ import HttpsProxyAgent from 'https-proxy-agent';
194
+
195
+ // Configure the default for all requests:
196
+ const openAI = new OpenAI({
197
+ httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
198
+ });
199
+
200
+ // Override per-request:
201
+ openAI.models.list({
202
+ baseURL: 'http://localhost:8080/test-api',
203
+ httpAgent: new http.Agent({ keepAlive: false }),
204
+ })
205
+ ```
76
206
 
77
- Streaming completions (`stream=true`) are not natively supported in this package yet, but [a workaround exists](https://github.com/openai/openai-node/issues/18#issuecomment-1369996933) if needed.
207
+ ## Status
78
208
 
79
- ## Upgrade guide
209
+ This package is in beta. Its internals and interfaces are not stable
210
+ and subject to change without a major semver bump;
211
+ please reach out if you rely on any undocumented behavior.
80
212
 
81
- All breaking changes for major version releases are listed below.
213
+ We are keen for your feedback; please open an [issue](https://www.github.com/openai/openai-node/issues) with questions, bugs, or suggestions.
82
214
 
83
- ### 3.0.0
215
+ ## Requirements
84
216
 
85
- - The function signature of `createCompletion(engineId, params)` changed to `createCompletion(params)`. The value previously passed in as the `engineId` argument should now be passed in as `model` in the params object (e.g. `createCompletion({ model: "text-davinci-003", ... })`)
86
- - Replace any `createCompletionFromModel(params)` calls with `createCompletion(params)`
217
+ The following runtimes are supported:
87
218
 
88
- ## Thanks
219
+ - Node.js version 12 or higher.
220
+ - Deno v1.28.0 or higher (experimental).
221
+ Use `import OpenAI from "npm:openai"`.
89
222
 
90
- Thank you to [ceifa](https://github.com/ceifa) for creating and maintaining the original unofficial `openai` npm package before we released this official library! ceifa's original package has been renamed to [gpt-x](https://www.npmjs.com/package/gpt-x).
223
+ If you are interested in other runtime environments, please open or upvote an issue on GitHub.