-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
api.clj
362 lines (288 loc) · 10.4 KB
/
api.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
(ns wkok.openai-clojure.api
(:require [wkok.openai-clojure.core :as core]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Models
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn list-models
"Lists the currently available models, and provides basic information about each one such as the owner and availability.
Example:
```
(list-models)
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/models/list)
"
[]
(core/response-for :openai :list-models {}))
(defn retrieve-model
"Retrieves a model instance, providing basic information about the model such as the owner and permissioning.
Example:
```
(retrieve-model {:model \"text-davinci-003\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/models/retrieve)
"
[params]
(core/response-for :openai :retrieve-model params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completion
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-completion
"Creates a completion for the provided prompt and parameters
Example:
```
(create-completion {:model \"text-davinci-003\"
:prompt \"Say this is a test\"
:max_tokens 7
:temperature 0})
```
For Azure OpenAI pass `:azure` for the `impl` argument
Streaming of token events is supported via the `:stream` param, see [Streaming Tokens](/doc/03-streaming.md)
Also see the [OpenAI](https://platform.openai.com/docs/api-reference/completions/create) / [Azure OpenAI](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#completions) documentation
"
([params]
(create-completion :openai params))
([impl params]
(core/response-for impl :create-completion params)))
(defn create-chat-completion
"Creates a completion for the chat message
Example:
```
(create-chat-completion {:model \"gpt-3.5-turbo\"
:messages [{:role \"system\" :content \"You are a helpful assistant.\"}
{:role \"user\" :content \"Who won the world series in 2020?\"}
{:role \"assistant\" :content \"The Los Angeles Dodgers won the World Series in 2020.\"}
{:role \"user\" :content \"Where was it played?\"}]})
```
Streaming of token events is supported via the `:stream` param, see [Streaming Tokens](/doc/03-streaming.md)
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/chat/create)
"
([params]
(core/response-for :openai :create-chat-completion params)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Edit
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-edit
"Creates a new edit for the provided input, instruction, and parameters
Example:
```
(create-edit {:model \"text-davinci-edit-001\"
:input \"What day of the wek is it?\"
:instruction \"Fix the spelling mistakes\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/edits/create)
"
[params]
(core/response-for :openai :create-edit params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Images
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-image
"Creates an image given a prompt.
Example:
```
(create-image {:prompt \"A cute baby sea otter\"
:n 2
:size \"1024x1024\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/images/create)
"
[params]
(core/response-for :openai :create-image params))
(defn create-image-edit
"Creates an edited or extended image given an original image and a prompt.
Example:
```
(create-image-edit {:image (clojure.java.io/file \"path/to/otter.png\")
:mask (clojure.java.io/file \"path/to/mask.png\")
:prompt \"A cute baby sea otter wearing a beret\"
:n 2
:size \"1024x1024\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/images/create-edit)
"
[params]
(core/response-for :openai :create-image-edit params))
(defn create-image-variation
"Creates a variation of a given image.
Example:
```
(create-image-variation {:image (clojure.java.io/file \"path/to/otter.png\")
:n 2
:size \"1024x1024\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/images/create-variation)
"
[params]
(core/response-for :openai :create-image-variation params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Embedding
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-embedding
"Creates an embedding vector representing the input text.
Example:
```
(create-embedding {:model \"text-embedding-ada-002\"
:input \"The food was delicious and the waiter...\"})
```
For Azure OpenAI pass `:azure` for the `impl` argument
Also see the [OpenAI](https://platform.openai.com/docs/api-reference/embeddings/create) / [Azure OpenAI](https://learn.microsoft.com/en-us/azure/cognitive-services/openai/reference#embeddings) documentation
"
([params]
(create-embedding :openai params))
([impl params]
(core/response-for impl :create-embedding params)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Audio
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-transcription
"Transcribes audio into the input language.
Example:
```
(create-transcription {:file (clojure.java.io/file \"path/to/audio.mp3\")
:model \"whisper-1\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/audio/create)
"
[params]
(core/response-for :openai :create-transcription params))
(defn create-translation
"Translates audio into English.
Example:
```
(create-translation {:file (clojure.java.io/file \"path/to/file/german.m4a\")
:model \"whisper-1\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/audio/create)
"
[params]
(core/response-for :openai :create-translation params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn list-files
"Returns a list of files that belong to the user's organization.
Example:
```
(list-files)
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files/list)
"
[]
(core/response-for :openai :list-files {}))
(defn create-file
"Upload a file that contains document(s) to be used across various endpoints/features. Currently, the size of all the files uploaded by one organization can be up to 1 GB.
Example:
```
(create-file {:purpose \"fine-tune\"
:file (clojure.java.io/file \"path/to/fine-tune.jsonl\")})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files/upload)
"
[params]
(core/response-for :openai :create-file params))
(defn delete-file
"Delete a file.
Example:
```
(delete-file {:file-id \"file-wefuhweof\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files/delete)
"
[params]
(core/response-for :openai :delete-file params))
(defn retrieve-file
"Returns information about a specific file.
Example:
```
(retrieve-file {:file-id \"file-wefuhweof\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files/retrieve)
"
[params]
(core/response-for :openai :retrieve-file params))
(defn download-file
"Returns the contents of the specified file
Example:
```
(download-file {:file-id \"file-wefuhweof\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/files/retrieve-content)
"
[params]
(core/response-for :openai :download-file params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Fine tune
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-fine-tune
"Creates a job that fine-tunes a specified model from a given dataset.\n\nResponse includes details of the enqueued job including job status and the name of the fine-tuned models once complete.
Example:
```
(create-fine-tune {:training_file \"file-xuhfiwuefb\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/create)
"
[params]
(core/response-for :openai :create-fine-tune params))
(defn list-fine-tunes
"List your organization's fine-tuning jobs
Example:
```
(list-fine-tunes)
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/list)
"
[]
(core/response-for :openai :list-fine-tunes {}))
(defn retrieve-fine-tune
"Gets info about the fine-tune job.
Example:
```
(retrieve-fine-tune {:fine_tune_id \"ft-1wefweub\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/retrieve)
"
[params]
(core/response-for :openai :retrieve-fine-tune params))
(defn cancel-fine-tune
"Immediately cancel a fine-tune job.
Example:
```
(cancel-fine-tune {:fine_tune_id \"ft-1wefweub\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/cancel)
"
[params]
(core/response-for :openai :cancel-fine-tune params))
(defn list-fine-tune-events
"Get fine-grained status updates for a fine-tune job.
Example:
```
(list-fine-tune-events {:fine_tune_id \"ft-1wefweub\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/events)
"
[params]
(core/response-for :openai :list-fine-tune-events params))
(defn delete-model
"Delete a fine-tuned model. You must have the Owner role in your organization.
Example:
```
(delete-model {:model \"fine-tune\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/fine-tunes/delete-model)
"
[params]
(core/response-for :openai :delete-model params))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Moderation
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defn create-moderation
"Classifies if text violates OpenAI's Content Policy
Example:
```
(create-moderation {:input \"I want to kill them\"})
```
Also see the [OpenAI documentation](https://platform.openai.com/docs/api-reference/moderations/create)
"
[params]
(core/response-for :openai :create-moderation params))