pixeltable 0.2.13__py3-none-any.whl → 0.2.15__py3-none-any.whl
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.
Potentially problematic release.
This version of pixeltable might be problematic. Click here for more details.
- pixeltable/__init__.py +1 -1
- pixeltable/__version__.py +2 -2
- pixeltable/catalog/column.py +8 -3
- pixeltable/catalog/globals.py +8 -0
- pixeltable/catalog/table.py +25 -9
- pixeltable/catalog/table_version.py +30 -55
- pixeltable/catalog/view.py +1 -1
- pixeltable/env.py +4 -4
- pixeltable/exec/__init__.py +2 -1
- pixeltable/exec/row_update_node.py +61 -0
- pixeltable/exec/{sql_scan_node.py → sql_node.py} +120 -56
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/arithmetic_expr.py +41 -16
- pixeltable/exprs/expr.py +72 -22
- pixeltable/exprs/function_call.py +64 -29
- pixeltable/exprs/globals.py +5 -1
- pixeltable/exprs/inline_array.py +18 -11
- pixeltable/exprs/method_ref.py +63 -0
- pixeltable/ext/__init__.py +9 -0
- pixeltable/ext/functions/__init__.py +8 -0
- pixeltable/ext/functions/whisperx.py +45 -5
- pixeltable/ext/functions/yolox.py +60 -14
- pixeltable/func/callable_function.py +12 -4
- pixeltable/func/expr_template_function.py +1 -1
- pixeltable/func/function.py +12 -2
- pixeltable/func/function_registry.py +24 -9
- pixeltable/func/udf.py +32 -4
- pixeltable/functions/__init__.py +1 -1
- pixeltable/functions/fireworks.py +33 -0
- pixeltable/functions/huggingface.py +96 -6
- pixeltable/functions/image.py +226 -41
- pixeltable/functions/json.py +46 -0
- pixeltable/functions/openai.py +214 -0
- pixeltable/functions/string.py +195 -218
- pixeltable/functions/timestamp.py +210 -0
- pixeltable/functions/together.py +106 -0
- pixeltable/functions/video.py +2 -2
- pixeltable/functions/{eval.py → vision.py} +170 -27
- pixeltable/functions/whisper.py +32 -0
- pixeltable/io/__init__.py +1 -1
- pixeltable/io/external_store.py +2 -2
- pixeltable/io/globals.py +133 -1
- pixeltable/io/pandas.py +82 -31
- pixeltable/iterators/video.py +55 -23
- pixeltable/metadata/__init__.py +1 -1
- pixeltable/metadata/converters/convert_18.py +39 -0
- pixeltable/metadata/notes.py +10 -0
- pixeltable/plan.py +76 -1
- pixeltable/store.py +65 -28
- pixeltable/tool/create_test_db_dump.py +8 -9
- pixeltable/tool/doc_plugins/griffe.py +4 -0
- pixeltable/type_system.py +84 -63
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/METADATA +2 -2
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/RECORD +57 -51
- pixeltable/exprs/image_member_access.py +0 -96
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/LICENSE +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/WHEEL +0 -0
- {pixeltable-0.2.13.dist-info → pixeltable-0.2.15.dist-info}/entry_points.txt +0 -0
pixeltable/functions/openai.py
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pixeltable [UDFs](https://pixeltable.readme.io/docs/user-defined-functions-udfs)
|
|
3
|
+
that wrap various endpoints from the OpenAI API. In order to use them, you must
|
|
4
|
+
first `pip install openai` and configure your OpenAI credentials, as described in
|
|
5
|
+
the [Working with OpenAI](https://pixeltable.readme.io/docs/working-with-openai) tutorial.
|
|
6
|
+
"""
|
|
7
|
+
|
|
1
8
|
import base64
|
|
2
9
|
import io
|
|
3
10
|
import pathlib
|
|
@@ -51,6 +58,33 @@ def _retry(fn: Callable) -> Callable:
|
|
|
51
58
|
def speech(
|
|
52
59
|
input: str, *, model: str, voice: str, response_format: Optional[str] = None, speed: Optional[float] = None
|
|
53
60
|
) -> str:
|
|
61
|
+
"""
|
|
62
|
+
Generates audio from the input text.
|
|
63
|
+
|
|
64
|
+
Equivalent to the OpenAI `audio/speech` API endpoint.
|
|
65
|
+
For additional details, see: [https://platform.openai.com/docs/guides/text-to-speech](https://platform.openai.com/docs/guides/text-to-speech)
|
|
66
|
+
|
|
67
|
+
__Requirements:__
|
|
68
|
+
|
|
69
|
+
- `pip install openai`
|
|
70
|
+
|
|
71
|
+
Args:
|
|
72
|
+
input: The text to synthesize into speech.
|
|
73
|
+
model: The model to use for speech synthesis.
|
|
74
|
+
voice: The voice profile to use for speech synthesis. Supported options include:
|
|
75
|
+
`alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`.
|
|
76
|
+
|
|
77
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/audio/createSpeech](https://platform.openai.com/docs/api-reference/audio/createSpeech)
|
|
78
|
+
|
|
79
|
+
Returns:
|
|
80
|
+
An audio file containing the synthesized speech.
|
|
81
|
+
|
|
82
|
+
Examples:
|
|
83
|
+
Add a computed column that applies the model `tts-1` to an existing Pixeltable column `tbl.text`
|
|
84
|
+
of the table `tbl`:
|
|
85
|
+
|
|
86
|
+
>>> tbl['audio'] = speech(tbl.text, model='tts-1', voice='nova')
|
|
87
|
+
"""
|
|
54
88
|
content = _retry(_openai_client().audio.speech.create)(
|
|
55
89
|
input=input, model=model, voice=voice, response_format=_opt(response_format), speed=_opt(speed)
|
|
56
90
|
)
|
|
@@ -77,6 +111,31 @@ def transcriptions(
|
|
|
77
111
|
prompt: Optional[str] = None,
|
|
78
112
|
temperature: Optional[float] = None,
|
|
79
113
|
) -> dict:
|
|
114
|
+
"""
|
|
115
|
+
Transcribes audio into the input language.
|
|
116
|
+
|
|
117
|
+
Equivalent to the OpenAI `audio/transcriptions` API endpoint.
|
|
118
|
+
For additional details, see: [https://platform.openai.com/docs/guides/speech-to-text](https://platform.openai.com/docs/guides/speech-to-text)
|
|
119
|
+
|
|
120
|
+
__Requirements:__
|
|
121
|
+
|
|
122
|
+
- `pip install openai`
|
|
123
|
+
|
|
124
|
+
Args:
|
|
125
|
+
audio: The audio to transcribe.
|
|
126
|
+
model: The model to use for speech transcription.
|
|
127
|
+
|
|
128
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/audio/createTranscription](https://platform.openai.com/docs/api-reference/audio/createTranscription)
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
A dictionary containing the transcription and other metadata.
|
|
132
|
+
|
|
133
|
+
Examples:
|
|
134
|
+
Add a computed column that applies the model `whisper-1` to an existing Pixeltable column `tbl.audio`
|
|
135
|
+
of the table `tbl`:
|
|
136
|
+
|
|
137
|
+
>>> tbl['transcription'] = transcriptions(tbl.audio, model='whisper-1', language='en')
|
|
138
|
+
"""
|
|
80
139
|
file = pathlib.Path(audio)
|
|
81
140
|
transcription = _retry(_openai_client().audio.transcriptions.create)(
|
|
82
141
|
file=file, model=model, language=_opt(language), prompt=_opt(prompt), temperature=_opt(temperature)
|
|
@@ -86,6 +145,31 @@ def transcriptions(
|
|
|
86
145
|
|
|
87
146
|
@pxt.udf(param_types=[ts.AudioType(), ts.StringType(), ts.StringType(nullable=True), ts.FloatType(nullable=True)])
|
|
88
147
|
def translations(audio: str, *, model: str, prompt: Optional[str] = None, temperature: Optional[float] = None) -> dict:
|
|
148
|
+
"""
|
|
149
|
+
Translates audio into English.
|
|
150
|
+
|
|
151
|
+
Equivalent to the OpenAI `audio/translations` API endpoint.
|
|
152
|
+
For additional details, see: [https://platform.openai.com/docs/guides/speech-to-text](https://platform.openai.com/docs/guides/speech-to-text)
|
|
153
|
+
|
|
154
|
+
__Requirements:__
|
|
155
|
+
|
|
156
|
+
- `pip install openai`
|
|
157
|
+
|
|
158
|
+
Args:
|
|
159
|
+
audio: The audio to translate.
|
|
160
|
+
model: The model to use for speech transcription and translation.
|
|
161
|
+
|
|
162
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/audio/createTranslation](https://platform.openai.com/docs/api-reference/audio/createTranslation)
|
|
163
|
+
|
|
164
|
+
Returns:
|
|
165
|
+
A dictionary containing the translation and other metadata.
|
|
166
|
+
|
|
167
|
+
Examples:
|
|
168
|
+
Add a computed column that applies the model `whisper-1` to an existing Pixeltable column `tbl.audio`
|
|
169
|
+
of the table `tbl`:
|
|
170
|
+
|
|
171
|
+
>>> tbl['translation'] = translations(tbl.audio, model='whisper-1', language='en')
|
|
172
|
+
"""
|
|
89
173
|
file = pathlib.Path(audio)
|
|
90
174
|
translation = _retry(_openai_client().audio.translations.create)(
|
|
91
175
|
file=file, model=model, prompt=_opt(prompt), temperature=_opt(temperature)
|
|
@@ -118,6 +202,35 @@ def chat_completions(
|
|
|
118
202
|
tool_choice: Optional[dict] = None,
|
|
119
203
|
user: Optional[str] = None,
|
|
120
204
|
) -> dict:
|
|
205
|
+
"""
|
|
206
|
+
Creates a model response for the given chat conversation.
|
|
207
|
+
|
|
208
|
+
Equivalent to the OpenAI `chat/completions` API endpoint.
|
|
209
|
+
For additional details, see: [https://platform.openai.com/docs/guides/chat-completions](https://platform.openai.com/docs/guides/chat-completions)
|
|
210
|
+
|
|
211
|
+
__Requirements:__
|
|
212
|
+
|
|
213
|
+
- `pip install openai`
|
|
214
|
+
|
|
215
|
+
Args:
|
|
216
|
+
messages: A list of messages to use for chat completion, as described in the OpenAI API documentation.
|
|
217
|
+
model: The model to use for chat completion.
|
|
218
|
+
|
|
219
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/chat](https://platform.openai.com/docs/api-reference/chat)
|
|
220
|
+
|
|
221
|
+
Returns:
|
|
222
|
+
A dictionary containing the response and other metadata.
|
|
223
|
+
|
|
224
|
+
Examples:
|
|
225
|
+
Add a computed column that applies the model `gpt-4o-mini` to an existing Pixeltable column `tbl.prompt`
|
|
226
|
+
of the table `tbl`:
|
|
227
|
+
|
|
228
|
+
>>> messages = [
|
|
229
|
+
{'role': 'system', 'content': 'You are a helpful assistant.'},
|
|
230
|
+
{'role': 'user', 'content': tbl.prompt}
|
|
231
|
+
]
|
|
232
|
+
tbl['response'] = chat_completions(messages, model='gpt-4o-mini')
|
|
233
|
+
"""
|
|
121
234
|
result = _retry(_openai_client().chat.completions.create)(
|
|
122
235
|
messages=messages,
|
|
123
236
|
model=model,
|
|
@@ -142,6 +255,30 @@ def chat_completions(
|
|
|
142
255
|
|
|
143
256
|
@pxt.udf
|
|
144
257
|
def vision(prompt: str, image: PIL.Image.Image, *, model: str) -> str:
|
|
258
|
+
"""
|
|
259
|
+
Analyzes an image with the OpenAI vision capability. This is a convenience function that takes an image and
|
|
260
|
+
prompt, and constructs a chat completion request that utilizes OpenAI vision.
|
|
261
|
+
|
|
262
|
+
For additional details, see: [https://platform.openai.com/docs/guides/vision](https://platform.openai.com/docs/guides/vision)
|
|
263
|
+
|
|
264
|
+
__Requirements:__
|
|
265
|
+
|
|
266
|
+
- `pip install openai`
|
|
267
|
+
|
|
268
|
+
Args:
|
|
269
|
+
prompt: A prompt for the OpenAI vision request.
|
|
270
|
+
image: The image to analyze.
|
|
271
|
+
model: The model to use for OpenAI vision.
|
|
272
|
+
|
|
273
|
+
Returns:
|
|
274
|
+
The response from the OpenAI vision API.
|
|
275
|
+
|
|
276
|
+
Examples:
|
|
277
|
+
Add a computed column that applies the model `gpt-4o-mini` to an existing Pixeltable column `tbl.image`
|
|
278
|
+
of the table `tbl`:
|
|
279
|
+
|
|
280
|
+
>>> tbl['response'] = vision("What's in this image?", tbl.image, model='gpt-4o-mini')
|
|
281
|
+
"""
|
|
145
282
|
# TODO(aaron-siegel): Decompose CPU/GPU ops into separate functions
|
|
146
283
|
bytes_arr = io.BytesIO()
|
|
147
284
|
image.save(bytes_arr, format='png')
|
|
@@ -174,6 +311,33 @@ _embedding_dimensions_cache: dict[str, int] = {
|
|
|
174
311
|
def embeddings(
|
|
175
312
|
input: Batch[str], *, model: str, dimensions: Optional[int] = None, user: Optional[str] = None
|
|
176
313
|
) -> Batch[np.ndarray]:
|
|
314
|
+
"""
|
|
315
|
+
Creates an embedding vector representing the input text.
|
|
316
|
+
|
|
317
|
+
Equivalent to the OpenAI `embeddings` API endpoint.
|
|
318
|
+
For additional details, see: [https://platform.openai.com/docs/guides/embeddings](https://platform.openai.com/docs/guides/embeddings)
|
|
319
|
+
|
|
320
|
+
__Requirements:__
|
|
321
|
+
|
|
322
|
+
- `pip install openai`
|
|
323
|
+
|
|
324
|
+
Args:
|
|
325
|
+
input: The text to embed.
|
|
326
|
+
model: The model to use for the embedding.
|
|
327
|
+
dimensions: The vector length of the embedding. If not specified, Pixeltable will use
|
|
328
|
+
a default value based on the model.
|
|
329
|
+
|
|
330
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/embeddings](https://platform.openai.com/docs/api-reference/embeddings)
|
|
331
|
+
|
|
332
|
+
Returns:
|
|
333
|
+
An array representing the application of the given embedding to `input`.
|
|
334
|
+
|
|
335
|
+
Examples:
|
|
336
|
+
Add a computed column that applies the model `text-embedding-3-small` to an existing
|
|
337
|
+
Pixeltable column `tbl.text` of the table `tbl`:
|
|
338
|
+
|
|
339
|
+
>>> tbl['embed'] = embeddings(tbl.text, model='text-embedding-3-small')
|
|
340
|
+
"""
|
|
177
341
|
result = _retry(_openai_client().embeddings.create)(
|
|
178
342
|
input=input, model=model, dimensions=_opt(dimensions), user=_opt(user), encoding_format='float'
|
|
179
343
|
)
|
|
@@ -204,6 +368,31 @@ def image_generations(
|
|
|
204
368
|
style: Optional[str] = None,
|
|
205
369
|
user: Optional[str] = None,
|
|
206
370
|
) -> PIL.Image.Image:
|
|
371
|
+
"""
|
|
372
|
+
Creates an image given a prompt.
|
|
373
|
+
|
|
374
|
+
Equivalent to the OpenAI `images/generations` API endpoint.
|
|
375
|
+
For additional details, see: [https://platform.openai.com/docs/guides/images](https://platform.openai.com/docs/guides/images)
|
|
376
|
+
|
|
377
|
+
__Requirements:__
|
|
378
|
+
|
|
379
|
+
- `pip install openai`
|
|
380
|
+
|
|
381
|
+
Args:
|
|
382
|
+
prompt: Prompt for the image.
|
|
383
|
+
model: The model to use for the generations.
|
|
384
|
+
|
|
385
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/images/create](https://platform.openai.com/docs/api-reference/images/create)
|
|
386
|
+
|
|
387
|
+
Returns:
|
|
388
|
+
The generated image.
|
|
389
|
+
|
|
390
|
+
Examples:
|
|
391
|
+
Add a computed column that applies the model `dall-e-2` to an existing
|
|
392
|
+
Pixeltable column `tbl.text` of the table `tbl`:
|
|
393
|
+
|
|
394
|
+
>>> tbl['gen_image'] = image_generations(tbl.text, model='dall-e-2')
|
|
395
|
+
"""
|
|
207
396
|
# TODO(aaron-siegel): Decompose CPU/GPU ops into separate functions
|
|
208
397
|
result = _retry(_openai_client().images.generate)(
|
|
209
398
|
prompt=prompt,
|
|
@@ -241,6 +430,31 @@ def _(size: Optional[str] = None) -> ts.ImageType:
|
|
|
241
430
|
|
|
242
431
|
@pxt.udf
|
|
243
432
|
def moderations(input: str, *, model: Optional[str] = None) -> dict:
|
|
433
|
+
"""
|
|
434
|
+
Classifies if text is potentially harmful.
|
|
435
|
+
|
|
436
|
+
Equivalent to the OpenAI `moderations` API endpoint.
|
|
437
|
+
For additional details, see: [https://platform.openai.com/docs/guides/moderation](https://platform.openai.com/docs/guides/moderation)
|
|
438
|
+
|
|
439
|
+
__Requirements:__
|
|
440
|
+
|
|
441
|
+
- `pip install openai`
|
|
442
|
+
|
|
443
|
+
Args:
|
|
444
|
+
input: Text to analyze with the moderations model.
|
|
445
|
+
model: The model to use for moderations.
|
|
446
|
+
|
|
447
|
+
For details on the other parameters, see: [https://platform.openai.com/docs/api-reference/moderations](https://platform.openai.com/docs/api-reference/moderations)
|
|
448
|
+
|
|
449
|
+
Returns:
|
|
450
|
+
Details of the moderations results.
|
|
451
|
+
|
|
452
|
+
Examples:
|
|
453
|
+
Add a computed column that applies the model `text-moderation-stable` to an existing
|
|
454
|
+
Pixeltable column `tbl.input` of the table `tbl`:
|
|
455
|
+
|
|
456
|
+
>>> tbl['moderations'] = moderations(tbl.text, model='text-moderation-stable')
|
|
457
|
+
"""
|
|
244
458
|
result = _retry(_openai_client().moderations.create)(input=input, model=_opt(model))
|
|
245
459
|
return result.dict()
|
|
246
460
|
|