pixeltable 0.3.6__py3-none-any.whl → 0.3.8__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.

Files changed (127) hide show
  1. pixeltable/__init__.py +5 -3
  2. pixeltable/__version__.py +2 -2
  3. pixeltable/catalog/__init__.py +1 -0
  4. pixeltable/catalog/catalog.py +335 -128
  5. pixeltable/catalog/column.py +22 -5
  6. pixeltable/catalog/dir.py +19 -6
  7. pixeltable/catalog/insertable_table.py +34 -37
  8. pixeltable/catalog/named_function.py +0 -4
  9. pixeltable/catalog/schema_object.py +28 -42
  10. pixeltable/catalog/table.py +193 -158
  11. pixeltable/catalog/table_version.py +191 -232
  12. pixeltable/catalog/table_version_handle.py +50 -0
  13. pixeltable/catalog/table_version_path.py +49 -33
  14. pixeltable/catalog/view.py +56 -96
  15. pixeltable/config.py +103 -0
  16. pixeltable/dataframe.py +89 -89
  17. pixeltable/env.py +98 -168
  18. pixeltable/exec/aggregation_node.py +5 -4
  19. pixeltable/exec/cache_prefetch_node.py +1 -1
  20. pixeltable/exec/component_iteration_node.py +13 -9
  21. pixeltable/exec/data_row_batch.py +3 -3
  22. pixeltable/exec/exec_context.py +0 -4
  23. pixeltable/exec/exec_node.py +3 -2
  24. pixeltable/exec/expr_eval/schedulers.py +2 -1
  25. pixeltable/exec/in_memory_data_node.py +9 -4
  26. pixeltable/exec/row_update_node.py +1 -2
  27. pixeltable/exec/sql_node.py +20 -16
  28. pixeltable/exprs/__init__.py +2 -0
  29. pixeltable/exprs/arithmetic_expr.py +7 -11
  30. pixeltable/exprs/array_slice.py +1 -1
  31. pixeltable/exprs/column_property_ref.py +3 -3
  32. pixeltable/exprs/column_ref.py +12 -13
  33. pixeltable/exprs/comparison.py +3 -6
  34. pixeltable/exprs/compound_predicate.py +4 -4
  35. pixeltable/exprs/expr.py +31 -22
  36. pixeltable/exprs/expr_dict.py +3 -3
  37. pixeltable/exprs/expr_set.py +1 -1
  38. pixeltable/exprs/function_call.py +110 -80
  39. pixeltable/exprs/globals.py +3 -3
  40. pixeltable/exprs/in_predicate.py +1 -1
  41. pixeltable/exprs/inline_expr.py +3 -3
  42. pixeltable/exprs/is_null.py +1 -1
  43. pixeltable/exprs/json_mapper.py +2 -2
  44. pixeltable/exprs/json_path.py +17 -10
  45. pixeltable/exprs/literal.py +1 -1
  46. pixeltable/exprs/method_ref.py +2 -2
  47. pixeltable/exprs/row_builder.py +8 -17
  48. pixeltable/exprs/rowid_ref.py +21 -10
  49. pixeltable/exprs/similarity_expr.py +5 -5
  50. pixeltable/exprs/sql_element_cache.py +1 -1
  51. pixeltable/exprs/type_cast.py +2 -3
  52. pixeltable/exprs/variable.py +2 -2
  53. pixeltable/ext/__init__.py +2 -0
  54. pixeltable/ext/functions/__init__.py +2 -0
  55. pixeltable/ext/functions/yolox.py +3 -3
  56. pixeltable/func/__init__.py +3 -1
  57. pixeltable/func/aggregate_function.py +9 -9
  58. pixeltable/func/callable_function.py +3 -4
  59. pixeltable/func/expr_template_function.py +6 -16
  60. pixeltable/func/function.py +48 -14
  61. pixeltable/func/function_registry.py +1 -3
  62. pixeltable/func/query_template_function.py +5 -12
  63. pixeltable/func/signature.py +23 -22
  64. pixeltable/func/tools.py +3 -3
  65. pixeltable/func/udf.py +6 -4
  66. pixeltable/functions/__init__.py +2 -0
  67. pixeltable/functions/fireworks.py +7 -4
  68. pixeltable/functions/globals.py +4 -5
  69. pixeltable/functions/huggingface.py +1 -5
  70. pixeltable/functions/image.py +17 -7
  71. pixeltable/functions/llama_cpp.py +1 -1
  72. pixeltable/functions/mistralai.py +1 -1
  73. pixeltable/functions/ollama.py +4 -4
  74. pixeltable/functions/openai.py +19 -19
  75. pixeltable/functions/string.py +23 -30
  76. pixeltable/functions/timestamp.py +11 -6
  77. pixeltable/functions/together.py +14 -12
  78. pixeltable/functions/util.py +1 -1
  79. pixeltable/functions/video.py +5 -4
  80. pixeltable/functions/vision.py +6 -9
  81. pixeltable/functions/whisper.py +3 -3
  82. pixeltable/globals.py +246 -260
  83. pixeltable/index/__init__.py +2 -0
  84. pixeltable/index/base.py +1 -1
  85. pixeltable/index/btree.py +3 -1
  86. pixeltable/index/embedding_index.py +11 -5
  87. pixeltable/io/external_store.py +11 -12
  88. pixeltable/io/label_studio.py +4 -3
  89. pixeltable/io/parquet.py +57 -56
  90. pixeltable/iterators/__init__.py +4 -2
  91. pixeltable/iterators/audio.py +11 -11
  92. pixeltable/iterators/document.py +10 -10
  93. pixeltable/iterators/string.py +1 -2
  94. pixeltable/iterators/video.py +14 -15
  95. pixeltable/metadata/__init__.py +9 -5
  96. pixeltable/metadata/converters/convert_10.py +0 -1
  97. pixeltable/metadata/converters/convert_15.py +0 -2
  98. pixeltable/metadata/converters/convert_23.py +0 -2
  99. pixeltable/metadata/converters/convert_24.py +3 -3
  100. pixeltable/metadata/converters/convert_25.py +1 -1
  101. pixeltable/metadata/converters/convert_27.py +0 -2
  102. pixeltable/metadata/converters/convert_28.py +0 -2
  103. pixeltable/metadata/converters/convert_29.py +7 -8
  104. pixeltable/metadata/converters/util.py +7 -7
  105. pixeltable/metadata/schema.py +27 -19
  106. pixeltable/plan.py +68 -40
  107. pixeltable/share/__init__.py +2 -0
  108. pixeltable/share/packager.py +15 -12
  109. pixeltable/share/publish.py +3 -5
  110. pixeltable/store.py +37 -38
  111. pixeltable/type_system.py +41 -28
  112. pixeltable/utils/coco.py +4 -4
  113. pixeltable/utils/console_output.py +1 -3
  114. pixeltable/utils/description_helper.py +1 -1
  115. pixeltable/utils/documents.py +3 -3
  116. pixeltable/utils/filecache.py +20 -9
  117. pixeltable/utils/formatter.py +2 -3
  118. pixeltable/utils/media_store.py +1 -1
  119. pixeltable/utils/pytorch.py +1 -1
  120. pixeltable/utils/sql.py +4 -4
  121. pixeltable/utils/transactional_directory.py +2 -1
  122. {pixeltable-0.3.6.dist-info → pixeltable-0.3.8.dist-info}/METADATA +1 -1
  123. pixeltable-0.3.8.dist-info/RECORD +174 -0
  124. pixeltable-0.3.6.dist-info/RECORD +0 -172
  125. {pixeltable-0.3.6.dist-info → pixeltable-0.3.8.dist-info}/LICENSE +0 -0
  126. {pixeltable-0.3.6.dist-info → pixeltable-0.3.8.dist-info}/WHEEL +0 -0
  127. {pixeltable-0.3.6.dist-info → pixeltable-0.3.8.dist-info}/entry_points.txt +0 -0
