pixeltable 0.3.5__py3-none-any.whl → 0.3.7__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 +5 -3
- pixeltable/__version__.py +2 -2
- pixeltable/catalog/__init__.py +1 -0
- pixeltable/catalog/catalog.py +335 -128
- pixeltable/catalog/column.py +21 -5
- pixeltable/catalog/dir.py +19 -6
- pixeltable/catalog/insertable_table.py +34 -37
- pixeltable/catalog/named_function.py +0 -4
- pixeltable/catalog/schema_object.py +28 -42
- pixeltable/catalog/table.py +195 -158
- pixeltable/catalog/table_version.py +187 -232
- pixeltable/catalog/table_version_handle.py +50 -0
- pixeltable/catalog/table_version_path.py +49 -33
- pixeltable/catalog/view.py +56 -96
- pixeltable/config.py +103 -0
- pixeltable/dataframe.py +90 -90
- pixeltable/env.py +98 -168
- pixeltable/exec/aggregation_node.py +5 -4
- pixeltable/exec/cache_prefetch_node.py +1 -1
- pixeltable/exec/component_iteration_node.py +13 -9
- pixeltable/exec/data_row_batch.py +3 -3
- pixeltable/exec/exec_context.py +0 -4
- pixeltable/exec/exec_node.py +3 -2
- pixeltable/exec/expr_eval/schedulers.py +2 -1
- pixeltable/exec/in_memory_data_node.py +9 -4
- pixeltable/exec/row_update_node.py +1 -2
- pixeltable/exec/sql_node.py +20 -16
- pixeltable/exprs/column_ref.py +9 -9
- pixeltable/exprs/comparison.py +1 -1
- pixeltable/exprs/data_row.py +4 -4
- pixeltable/exprs/expr.py +20 -5
- pixeltable/exprs/function_call.py +98 -58
- pixeltable/exprs/json_mapper.py +25 -8
- pixeltable/exprs/json_path.py +6 -5
- pixeltable/exprs/object_ref.py +16 -5
- pixeltable/exprs/row_builder.py +15 -15
- pixeltable/exprs/rowid_ref.py +21 -7
- pixeltable/func/__init__.py +1 -1
- pixeltable/func/function.py +38 -6
- pixeltable/func/query_template_function.py +3 -6
- pixeltable/func/tools.py +26 -26
- pixeltable/func/udf.py +1 -1
- pixeltable/functions/__init__.py +2 -0
- pixeltable/functions/anthropic.py +9 -3
- pixeltable/functions/fireworks.py +7 -4
- pixeltable/functions/globals.py +4 -5
- pixeltable/functions/huggingface.py +1 -5
- pixeltable/functions/image.py +17 -7
- pixeltable/functions/llama_cpp.py +1 -1
- pixeltable/functions/mistralai.py +1 -1
- pixeltable/functions/ollama.py +4 -4
- pixeltable/functions/openai.py +26 -23
- pixeltable/functions/string.py +23 -30
- pixeltable/functions/timestamp.py +11 -6
- pixeltable/functions/together.py +14 -12
- pixeltable/functions/util.py +1 -1
- pixeltable/functions/video.py +5 -4
- pixeltable/functions/vision.py +6 -9
- pixeltable/functions/whisper.py +3 -3
- pixeltable/globals.py +246 -260
- pixeltable/index/__init__.py +2 -0
- pixeltable/index/base.py +1 -1
- pixeltable/index/btree.py +3 -1
- pixeltable/index/embedding_index.py +11 -5
- pixeltable/io/external_store.py +11 -12
- pixeltable/io/label_studio.py +4 -3
- pixeltable/io/parquet.py +57 -56
- pixeltable/iterators/__init__.py +4 -2
- pixeltable/iterators/audio.py +11 -11
- pixeltable/iterators/document.py +10 -10
- pixeltable/iterators/string.py +1 -2
- pixeltable/iterators/video.py +14 -15
- pixeltable/metadata/__init__.py +9 -5
- pixeltable/metadata/converters/convert_10.py +0 -1
- pixeltable/metadata/converters/convert_15.py +0 -2
- pixeltable/metadata/converters/convert_23.py +0 -2
- pixeltable/metadata/converters/convert_24.py +3 -3
- pixeltable/metadata/converters/convert_25.py +1 -1
- pixeltable/metadata/converters/convert_27.py +0 -2
- pixeltable/metadata/converters/convert_28.py +0 -2
- pixeltable/metadata/converters/convert_29.py +7 -8
- pixeltable/metadata/converters/util.py +7 -7
- pixeltable/metadata/schema.py +27 -19
- pixeltable/plan.py +68 -40
- pixeltable/share/packager.py +12 -9
- pixeltable/store.py +37 -38
- pixeltable/type_system.py +41 -28
- pixeltable/utils/filecache.py +2 -1
- {pixeltable-0.3.5.dist-info → pixeltable-0.3.7.dist-info}/METADATA +1 -1
- pixeltable-0.3.7.dist-info/RECORD +174 -0
- pixeltable-0.3.5.dist-info/RECORD +0 -172
- {pixeltable-0.3.5.dist-info → pixeltable-0.3.7.dist-info}/LICENSE +0 -0
- {pixeltable-0.3.5.dist-info → pixeltable-0.3.7.dist-info}/WHEEL +0 -0
- {pixeltable-0.3.5.dist-info → pixeltable-0.3.7.dist-info}/entry_points.txt +0 -0
pixeltable/functions/image.py
CHANGED
|
@@ -80,7 +80,9 @@ def convert(self: PIL.Image.Image, mode: str) -> PIL.Image.Image:
|
|
|
80
80
|
[`PIL.Image.Image.convert()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.convert).
|
|
81
81
|
|
|
82
82
|
Args:
|
|
83
|
-
mode: The mode to convert to. See the
|
|
83
|
+
mode: The mode to convert to. See the
|
|
84
|
+
[Pillow documentation](https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes)
|
|
85
|
+
for a list of supported modes.
|
|
84
86
|
"""
|
|
85
87
|
return self.convert(mode)
|
|
86
88
|
|
|
@@ -109,7 +111,7 @@ def crop(self: PIL.Image.Image, box: tuple[int, int, int, int]) -> PIL.Image.Ima
|
|
|
109
111
|
def _(self: Expr, box: tuple[int, int, int, int]) -> pxt.ColumnType:
|
|
110
112
|
input_type = self.col_type
|
|
111
113
|
assert isinstance(input_type, pxt.ImageType)
|
|
112
|
-
if (isinstance(box, list
|
|
114
|
+
if (isinstance(box, (list, tuple))) and len(box) == 4 and all(isinstance(x, int) for x in box):
|
|
113
115
|
return pxt.ImageType(
|
|
114
116
|
size=(box[2] - box[0], box[3] - box[1]), mode=input_type.mode, nullable=input_type.nullable
|
|
115
117
|
)
|
|
@@ -225,7 +227,9 @@ def transpose(self: PIL.Image.Image, method: int) -> PIL.Image.Image:
|
|
|
225
227
|
[`PIL.Image.Image.transpose()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transpose)
|
|
226
228
|
|
|
227
229
|
Args:
|
|
228
|
-
method: The transpose method. See the
|
|
230
|
+
method: The transpose method. See the
|
|
231
|
+
[Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transpose)
|
|
232
|
+
for a list of supported methods.
|
|
229
233
|
"""
|
|
230
234
|
pass
|
|
231
235
|
|
|
@@ -271,7 +275,8 @@ def getbbox(self: PIL.Image.Image, *, alpha_only: bool = True) -> tuple[int, int
|
|
|
271
275
|
Equivalent to [`PIL.Image.Image.getbbox()`](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.getbbox)
|
|
272
276
|
|
|
273
277
|
Args:
|
|
274
|
-
alpha_only: If `True`, and the image has an alpha channel, trim transparent pixels. Otherwise,
|
|
278
|
+
alpha_only: If `True`, and the image has an alpha channel, trim transparent pixels. Otherwise,
|
|
279
|
+
trim pixels when all channels are zero.
|
|
275
280
|
"""
|
|
276
281
|
pass
|
|
277
282
|
|
|
@@ -375,10 +380,14 @@ def quantize(
|
|
|
375
380
|
|
|
376
381
|
Args:
|
|
377
382
|
colors: The number of colors to quantize to.
|
|
378
|
-
method: The quantization method. See the
|
|
383
|
+
method: The quantization method. See the
|
|
384
|
+
[Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize)
|
|
385
|
+
for a list of supported methods.
|
|
379
386
|
kmeans: The number of k-means clusters to use.
|
|
380
387
|
palette: The palette to use.
|
|
381
|
-
dither: The dithering method. See the
|
|
388
|
+
dither: The dithering method. See the
|
|
389
|
+
[Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize)
|
|
390
|
+
for a list of supported methods.
|
|
382
391
|
"""
|
|
383
392
|
pass
|
|
384
393
|
|
|
@@ -393,7 +402,8 @@ def reduce(self: PIL.Image.Image, factor: int, box: Optional[tuple[int, int, int
|
|
|
393
402
|
|
|
394
403
|
Args:
|
|
395
404
|
factor: The reduction factor.
|
|
396
|
-
box: An optional 4-tuple of ints providing the source image region to be reduced. The values must be within
|
|
405
|
+
box: An optional 4-tuple of ints providing the source image region to be reduced. The values must be within
|
|
406
|
+
(0, 0, width, height) rectangle. If omitted or None, the entire source is used.
|
|
397
407
|
"""
|
|
398
408
|
pass
|
|
399
409
|
|
|
@@ -62,7 +62,7 @@ def create_chat_completion(
|
|
|
62
62
|
def _is_gpu_available() -> bool:
|
|
63
63
|
import llama_cpp
|
|
64
64
|
|
|
65
|
-
global _IS_GPU_AVAILABLE
|
|
65
|
+
global _IS_GPU_AVAILABLE # noqa: PLW0603
|
|
66
66
|
if _IS_GPU_AVAILABLE is None:
|
|
67
67
|
llama_cpp_path = Path(llama_cpp.__file__).parent
|
|
68
68
|
lib = llama_cpp.llama_cpp.load_shared_library('llama', llama_cpp_path / 'lib')
|
|
@@ -148,7 +148,7 @@ _embedding_dimensions_cache: dict[str, int] = {'mistral-embed': 1024}
|
|
|
148
148
|
|
|
149
149
|
|
|
150
150
|
@pxt.udf(batch_size=16, resource_pool='request-rate:mistral')
|
|
151
|
-
async def embeddings(input: Batch[str], *, model: str) -> Batch[pxt.Array[(None,), pxt.Float]]:
|
|
151
|
+
async def embeddings(input: Batch[str], *, model: str) -> Batch[pxt.Array[(None,), pxt.Float]]: # noqa: RUF029
|
|
152
152
|
"""
|
|
153
153
|
Embeddings API.
|
|
154
154
|
|
pixeltable/functions/ollama.py
CHANGED
|
@@ -50,8 +50,8 @@ def generate(
|
|
|
50
50
|
template: Prompt template to use.
|
|
51
51
|
context: The context parameter returned from a previous call to `generate()`.
|
|
52
52
|
raw: If `True`, no formatting will be applied to the prompt.
|
|
53
|
-
options: Additional options to pass to the `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
54
|
-
For details, see the
|
|
53
|
+
options: Additional options to pass to the `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
54
|
+
`top_k`. For details, see the
|
|
55
55
|
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values)
|
|
56
56
|
section of the Ollama documentation.
|
|
57
57
|
"""
|
|
@@ -89,8 +89,8 @@ def chat(
|
|
|
89
89
|
model: The model name.
|
|
90
90
|
tools: Tools for the model to use.
|
|
91
91
|
format: The format of the response; must be one of `'json'` or `None`.
|
|
92
|
-
options: Additional options to pass to the `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
93
|
-
For details, see the
|
|
92
|
+
options: Additional options to pass to the `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
93
|
+
`top_k`. For details, see the
|
|
94
94
|
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.md#valid-parameters-and-values)
|
|
95
95
|
section of the Ollama documentation.
|
|
96
96
|
"""
|
pixeltable/functions/openai.py
CHANGED
|
@@ -183,7 +183,7 @@ async def speech(
|
|
|
183
183
|
Generates audio from the input text.
|
|
184
184
|
|
|
185
185
|
Equivalent to the OpenAI `audio/speech` API endpoint.
|
|
186
|
-
For additional details, see:
|
|
186
|
+
For additional details, see: <https://platform.openai.com/docs/guides/text-to-speech>
|
|
187
187
|
|
|
188
188
|
Request throttling:
|
|
189
189
|
Applies the rate limit set in the config (section `openai.rate_limits`; use the model id as the key). If no rate
|
|
@@ -199,7 +199,7 @@ async def speech(
|
|
|
199
199
|
voice: The voice profile to use for speech synthesis. Supported options include:
|
|
200
200
|
`alloy`, `echo`, `fable`, `onyx`, `nova`, and `shimmer`.
|
|
201
201
|
|
|
202
|
-
For details on the other parameters, see:
|
|
202
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/audio/createSpeech>
|
|
203
203
|
|
|
204
204
|
Returns:
|
|
205
205
|
An audio file containing the synthesized speech.
|
|
@@ -238,7 +238,7 @@ async def transcriptions(
|
|
|
238
238
|
Transcribes audio into the input language.
|
|
239
239
|
|
|
240
240
|
Equivalent to the OpenAI `audio/transcriptions` API endpoint.
|
|
241
|
-
For additional details, see:
|
|
241
|
+
For additional details, see: <https://platform.openai.com/docs/guides/speech-to-text>
|
|
242
242
|
|
|
243
243
|
Request throttling:
|
|
244
244
|
Applies the rate limit set in the config (section `openai.rate_limits`; use the model id as the key). If no rate
|
|
@@ -252,7 +252,7 @@ async def transcriptions(
|
|
|
252
252
|
audio: The audio to transcribe.
|
|
253
253
|
model: The model to use for speech transcription.
|
|
254
254
|
|
|
255
|
-
For details on the other parameters, see:
|
|
255
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/audio/createTranscription>
|
|
256
256
|
|
|
257
257
|
Returns:
|
|
258
258
|
A dictionary containing the transcription and other metadata.
|
|
@@ -288,7 +288,7 @@ async def translations(
|
|
|
288
288
|
Translates audio into English.
|
|
289
289
|
|
|
290
290
|
Equivalent to the OpenAI `audio/translations` API endpoint.
|
|
291
|
-
For additional details, see:
|
|
291
|
+
For additional details, see: <https://platform.openai.com/docs/guides/speech-to-text>
|
|
292
292
|
|
|
293
293
|
Request throttling:
|
|
294
294
|
Applies the rate limit set in the config (section `openai.rate_limits`; use the model id as the key). If no rate
|
|
@@ -302,7 +302,7 @@ async def translations(
|
|
|
302
302
|
audio: The audio to translate.
|
|
303
303
|
model: The model to use for speech transcription and translation.
|
|
304
304
|
|
|
305
|
-
For details on the other parameters, see:
|
|
305
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/audio/createTranslation>
|
|
306
306
|
|
|
307
307
|
Returns:
|
|
308
308
|
A dictionary containing the translation and other metadata.
|
|
@@ -395,7 +395,7 @@ async def chat_completions(
|
|
|
395
395
|
Creates a model response for the given chat conversation.
|
|
396
396
|
|
|
397
397
|
Equivalent to the OpenAI `chat/completions` API endpoint.
|
|
398
|
-
For additional details, see:
|
|
398
|
+
For additional details, see: <https://platform.openai.com/docs/guides/chat-completions>
|
|
399
399
|
|
|
400
400
|
Request throttling:
|
|
401
401
|
Uses the rate limit-related headers returned by the API to throttle requests adaptively, based on available
|
|
@@ -409,7 +409,7 @@ async def chat_completions(
|
|
|
409
409
|
messages: A list of messages to use for chat completion, as described in the OpenAI API documentation.
|
|
410
410
|
model: The model to use for chat completion.
|
|
411
411
|
|
|
412
|
-
For details on the other parameters, see:
|
|
412
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/chat>
|
|
413
413
|
|
|
414
414
|
Returns:
|
|
415
415
|
A dictionary containing the response and other metadata.
|
|
@@ -498,9 +498,9 @@ def _vision_get_request_resources(
|
|
|
498
498
|
crops_height = math.ceil(image.height / 512)
|
|
499
499
|
total_crops = crops_width * crops_height
|
|
500
500
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
img_tokens =
|
|
501
|
+
base_tokens = 85 # base cost for the initial 512x512 overview
|
|
502
|
+
crop_tokens = 170 # cost per additional 512x512 crop
|
|
503
|
+
img_tokens = base_tokens + (crop_tokens * total_crops)
|
|
504
504
|
|
|
505
505
|
total_tokens = (
|
|
506
506
|
prompt_tokens
|
|
@@ -527,7 +527,7 @@ async def vision(
|
|
|
527
527
|
Analyzes an image with the OpenAI vision capability. This is a convenience function that takes an image and
|
|
528
528
|
prompt, and constructs a chat completion request that utilizes OpenAI vision.
|
|
529
529
|
|
|
530
|
-
For additional details, see:
|
|
530
|
+
For additional details, see: <https://platform.openai.com/docs/guides/vision>
|
|
531
531
|
|
|
532
532
|
Request throttling:
|
|
533
533
|
Uses the rate limit-related headers returned by the API to throttle requests adaptively, based on available
|
|
@@ -616,7 +616,7 @@ async def embeddings(
|
|
|
616
616
|
Creates an embedding vector representing the input text.
|
|
617
617
|
|
|
618
618
|
Equivalent to the OpenAI `embeddings` API endpoint.
|
|
619
|
-
For additional details, see:
|
|
619
|
+
For additional details, see: <https://platform.openai.com/docs/guides/embeddings>
|
|
620
620
|
|
|
621
621
|
Request throttling:
|
|
622
622
|
Uses the rate limit-related headers returned by the API to throttle requests adaptively, based on available
|
|
@@ -632,7 +632,7 @@ async def embeddings(
|
|
|
632
632
|
dimensions: The vector length of the embedding. If not specified, Pixeltable will use
|
|
633
633
|
a default value based on the model.
|
|
634
634
|
|
|
635
|
-
For details on the other parameters, see:
|
|
635
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/embeddings>
|
|
636
636
|
|
|
637
637
|
Returns:
|
|
638
638
|
An array representing the application of the given embedding to `input`.
|
|
@@ -671,7 +671,7 @@ def _(model: str, dimensions: Optional[int] = None) -> pxt.ArrayType:
|
|
|
671
671
|
if model not in _embedding_dimensions_cache:
|
|
672
672
|
# TODO: find some other way to retrieve a sample
|
|
673
673
|
return pxt.ArrayType((None,), dtype=pxt.FloatType(), nullable=False)
|
|
674
|
-
dimensions = _embedding_dimensions_cache.get(model
|
|
674
|
+
dimensions = _embedding_dimensions_cache.get(model)
|
|
675
675
|
return pxt.ArrayType((dimensions,), dtype=pxt.FloatType(), nullable=False)
|
|
676
676
|
|
|
677
677
|
|
|
@@ -694,7 +694,7 @@ async def image_generations(
|
|
|
694
694
|
Creates an image given a prompt.
|
|
695
695
|
|
|
696
696
|
Equivalent to the OpenAI `images/generations` API endpoint.
|
|
697
|
-
For additional details, see:
|
|
697
|
+
For additional details, see: <https://platform.openai.com/docs/guides/images>
|
|
698
698
|
|
|
699
699
|
Request throttling:
|
|
700
700
|
Applies the rate limit set in the config (section `openai.rate_limits`; use the model id as the key). If no rate
|
|
@@ -708,7 +708,7 @@ async def image_generations(
|
|
|
708
708
|
prompt: Prompt for the image.
|
|
709
709
|
model: The model to use for the generations.
|
|
710
710
|
|
|
711
|
-
For details on the other parameters, see:
|
|
711
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/images/create>
|
|
712
712
|
|
|
713
713
|
Returns:
|
|
714
714
|
The generated image.
|
|
@@ -761,7 +761,7 @@ async def moderations(input: str, *, model: str = 'omni-moderation-latest') -> d
|
|
|
761
761
|
Classifies if text is potentially harmful.
|
|
762
762
|
|
|
763
763
|
Equivalent to the OpenAI `moderations` API endpoint.
|
|
764
|
-
For additional details, see:
|
|
764
|
+
For additional details, see: <https://platform.openai.com/docs/guides/moderation>
|
|
765
765
|
|
|
766
766
|
Request throttling:
|
|
767
767
|
Applies the rate limit set in the config (section `openai.rate_limits`; use the model id as the key). If no rate
|
|
@@ -775,7 +775,7 @@ async def moderations(input: str, *, model: str = 'omni-moderation-latest') -> d
|
|
|
775
775
|
input: Text to analyze with the moderations model.
|
|
776
776
|
model: The model to use for moderations.
|
|
777
777
|
|
|
778
|
-
For details on the other parameters, see:
|
|
778
|
+
For details on the other parameters, see: <https://platform.openai.com/docs/api-reference/moderations>
|
|
779
779
|
|
|
780
780
|
Returns:
|
|
781
781
|
Details of the moderations results.
|
|
@@ -816,10 +816,13 @@ def _openai_response_to_pxt_tool_calls(response: dict) -> Optional[dict]:
|
|
|
816
816
|
if 'tool_calls' not in response['choices'][0]['message'] or response['choices'][0]['message']['tool_calls'] is None:
|
|
817
817
|
return None
|
|
818
818
|
openai_tool_calls = response['choices'][0]['message']['tool_calls']
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
819
|
+
pxt_tool_calls: dict[str, list[dict[str, Any]]] = {}
|
|
820
|
+
for tool_call in openai_tool_calls:
|
|
821
|
+
tool_name = tool_call['function']['name']
|
|
822
|
+
if tool_name not in pxt_tool_calls:
|
|
823
|
+
pxt_tool_calls[tool_name] = []
|
|
824
|
+
pxt_tool_calls[tool_name].append({'args': json.loads(tool_call['function']['arguments'])})
|
|
825
|
+
return pxt_tool_calls
|
|
823
826
|
|
|
824
827
|
|
|
825
828
|
_T = TypeVar('_T')
|
pixeltable/functions/string.py
CHANGED
|
@@ -12,10 +12,10 @@ t.select(pxt_str.capitalize(t.str_col)).collect()
|
|
|
12
12
|
```
|
|
13
13
|
"""
|
|
14
14
|
|
|
15
|
+
import builtins
|
|
15
16
|
from typing import Any, Optional
|
|
16
17
|
|
|
17
18
|
import pixeltable as pxt
|
|
18
|
-
import pixeltable.exceptions as excs
|
|
19
19
|
from pixeltable.utils.code import local_public_names
|
|
20
20
|
|
|
21
21
|
|
|
@@ -70,11 +70,10 @@ def contains(self: str, pattern: str, case: bool = True, flags: int = 0, regex:
|
|
|
70
70
|
if not case:
|
|
71
71
|
flags |= re.IGNORECASE
|
|
72
72
|
return bool(re.search(pattern, self, flags))
|
|
73
|
+
elif case:
|
|
74
|
+
return pattern in self
|
|
73
75
|
else:
|
|
74
|
-
|
|
75
|
-
return pattern in self
|
|
76
|
-
else:
|
|
77
|
-
return pattern.lower() in self.lower()
|
|
76
|
+
return pattern.lower() in self.lower()
|
|
78
77
|
|
|
79
78
|
|
|
80
79
|
@pxt.udf(is_method=True)
|
|
@@ -87,9 +86,8 @@ def count(self: str, pattern: str, flags: int = 0) -> int:
|
|
|
87
86
|
flags: [flags](https://docs.python.org/3/library/re.html#flags) for the `re` module
|
|
88
87
|
"""
|
|
89
88
|
import re
|
|
90
|
-
from builtins import len
|
|
91
89
|
|
|
92
|
-
return len(re.findall(pattern, self, flags))
|
|
90
|
+
return builtins.len(re.findall(pattern, self, flags))
|
|
93
91
|
|
|
94
92
|
|
|
95
93
|
@pxt.udf(is_method=True)
|
|
@@ -263,7 +261,8 @@ def isidentifier(self: str) -> bool:
|
|
|
263
261
|
@pxt.udf(is_method=True)
|
|
264
262
|
def islower(self: str) -> bool:
|
|
265
263
|
"""
|
|
266
|
-
Return `True` if all cased characters in the string are lowercase and there is at least one cased character,
|
|
264
|
+
Return `True` if all cased characters in the string are lowercase and there is at least one cased character,
|
|
265
|
+
`False` otherwise.
|
|
267
266
|
|
|
268
267
|
Equivalent to [`str.islower()`](https://docs.python.org/3/library/stdtypes.html#str.islower)
|
|
269
268
|
"""
|
|
@@ -283,7 +282,8 @@ def isnumeric(self: str) -> bool:
|
|
|
283
282
|
@pxt.udf(is_method=True)
|
|
284
283
|
def isupper(self: str) -> bool:
|
|
285
284
|
"""
|
|
286
|
-
Return `True` if all cased characters in the string are uppercase and there is at least one cased character,
|
|
285
|
+
Return `True` if all cased characters in the string are uppercase and there is at least one cased character,
|
|
286
|
+
`False` otherwise.
|
|
287
287
|
|
|
288
288
|
Equivalent to [`str.isupper()`](https://docs.python.org/3/library/stdtypes.html#str.isupper)
|
|
289
289
|
"""
|
|
@@ -303,7 +303,8 @@ def istitle(self: str) -> bool:
|
|
|
303
303
|
@pxt.udf(is_method=True)
|
|
304
304
|
def isspace(self: str) -> bool:
|
|
305
305
|
"""
|
|
306
|
-
Return `True` if there are only whitespace characters in the string and there is at least one character,
|
|
306
|
+
Return `True` if there are only whitespace characters in the string and there is at least one character,
|
|
307
|
+
`False` otherwise.
|
|
307
308
|
|
|
308
309
|
Equivalent to [`str.isspace()`](https://docs.python.org/3/library/stdtypes.html#str.isspace)
|
|
309
310
|
"""
|
|
@@ -327,7 +328,7 @@ def len(self: str) -> int:
|
|
|
327
328
|
|
|
328
329
|
Equivalent to [`len(str)`](https://docs.python.org/3/library/functions.html#len)
|
|
329
330
|
"""
|
|
330
|
-
return
|
|
331
|
+
return builtins.len(self)
|
|
331
332
|
|
|
332
333
|
|
|
333
334
|
@pxt.udf(is_method=True)
|
|
@@ -338,7 +339,8 @@ def ljust(self: str, width: int, fillchar: str = ' ') -> str:
|
|
|
338
339
|
Equivalent to [`str.ljust()`](https://docs.python.org/3/library/stdtypes.html#str.ljust)
|
|
339
340
|
|
|
340
341
|
Args:
|
|
341
|
-
width: Minimum width of resulting string; additional characters will be filled with character defined in
|
|
342
|
+
width: Minimum width of resulting string; additional characters will be filled with character defined in
|
|
343
|
+
`fillchar`.
|
|
342
344
|
fillchar: Additional character for filling.
|
|
343
345
|
"""
|
|
344
346
|
return self.ljust(width, fillchar)
|
|
@@ -393,7 +395,7 @@ def normalize(self: str, form: str) -> str:
|
|
|
393
395
|
Equivalent to [`unicodedata.normalize()`](https://docs.python.org/3/library/unicodedata.html#unicodedata.normalize)
|
|
394
396
|
|
|
395
397
|
Args:
|
|
396
|
-
form: Unicode normal form (
|
|
398
|
+
form: Unicode normal form (`'NFC'`, `'NFKC'`, `'NFD'`, `'NFKD'`)
|
|
397
399
|
"""
|
|
398
400
|
import unicodedata
|
|
399
401
|
|
|
@@ -406,8 +408,9 @@ def pad(self: str, width: int, side: str = 'left', fillchar: str = ' ') -> str:
|
|
|
406
408
|
Pad string up to width
|
|
407
409
|
|
|
408
410
|
Args:
|
|
409
|
-
width: Minimum width of resulting string; additional characters will be filled with character defined in
|
|
410
|
-
|
|
411
|
+
width: Minimum width of resulting string; additional characters will be filled with character defined in
|
|
412
|
+
`fillchar`.
|
|
413
|
+
side: Side from which to fill resulting string (`'left'`, `'right'`, `'both'`)
|
|
411
414
|
fillchar: Additional character for filling
|
|
412
415
|
"""
|
|
413
416
|
if side == 'left':
|
|
@@ -430,9 +433,7 @@ def partition(self: str, sep: str = ' ') -> list:
|
|
|
430
433
|
idx = self.find(sep)
|
|
431
434
|
if idx == -1:
|
|
432
435
|
return [self, '', '']
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
return [self[:idx], sep, self[idx + len(sep) :]]
|
|
436
|
+
return [self[:idx], sep, self[idx + builtins.len(sep) :]]
|
|
436
437
|
|
|
437
438
|
|
|
438
439
|
@pxt.udf(is_method=True)
|
|
@@ -441,10 +442,7 @@ def removeprefix(self: str, prefix: str) -> str:
|
|
|
441
442
|
Remove prefix. If the prefix is not present, returns string.
|
|
442
443
|
"""
|
|
443
444
|
if self.startswith(prefix):
|
|
444
|
-
|
|
445
|
-
from builtins import len
|
|
446
|
-
|
|
447
|
-
return self[len(prefix) :]
|
|
445
|
+
return self[builtins.len(prefix) :]
|
|
448
446
|
return self
|
|
449
447
|
|
|
450
448
|
|
|
@@ -454,10 +452,7 @@ def removesuffix(self: str, suffix: str) -> str:
|
|
|
454
452
|
Remove suffix. If the suffix is not present, returns string.
|
|
455
453
|
"""
|
|
456
454
|
if self.endswith(suffix):
|
|
457
|
-
|
|
458
|
-
from builtins import len
|
|
459
|
-
|
|
460
|
-
return self[: -len(suffix)]
|
|
455
|
+
return self[: -builtins.len(suffix)]
|
|
461
456
|
return self
|
|
462
457
|
|
|
463
458
|
|
|
@@ -492,7 +487,7 @@ def replace(
|
|
|
492
487
|
|
|
493
488
|
if not case:
|
|
494
489
|
flags |= re.IGNORECASE
|
|
495
|
-
return re.sub(pattern, repl, self, 0 if n == -1 else n, flags)
|
|
490
|
+
return re.sub(pattern, repl, self, count=(0 if n == -1 else n), flags=flags)
|
|
496
491
|
else:
|
|
497
492
|
return self.replace(pattern, repl, n)
|
|
498
493
|
|
|
@@ -546,9 +541,7 @@ def rpartition(self: str, sep: str = ' ') -> list:
|
|
|
546
541
|
idx = self.rfind(sep)
|
|
547
542
|
if idx == -1:
|
|
548
543
|
return [self, '', '']
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
return [self[:idx], sep, self[idx + len(sep) :]]
|
|
544
|
+
return [self[:idx], sep, self[idx + builtins.len(sep) :]]
|
|
552
545
|
|
|
553
546
|
|
|
554
547
|
@pxt.udf(is_method=True)
|
|
@@ -19,6 +19,8 @@ import pixeltable as pxt
|
|
|
19
19
|
from pixeltable.env import Env
|
|
20
20
|
from pixeltable.utils.code import local_public_names
|
|
21
21
|
|
|
22
|
+
_SQL_ZERO = sql.literal(0)
|
|
23
|
+
|
|
22
24
|
|
|
23
25
|
@pxt.udf(is_property=True)
|
|
24
26
|
def year(self: datetime) -> int:
|
|
@@ -191,7 +193,9 @@ def isoformat(self: datetime, sep: str = 'T', timespec: str = 'auto') -> str:
|
|
|
191
193
|
|
|
192
194
|
Args:
|
|
193
195
|
sep: Separator between date and time.
|
|
194
|
-
timespec: The number of additional terms in the output. See the
|
|
196
|
+
timespec: The number of additional terms in the output. See the
|
|
197
|
+
[`datetime.isoformat()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat)
|
|
198
|
+
documentation for more details.
|
|
195
199
|
"""
|
|
196
200
|
return self.isoformat(sep=sep, timespec=timespec)
|
|
197
201
|
|
|
@@ -204,7 +208,8 @@ def strftime(self: datetime, format: str) -> str:
|
|
|
204
208
|
Equivalent to [`datetime.strftime()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.strftime).
|
|
205
209
|
|
|
206
210
|
Args:
|
|
207
|
-
format: The format string to control the output. For a complete list of formatting directives, see
|
|
211
|
+
format: The format string to control the output. For a complete list of formatting directives, see
|
|
212
|
+
[`strftime()` and `strptime()` Behavior](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior).
|
|
208
213
|
"""
|
|
209
214
|
return self.strftime(format)
|
|
210
215
|
|
|
@@ -226,10 +231,10 @@ def _(
|
|
|
226
231
|
year: sql.ColumnElement,
|
|
227
232
|
month: sql.ColumnElement,
|
|
228
233
|
day: sql.ColumnElement,
|
|
229
|
-
hour: sql.ColumnElement =
|
|
230
|
-
minute: sql.ColumnElement =
|
|
231
|
-
second: sql.ColumnElement =
|
|
232
|
-
microsecond: sql.ColumnElement =
|
|
234
|
+
hour: sql.ColumnElement = _SQL_ZERO,
|
|
235
|
+
minute: sql.ColumnElement = _SQL_ZERO,
|
|
236
|
+
second: sql.ColumnElement = _SQL_ZERO,
|
|
237
|
+
microsecond: sql.ColumnElement = _SQL_ZERO,
|
|
233
238
|
) -> sql.ColumnElement:
|
|
234
239
|
return sql.func.make_timestamptz(
|
|
235
240
|
sql.cast(year, sql.Integer),
|
pixeltable/functions/together.py
CHANGED
|
@@ -68,7 +68,7 @@ async def completions(
|
|
|
68
68
|
Generate completions based on a given prompt using a specified model.
|
|
69
69
|
|
|
70
70
|
Equivalent to the Together AI `completions` API endpoint.
|
|
71
|
-
For additional details, see:
|
|
71
|
+
For additional details, see: <https://docs.together.ai/reference/completions-1>
|
|
72
72
|
|
|
73
73
|
Request throttling:
|
|
74
74
|
Applies the rate limit set in the config (section `together.rate_limits`, key `chat`). If no rate
|
|
@@ -82,14 +82,14 @@ async def completions(
|
|
|
82
82
|
prompt: A string providing context for the model to complete.
|
|
83
83
|
model: The name of the model to query.
|
|
84
84
|
|
|
85
|
-
For details on the other parameters, see:
|
|
85
|
+
For details on the other parameters, see: <https://docs.together.ai/reference/completions-1>
|
|
86
86
|
|
|
87
87
|
Returns:
|
|
88
88
|
A dictionary containing the response and other metadata.
|
|
89
89
|
|
|
90
90
|
Examples:
|
|
91
|
-
Add a computed column that applies the model `mistralai/Mixtral-8x7B-v0.1` to an existing Pixeltable column
|
|
92
|
-
of the table `tbl`:
|
|
91
|
+
Add a computed column that applies the model `mistralai/Mixtral-8x7B-v0.1` to an existing Pixeltable column
|
|
92
|
+
`tbl.prompt` of the table `tbl`:
|
|
93
93
|
|
|
94
94
|
>>> tbl.add_computed_column(response=completions(tbl.prompt, model='mistralai/Mixtral-8x7B-v0.1'))
|
|
95
95
|
"""
|
|
@@ -133,7 +133,7 @@ async def chat_completions(
|
|
|
133
133
|
Generate chat completions based on a given prompt using a specified model.
|
|
134
134
|
|
|
135
135
|
Equivalent to the Together AI `chat/completions` API endpoint.
|
|
136
|
-
For additional details, see:
|
|
136
|
+
For additional details, see: <https://docs.together.ai/reference/chat-completions-1>
|
|
137
137
|
|
|
138
138
|
Request throttling:
|
|
139
139
|
Applies the rate limit set in the config (section `together.rate_limits`, key `chat`). If no rate
|
|
@@ -147,14 +147,14 @@ async def chat_completions(
|
|
|
147
147
|
messages: A list of messages comprising the conversation so far.
|
|
148
148
|
model: The name of the model to query.
|
|
149
149
|
|
|
150
|
-
For details on the other parameters, see:
|
|
150
|
+
For details on the other parameters, see: <https://docs.together.ai/reference/chat-completions-1>
|
|
151
151
|
|
|
152
152
|
Returns:
|
|
153
153
|
A dictionary containing the response and other metadata.
|
|
154
154
|
|
|
155
155
|
Examples:
|
|
156
|
-
Add a computed column that applies the model `mistralai/Mixtral-8x7B-v0.1` to an existing Pixeltable column
|
|
157
|
-
of the table `tbl`:
|
|
156
|
+
Add a computed column that applies the model `mistralai/Mixtral-8x7B-v0.1` to an existing Pixeltable column
|
|
157
|
+
`tbl.prompt` of the table `tbl`:
|
|
158
158
|
|
|
159
159
|
>>> messages = [{'role': 'user', 'content': tbl.prompt}]
|
|
160
160
|
... tbl.add_computed_column(response=chat_completions(messages, model='mistralai/Mixtral-8x7B-v0.1'))
|
|
@@ -197,7 +197,7 @@ async def embeddings(input: Batch[str], *, model: str) -> Batch[pxt.Array[(None,
|
|
|
197
197
|
Query an embedding model for a given string of text.
|
|
198
198
|
|
|
199
199
|
Equivalent to the Together AI `embeddings` API endpoint.
|
|
200
|
-
For additional details, see:
|
|
200
|
+
For additional details, see: <https://docs.together.ai/reference/embeddings-2>
|
|
201
201
|
|
|
202
202
|
Request throttling:
|
|
203
203
|
Applies the rate limit set in the config (section `together.rate_limits`, key `embeddings`). If no rate
|
|
@@ -248,7 +248,7 @@ async def image_generations(
|
|
|
248
248
|
Generate images based on a given prompt using a specified model.
|
|
249
249
|
|
|
250
250
|
Equivalent to the Together AI `images/generations` API endpoint.
|
|
251
|
-
For additional details, see:
|
|
251
|
+
For additional details, see: <https://docs.together.ai/reference/post_images-generations>
|
|
252
252
|
|
|
253
253
|
Request throttling:
|
|
254
254
|
Applies the rate limit set in the config (section `together.rate_limits`, key `images`). If no rate
|
|
@@ -262,7 +262,7 @@ async def image_generations(
|
|
|
262
262
|
prompt: A description of the desired images.
|
|
263
263
|
model: The model to use for image generation.
|
|
264
264
|
|
|
265
|
-
For details on the other parameters, see:
|
|
265
|
+
For details on the other parameters, see: <https://docs.together.ai/reference/post_images-generations>
|
|
266
266
|
|
|
267
267
|
Returns:
|
|
268
268
|
The generated image.
|
|
@@ -271,7 +271,9 @@ async def image_generations(
|
|
|
271
271
|
Add a computed column that applies the model `stabilityai/stable-diffusion-xl-base-1.0`
|
|
272
272
|
to an existing Pixeltable column `tbl.prompt` of the table `tbl`:
|
|
273
273
|
|
|
274
|
-
>>> tbl.add_computed_column(
|
|
274
|
+
>>> tbl.add_computed_column(
|
|
275
|
+
... response=image_generations(tbl.prompt, model='stabilityai/stable-diffusion-xl-base-1.0')
|
|
276
|
+
... )
|
|
275
277
|
"""
|
|
276
278
|
result = await _together_client().images.generate(
|
|
277
279
|
prompt=prompt, model=model, steps=steps, seed=seed, height=height, width=width, negative_prompt=negative_prompt
|
pixeltable/functions/util.py
CHANGED
|
@@ -21,7 +21,7 @@ def normalize_image_mode(image: PIL.Image.Image) -> PIL.Image.Image:
|
|
|
21
21
|
Converts grayscale images to 3-channel for compatibility with models that only work with
|
|
22
22
|
multichannel input.
|
|
23
23
|
"""
|
|
24
|
-
if image.mode
|
|
24
|
+
if image.mode in {'1', 'L'}:
|
|
25
25
|
return image.convert('RGB')
|
|
26
26
|
if image.mode == 'LA':
|
|
27
27
|
return image.convert('RGBA')
|
pixeltable/functions/video.py
CHANGED
|
@@ -21,18 +21,19 @@ import numpy as np
|
|
|
21
21
|
import PIL.Image
|
|
22
22
|
|
|
23
23
|
import pixeltable as pxt
|
|
24
|
-
|
|
24
|
+
from pixeltable import env
|
|
25
25
|
from pixeltable.utils.code import local_public_names
|
|
26
26
|
|
|
27
27
|
_format_defaults = { # format -> (codec, ext)
|
|
28
28
|
'wav': ('pcm_s16le', 'wav'),
|
|
29
29
|
'mp3': ('libmp3lame', 'mp3'),
|
|
30
30
|
'flac': ('flac', 'flac'),
|
|
31
|
-
#'mp4': ('aac', 'm4a'),
|
|
31
|
+
# 'mp4': ('aac', 'm4a'),
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
# for mp4:
|
|
35
|
-
# - extract_audio() fails with
|
|
35
|
+
# - extract_audio() fails with
|
|
36
|
+
# "Application provided invalid, non monotonically increasing dts to muxer in stream 0: 1146 >= 290"
|
|
36
37
|
# - chatgpt suggests this can be fixed in the following manner
|
|
37
38
|
# for packet in container.demux(audio_stream):
|
|
38
39
|
# packet.pts = None # Reset the PTS and DTS to allow FFmpeg to set them automatically
|
|
@@ -142,7 +143,7 @@ def _get_metadata(path: str) -> dict:
|
|
|
142
143
|
|
|
143
144
|
|
|
144
145
|
def __get_stream_metadata(stream: av.stream.Stream) -> dict:
|
|
145
|
-
if stream.type
|
|
146
|
+
if stream.type not in {'audio', 'video'}:
|
|
146
147
|
return {'type': stream.type} # Currently unsupported
|
|
147
148
|
|
|
148
149
|
codec_context = stream.codec_context
|