@@ -9,6 +9,7 @@ from typing import TYPE_CHECKING, Optional
9
9
 
10
10
  import pixeltable as pxt
11
11
  from pixeltable import env
12
+ from pixeltable.config import Config
12
13
  from pixeltable.utils.code import local_public_names
13
14
 
14
15
  if TYPE_CHECKING:
@@ -41,7 +42,7 @@ async def chat_completions(
41
42
  Creates a model response for the given chat conversation.
42
43
 
43
44
  Equivalent to the Fireworks AI `chat/completions` API endpoint.
44
- For additional details, see: [https://docs.fireworks.ai/api-reference/post-chatcompletions](https://docs.fireworks.ai/api-reference/post-chatcompletions)
45
+ For additional details, see: <https://docs.fireworks.ai/api-reference/post-chatcompletions>
45
46
 
46
47
  Request throttling:
47
48
  Applies the rate limit set in the config (section `fireworks`, key `rate_limit`). If no rate
@@ -55,7 +56,7 @@ async def chat_completions(
55
56
  messages: A list of messages comprising the conversation so far.
56
57
  model: The name of the model to use.
57
58
 
58
- For details on the other parameters, see: [https://docs.fireworks.ai/api-reference/post-chatcompletions](https://docs.fireworks.ai/api-reference/post-chatcompletions)
59
+ For details on the other parameters, see: <https://docs.fireworks.ai/api-reference/post-chatcompletions>
59
60
 
60
61
  Returns:
61
62
  A dictionary containing the response and other metadata.
@@ -65,7 +66,9 @@ async def chat_completions(
65
66
  to an existing Pixeltable column `tbl.prompt` of the table `tbl`:
66
67
 
67
68
  >>> messages = [{'role': 'user', 'content': tbl.prompt}]
68
- ... tbl.add_computed_column(response=chat_completions(messages, model='accounts/fireworks/models/mixtral-8x22b-instruct'))
69
+ ... tbl.add_computed_column(
70
+ ... response=chat_completions(messages, model='accounts/fireworks/models/mixtral-8x22b-instruct')
71
+ ... )
69
72
  """
70
73
  kwargs = {'max_tokens': max_tokens, 'top_k': top_k, 'top_p': top_p, 'temperature': temperature}
71
74
  kwargs_not_none = {k: v for k, v in kwargs.items() if v is not None}
@@ -75,7 +78,7 @@ async def chat_completions(
75
78
  # res_sync_dict = res_sync.dict()
76
79
 
77
80
  if request_timeout is None:
78
- request_timeout = env.Env.get().config.get_int_value('timeout', section='fireworks') or 600
81
+ request_timeout = Config.get().get_int_value('timeout', section='fireworks') or 600
79
82
  # TODO: this timeout doesn't really work, I think it only applies to returning the stream, but not to the timing
80
83
  # of the chunks; addressing this would require a timeout for the task running this udf
81
84
  stream = _fireworks_client().chat.completions.acreate(
@@ -6,9 +6,8 @@ from typing import Optional, Union
6
6
 
7
7
  import sqlalchemy as sql
8
8
 
9
- import pixeltable.func as func
10
9
  import pixeltable.type_system as ts
11
- from pixeltable import exprs
10
+ from pixeltable import exprs, func
12
11
  from pixeltable.utils.code import local_public_names
13
12
 
14
13
 
@@ -50,7 +49,6 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
50
49
  @func.uda(
51
50
  allows_window=True,
52
51
  # Allow counting non-null values of any type
53
- # TODO: I couldn't include "Array" because we don't have a way to represent a generic array (of arbitrary dimension).
54
52
  # TODO: should we have an "Any" type that can be used here?
55
53
  type_substitutions=tuple(
56
54
  {T: Optional[t]} # type: ignore[misc]
@@ -60,6 +58,7 @@ def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
60
58
  ts.Float,
61
59
  ts.Bool,
62
60
  ts.Timestamp,
61
+ ts.Array,
63
62
  ts.Json,
64
63
  ts.Image,
65
64
  ts.Video,
@@ -107,7 +106,7 @@ class min(func.Aggregator, typing.Generic[T]):
107
106
 
108
107
  @min.to_sql
109
108
  def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
110
- if val.type.python_type == bool:
109
+ if val.type.python_type is bool:
111
110
  # TODO: min/max aggregation of booleans is not supported in Postgres (but it is in Python).
112
111
  # Right now we simply force the computation to be done in Python; we might consider implementing an alternate
113
112
  # way of doing it in SQL. (min/max of booleans is simply logical and/or, respectively.)
@@ -137,7 +136,7 @@ class max(func.Aggregator, typing.Generic[T]):
137
136
 
138
137
  @max.to_sql
139
138
  def _(val: sql.ColumnElement) -> Optional[sql.ColumnElement]:
140
- if val.type.python_type == bool:
139
+ if val.type.python_type is bool:
141
140
  # TODO: see comment in @min.to_sql.
142
141
  return None
143
142
  return sql.sql.func.max(val)
@@ -12,8 +12,8 @@ from typing import Any, Callable, Optional, TypeVar
12
12
  import PIL.Image
13
13
 
14
14
  import pixeltable as pxt
15
- import pixeltable.env as env
16
15
  import pixeltable.exceptions as excs
16
+ from pixeltable import env
17
17
  from pixeltable.func import Batch
18
18
  from pixeltable.functions.util import normalize_image_mode, resolve_torch_device
19
19
  from pixeltable.utils.code import local_public_names
@@ -50,7 +50,6 @@ def sentence_transformer(
50
50
  """
51
51
  env.Env.get().require_package('sentence_transformers')
52
52
  device = resolve_torch_device('auto')
53
- import torch
54
53
  from sentence_transformers import SentenceTransformer # type: ignore
55
54
 
56
55
  # specifying the device, moves the model to device (gpu:cuda/mps, cpu)
@@ -76,7 +75,6 @@ def _(model_id: str) -> pxt.ArrayType:
76
75
  def sentence_transformer_list(sentences: list, *, model_id: str, normalize_embeddings: bool = False) -> list:
77
76
  env.Env.get().require_package('sentence_transformers')
78
77
  device = resolve_torch_device('auto')
79
- import torch
80
78
  from sentence_transformers import SentenceTransformer
81
79
 
82
80
  # specifying the device, moves the model to device (gpu:cuda/mps, cpu)
@@ -117,7 +115,6 @@ def cross_encoder(sentences1: Batch[str], sentences2: Batch[str], *, model_id: s
117
115
  """
118
116
  env.Env.get().require_package('sentence_transformers')
119
117
  device = resolve_torch_device('auto')
120
- import torch
121
118
  from sentence_transformers import CrossEncoder
122
119
 
123
120
  # specifying the device, moves the model to device (gpu:cuda/mps, cpu)
@@ -132,7 +129,6 @@ def cross_encoder(sentences1: Batch[str], sentences2: Batch[str], *, model_id: s
132
129
  def cross_encoder_list(sentence1: str, sentences2: list, *, model_id: str) -> list:
133
130
  env.Env.get().require_package('sentence_transformers')
134
131
  device = resolve_torch_device('auto')
135
- import torch
136
132
  from sentence_transformers import CrossEncoder
137
133
 
138
134
  # specifying the device, moves the model to device (gpu:cuda/mps, cpu)
@@ -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 [Pillow documentation](https://pillow.readthedocs.io/en/stable/handbook/concepts.html#concept-modes) for a list of supported modes.
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) or isinstance(box, tuple)) and len(box) == 4 and all(isinstance(x, int) for x in box):
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 [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.transpose) for a list of supported methods.
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, trim pixels when all channels are zero.
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 [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize) for a list of supported methods.
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 [Pillow documentation](https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.quantize) for a list of supported methods.
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 (0, 0, width, height) rectangle. If omitted or None, the entire source is used.
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
 
@@ -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 `top_k`.
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 `top_k`.
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
  """
@@ -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: [https://platform.openai.com/docs/guides/text-to-speech](https://platform.openai.com/docs/guides/text-to-speech)
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: [https://platform.openai.com/docs/api-reference/audio/createSpeech](https://platform.openai.com/docs/api-reference/audio/createSpeech)
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: [https://platform.openai.com/docs/guides/speech-to-text](https://platform.openai.com/docs/guides/speech-to-text)
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: [https://platform.openai.com/docs/api-reference/audio/createTranscription](https://platform.openai.com/docs/api-reference/audio/createTranscription)
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: [https://platform.openai.com/docs/guides/speech-to-text](https://platform.openai.com/docs/guides/speech-to-text)
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: [https://platform.openai.com/docs/api-reference/audio/createTranslation](https://platform.openai.com/docs/api-reference/audio/createTranslation)
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: [https://platform.openai.com/docs/guides/chat-completions](https://platform.openai.com/docs/guides/chat-completions)
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: [https://platform.openai.com/docs/api-reference/chat](https://platform.openai.com/docs/api-reference/chat)
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
- 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)
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: [https://platform.openai.com/docs/guides/vision](https://platform.openai.com/docs/guides/vision)
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: [https://platform.openai.com/docs/guides/embeddings](https://platform.openai.com/docs/guides/embeddings)
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: [https://platform.openai.com/docs/api-reference/embeddings](https://platform.openai.com/docs/api-reference/embeddings)
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, None)
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: [https://platform.openai.com/docs/guides/images](https://platform.openai.com/docs/guides/images)
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: [https://platform.openai.com/docs/api-reference/images/create](https://platform.openai.com/docs/api-reference/images/create)
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: [https://platform.openai.com/docs/guides/moderation](https://platform.openai.com/docs/guides/moderation)
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: [https://platform.openai.com/docs/api-reference/moderations](https://platform.openai.com/docs/api-reference/moderations)
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.
@@ -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
- if case:
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, `False` otherwise.
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, `False` otherwise.
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, `False` otherwise.
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 self.__len__()
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 `fillchar`.
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 (`‘NFC’`, `‘NFKC’`, `‘NFD’`, `‘NFKD’`)
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 `fillchar`.
410
- side: Side from which to fill resulting string (`‘left’`, `‘right’`, `‘both’`)
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
- from builtins import len
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
- # we need to avoid referring to our symbol 'len'
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
- # we need to avoid referring to our symbol 'len'
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
- from builtins import len
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 [`datetime.isoformat()`](https://docs.python.org/3/library/datetime.html#datetime.datetime.isoformat) documentation for more details.
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 [`strftime()` and `strptime()` Behavior](https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior).
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 = sql.literal(0),
230
- minute: sql.ColumnElement = sql.literal(0),
231
- second: sql.ColumnElement = sql.literal(0),
232
- microsecond: sql.ColumnElement = sql.literal(0),
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),