pixeltable 0.3.14__py3-none-any.whl → 0.4.0__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 (79) hide show
  1. pixeltable/__init__.py +1 -1
  2. pixeltable/__version__.py +2 -2
  3. pixeltable/catalog/__init__.py +9 -1
  4. pixeltable/catalog/catalog.py +559 -134
  5. pixeltable/catalog/column.py +36 -32
  6. pixeltable/catalog/dir.py +1 -2
  7. pixeltable/catalog/globals.py +12 -0
  8. pixeltable/catalog/insertable_table.py +30 -25
  9. pixeltable/catalog/schema_object.py +9 -6
  10. pixeltable/catalog/table.py +334 -267
  11. pixeltable/catalog/table_version.py +360 -241
  12. pixeltable/catalog/table_version_handle.py +18 -2
  13. pixeltable/catalog/table_version_path.py +86 -23
  14. pixeltable/catalog/view.py +47 -23
  15. pixeltable/dataframe.py +198 -19
  16. pixeltable/env.py +6 -4
  17. pixeltable/exceptions.py +6 -0
  18. pixeltable/exec/__init__.py +1 -1
  19. pixeltable/exec/exec_node.py +2 -0
  20. pixeltable/exec/expr_eval/evaluators.py +4 -1
  21. pixeltable/exec/expr_eval/expr_eval_node.py +4 -4
  22. pixeltable/exec/in_memory_data_node.py +1 -1
  23. pixeltable/exec/sql_node.py +188 -22
  24. pixeltable/exprs/column_property_ref.py +16 -6
  25. pixeltable/exprs/column_ref.py +33 -11
  26. pixeltable/exprs/comparison.py +1 -1
  27. pixeltable/exprs/data_row.py +5 -3
  28. pixeltable/exprs/expr.py +11 -4
  29. pixeltable/exprs/literal.py +2 -0
  30. pixeltable/exprs/row_builder.py +4 -6
  31. pixeltable/exprs/rowid_ref.py +8 -0
  32. pixeltable/exprs/similarity_expr.py +1 -0
  33. pixeltable/func/__init__.py +1 -0
  34. pixeltable/func/mcp.py +74 -0
  35. pixeltable/func/query_template_function.py +5 -3
  36. pixeltable/func/tools.py +12 -2
  37. pixeltable/func/udf.py +2 -2
  38. pixeltable/functions/__init__.py +1 -0
  39. pixeltable/functions/anthropic.py +19 -45
  40. pixeltable/functions/deepseek.py +19 -38
  41. pixeltable/functions/fireworks.py +9 -18
  42. pixeltable/functions/gemini.py +165 -33
  43. pixeltable/functions/groq.py +108 -0
  44. pixeltable/functions/llama_cpp.py +6 -6
  45. pixeltable/functions/math.py +63 -0
  46. pixeltable/functions/mistralai.py +16 -53
  47. pixeltable/functions/ollama.py +1 -1
  48. pixeltable/functions/openai.py +82 -165
  49. pixeltable/functions/string.py +212 -58
  50. pixeltable/functions/together.py +22 -80
  51. pixeltable/globals.py +10 -4
  52. pixeltable/index/base.py +5 -0
  53. pixeltable/index/btree.py +5 -0
  54. pixeltable/index/embedding_index.py +5 -0
  55. pixeltable/io/external_store.py +10 -31
  56. pixeltable/io/label_studio.py +5 -5
  57. pixeltable/io/parquet.py +4 -4
  58. pixeltable/io/table_data_conduit.py +1 -32
  59. pixeltable/metadata/__init__.py +11 -2
  60. pixeltable/metadata/converters/convert_13.py +2 -2
  61. pixeltable/metadata/converters/convert_30.py +6 -11
  62. pixeltable/metadata/converters/convert_35.py +9 -0
  63. pixeltable/metadata/converters/convert_36.py +38 -0
  64. pixeltable/metadata/converters/convert_37.py +15 -0
  65. pixeltable/metadata/converters/util.py +3 -9
  66. pixeltable/metadata/notes.py +3 -0
  67. pixeltable/metadata/schema.py +13 -1
  68. pixeltable/plan.py +135 -12
  69. pixeltable/share/packager.py +321 -20
  70. pixeltable/share/publish.py +2 -2
  71. pixeltable/store.py +31 -13
  72. pixeltable/type_system.py +30 -0
  73. pixeltable/utils/dbms.py +1 -1
  74. pixeltable/utils/formatter.py +64 -42
  75. {pixeltable-0.3.14.dist-info → pixeltable-0.4.0.dist-info}/METADATA +2 -1
  76. {pixeltable-0.3.14.dist-info → pixeltable-0.4.0.dist-info}/RECORD +79 -74
  77. {pixeltable-0.3.14.dist-info → pixeltable-0.4.0.dist-info}/LICENSE +0 -0
  78. {pixeltable-0.3.14.dist-info → pixeltable-0.4.0.dist-info}/WHEEL +0 -0
  79. {pixeltable-0.3.14.dist-info → pixeltable-0.4.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,108 @@
1
+ """
2
+ Pixeltable [UDFs](https://pixeltable.readme.io/docs/user-defined-functions-udfs)
3
+ that wrap various endpoints from the Groq API. In order to use them, you must
4
+ first `pip install groq` and configure your Groq credentials, as described in
5
+ the [Working with Groq](https://pixeltable.readme.io/docs/working-with-groq) tutorial.
6
+ """
7
+
8
+ from typing import TYPE_CHECKING, Any, Optional
9
+
10
+ import pixeltable as pxt
11
+ from pixeltable import exprs
12
+ from pixeltable.env import Env, register_client
13
+ from pixeltable.utils.code import local_public_names
14
+
15
+ from .openai import _openai_response_to_pxt_tool_calls
16
+
17
+ if TYPE_CHECKING:
18
+ import groq
19
+
20
+
21
+ @register_client('groq')
22
+ def _(api_key: str) -> 'groq.AsyncGroq':
23
+ import groq
24
+
25
+ return groq.AsyncGroq(api_key=api_key)
26
+
27
+
28
+ def _groq_client() -> 'groq.AsyncGroq':
29
+ return Env.get().get_client('groq')
30
+
31
+
32
+ @pxt.udf(resource_pool='request-rate:groq')
33
+ async def chat_completions(
34
+ messages: list[dict[str, str]],
35
+ *,
36
+ model: str,
37
+ model_kwargs: Optional[dict[str, Any]] = None,
38
+ tools: Optional[list[dict[str, Any]]] = None,
39
+ tool_choice: Optional[dict[str, Any]] = None,
40
+ ) -> dict:
41
+ """
42
+ Chat Completion API.
43
+
44
+ Equivalent to the Groq `chat/completions` API endpoint.
45
+ For additional details, see: <https://console.groq.com/docs/api-reference#chat-create>
46
+
47
+ Request throttling:
48
+ Applies the rate limit set in the config (section `groq`, key `rate_limit`). If no rate
49
+ limit is configured, uses a default of 600 RPM.
50
+
51
+ __Requirements:__
52
+
53
+ - `pip install groq`
54
+
55
+ Args:
56
+ messages: A list of messages comprising the conversation so far.
57
+ model: ID of the model to use. (See overview here: <https://console.groq.com/docs/models>)
58
+ model_kwargs: Additional keyword args for the Groq `chat/completions` API.
59
+ For details on the available parameters, see: <https://console.groq.com/docs/api-reference#chat-create>
60
+
61
+ Returns:
62
+ A dictionary containing the response and other metadata.
63
+
64
+ Examples:
65
+ Add a computed column that applies the model `llama3-8b-8192`
66
+ to an existing Pixeltable column `tbl.prompt` of the table `tbl`:
67
+
68
+ >>> messages = [{'role': 'user', 'content': tbl.prompt}]
69
+ ... tbl.add_computed_column(response=chat_completions(messages, model='llama3-8b-8192'))
70
+ """
71
+ if model_kwargs is None:
72
+ model_kwargs = {}
73
+
74
+ Env.get().require_package('groq')
75
+
76
+ if tools is not None:
77
+ model_kwargs['tools'] = [{'type': 'function', 'function': tool} for tool in tools]
78
+
79
+ if tool_choice is not None:
80
+ if tool_choice['auto']:
81
+ model_kwargs['tool_choice'] = 'auto'
82
+ elif tool_choice['required']:
83
+ model_kwargs['tool_choice'] = 'required'
84
+ else:
85
+ assert tool_choice['tool'] is not None
86
+ model_kwargs['tool_choice'] = {'type': 'function', 'function': {'name': tool_choice['tool']}}
87
+
88
+ if tool_choice is not None and not tool_choice['parallel_tool_calls']:
89
+ model_kwargs['parallel_tool_calls'] = False
90
+
91
+ result = await _groq_client().chat.completions.create(
92
+ messages=messages, # type: ignore[arg-type]
93
+ model=model,
94
+ **model_kwargs,
95
+ )
96
+ return result.model_dump()
97
+
98
+
99
+ def invoke_tools(tools: pxt.func.Tools, response: exprs.Expr) -> exprs.InlineDict:
100
+ """Converts an OpenAI response dict to Pixeltable tool invocation format and calls `tools._invoke()`."""
101
+ return tools._invoke(_openai_response_to_pxt_tool_calls(response))
102
+
103
+
104
+ __all__ = local_public_names(__name__)
105
+
106
+
107
+ def __dir__() -> list[str]:
108
+ return __all__
@@ -17,7 +17,7 @@ def create_chat_completion(
17
17
  model_path: Optional[str] = None,
18
18
  repo_id: Optional[str] = None,
19
19
  repo_filename: Optional[str] = None,
20
- args: Optional[dict[str, Any]] = None,
20
+ model_kwargs: Optional[dict[str, Any]] = None,
21
21
  ) -> dict:
22
22
  """
23
23
  Generate a chat completion from a list of messages.
@@ -35,14 +35,14 @@ def create_chat_completion(
35
35
  repo_id: The Hugging Face model repo id (if using a pretrained model).
36
36
  repo_filename: A filename or glob pattern to match the model file in the repo (optional, if using a
37
37
  pretrained model).
38
- args: Additional arguments to pass to the `create_chat_completions` call, such as `max_tokens`, `temperature`,
39
- `top_p`, and `top_k`. For details, see the
38
+ model_kwargs: Additional keyword args for the llama_cpp `create_chat_completions` API, such as `max_tokens`,
39
+ `temperature`, `top_p`, and `top_k`. For details, see the
40
40
  [llama_cpp create_chat_completions documentation](https://llama-cpp-python.readthedocs.io/en/latest/api-reference/#llama_cpp.Llama.create_chat_completion).
41
41
  """
42
42
  Env.get().require_package('llama_cpp', min_version=[0, 3, 1])
43
43
 
44
- if args is None:
45
- args = {}
44
+ if model_kwargs is None:
45
+ model_kwargs = {}
46
46
 
47
47
  if (model_path is None) == (repo_id is None):
48
48
  raise excs.Error('Exactly one of `model_path` or `repo_id` must be provided.')
@@ -56,7 +56,7 @@ def create_chat_completion(
56
56
  else:
57
57
  Env.get().require_package('huggingface_hub')
58
58
  llm = _lookup_pretrained_model(repo_id, repo_filename, n_gpu_layers)
59
- return llm.create_chat_completion(messages, **args) # type: ignore
59
+ return llm.create_chat_completion(messages, **model_kwargs) # type: ignore
60
60
 
61
61
 
62
62
  def _is_gpu_available() -> bool:
@@ -100,6 +100,69 @@ def _(self: sql.ColumnElement, digits: Optional[sql.ColumnElement] = None) -> sq
100
100
  return sql.func.round(sql.cast(self, sql.Numeric), sql.cast(digits, sql.Integer))
101
101
 
102
102
 
103
+ @pxt.udf(is_method=True)
104
+ def pow(self: int, other: int) -> float:
105
+ """
106
+ Raise `self` to the power of `other`.
107
+
108
+ Equivalent to Python [`self ** other`](https://docs.python.org/3/library/functions.html#pow).
109
+ """
110
+ return self**other
111
+
112
+
113
+ @pow.to_sql
114
+ def _(self: sql.ColumnElement, other: sql.ColumnElement) -> sql.ColumnElement:
115
+ return sql.func.pow(self, other)
116
+
117
+
118
+ @pxt.udf(is_method=True)
119
+ def bitwise_and(self: int, other: int) -> int:
120
+ """
121
+ Bitwise AND of two integers.
122
+
123
+ Equivalent to Python
124
+ [`self & other`](https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types).
125
+ """
126
+ return self & other
127
+
128
+
129
+ @bitwise_and.to_sql
130
+ def _(self: sql.ColumnElement, other: sql.ColumnElement) -> sql.ColumnElement:
131
+ return self.bitwise_and(other)
132
+
133
+
134
+ @pxt.udf(is_method=True)
135
+ def bitwise_or(self: int, other: int) -> int:
136
+ """
137
+ Bitwise OR of two integers.
138
+
139
+ Equivalent to Python
140
+ [`self | other`](https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types).
141
+ """
142
+ return self | other
143
+
144
+
145
+ @bitwise_or.to_sql
146
+ def _(self: sql.ColumnElement, other: sql.ColumnElement) -> sql.ColumnElement:
147
+ return self.bitwise_or(other)
148
+
149
+
150
+ @pxt.udf(is_method=True)
151
+ def bitwise_xor(self: int, other: int) -> int:
152
+ """
153
+ Bitwise XOR of two integers.
154
+
155
+ Equivalent to Python
156
+ [`self ^ other`](https://docs.python.org/3/library/stdtypes.html#bitwise-operations-on-integer-types).
157
+ """
158
+ return self ^ other
159
+
160
+
161
+ @bitwise_xor.to_sql
162
+ def _(self: sql.ColumnElement, other: sql.ColumnElement) -> sql.ColumnElement:
163
+ return self.bitwise_xor(other)
164
+
165
+
103
166
  __all__ = local_public_names(__name__)
104
167
 
105
168
 
@@ -5,7 +5,7 @@ first `pip install mistralai` and configure your Mistral AI credentials, as desc
5
5
  the [Working with Mistral AI](https://pixeltable.readme.io/docs/working-with-mistralai) tutorial.
6
6
  """
7
7
 
8
- from typing import TYPE_CHECKING, Optional, TypeVar, Union
8
+ from typing import TYPE_CHECKING, Any, Optional
9
9
 
10
10
  import numpy as np
11
11
 
@@ -16,7 +16,7 @@ from pixeltable.func.signature import Batch
16
16
  from pixeltable.utils.code import local_public_names
17
17
 
18
18
  if TYPE_CHECKING:
19
- import mistralai.types.basemodel
19
+ import mistralai
20
20
 
21
21
 
22
22
  @register_client('mistral')
@@ -32,16 +32,7 @@ def _mistralai_client() -> 'mistralai.Mistral':
32
32
 
33
33
  @pxt.udf(resource_pool='request-rate:mistral')
34
34
  async def chat_completions(
35
- messages: list[dict[str, str]],
36
- *,
37
- model: str,
38
- temperature: Optional[float] = 0.7,
39
- top_p: Optional[float] = 1.0,
40
- max_tokens: Optional[int] = None,
41
- stop: Optional[list[str]] = None,
42
- random_seed: Optional[int] = None,
43
- response_format: Optional[dict] = None,
44
- safe_prompt: Optional[bool] = False,
35
+ messages: list[dict[str, str]], *, model: str, model_kwargs: Optional[dict[str, Any]] = None
45
36
  ) -> dict:
46
37
  """
47
38
  Chat Completion API.
@@ -60,8 +51,8 @@ async def chat_completions(
60
51
  Args:
61
52
  messages: The prompt(s) to generate completions for.
62
53
  model: ID of the model to use. (See overview here: <https://docs.mistral.ai/getting-started/models/>)
63
-
64
- For details on the other parameters, see: <https://docs.mistral.ai/api/#tag/chat>
54
+ model_kwargs: Additional keyword args for the Mistral `chat/completions` API.
55
+ For details on the available parameters, see: <https://docs.mistral.ai/api/#tag/chat>
65
56
 
66
57
  Returns:
67
58
  A dictionary containing the response and other metadata.
@@ -73,34 +64,20 @@ async def chat_completions(
73
64
  >>> messages = [{'role': 'user', 'content': tbl.prompt}]
74
65
  ... tbl.add_computed_column(response=completions(messages, model='mistral-latest-small'))
75
66
  """
67
+ if model_kwargs is None:
68
+ model_kwargs = {}
69
+
76
70
  Env.get().require_package('mistralai')
77
71
  result = await _mistralai_client().chat.complete_async(
78
72
  messages=messages, # type: ignore[arg-type]
79
73
  model=model,
80
- temperature=temperature,
81
- top_p=top_p,
82
- max_tokens=_opt(max_tokens),
83
- stop=stop,
84
- random_seed=_opt(random_seed),
85
- response_format=response_format, # type: ignore[arg-type]
86
- safe_prompt=safe_prompt,
74
+ **model_kwargs,
87
75
  )
88
76
  return result.dict()
89
77
 
90
78
 
91
79
  @pxt.udf(resource_pool='request-rate:mistral')
92
- async def fim_completions(
93
- prompt: str,
94
- *,
95
- model: str,
96
- temperature: Optional[float] = 0.7,
97
- top_p: Optional[float] = 1.0,
98
- max_tokens: Optional[int] = None,
99
- min_tokens: Optional[int] = None,
100
- stop: Optional[list[str]] = None,
101
- random_seed: Optional[int] = None,
102
- suffix: Optional[str] = None,
103
- ) -> dict:
80
+ async def fim_completions(prompt: str, *, model: str, model_kwargs: Optional[dict[str, Any]] = None) -> dict:
104
81
  """
105
82
  Fill-in-the-middle Completion API.
106
83
 
@@ -118,6 +95,8 @@ async def fim_completions(
118
95
  Args:
119
96
  prompt: The text/code to complete.
120
97
  model: ID of the model to use. (See overview here: <https://docs.mistral.ai/getting-started/models/>)
98
+ model_kwargs: Additional keyword args for the Mistral `fim/completions` API.
99
+ For details on the available parameters, see: <https://docs.mistral.ai/api/#tag/fim>
121
100
 
122
101
  For details on the other parameters, see: <https://docs.mistral.ai/api/#tag/fim>
123
102
 
@@ -130,18 +109,11 @@ async def fim_completions(
130
109
 
131
110
  >>> tbl.add_computed_column(response=completions(tbl.prompt, model='codestral-latest'))
132
111
  """
112
+ if model_kwargs is None:
113
+ model_kwargs = {}
114
+
133
115
  Env.get().require_package('mistralai')
134
- result = await _mistralai_client().fim.complete_async(
135
- prompt=prompt,
136
- model=model,
137
- temperature=temperature,
138
- top_p=top_p,
139
- max_tokens=_opt(max_tokens),
140
- min_tokens=_opt(min_tokens),
141
- stop=stop,
142
- random_seed=_opt(random_seed),
143
- suffix=_opt(suffix),
144
- )
116
+ result = await _mistralai_client().fim.complete_async(prompt=prompt, model=model, **model_kwargs)
145
117
  return result.dict()
146
118
 
147
119
 
@@ -182,15 +154,6 @@ def _(model: str) -> ts.ArrayType:
182
154
  return ts.ArrayType((dimensions,), dtype=ts.FloatType())
183
155
 
184
156
 
185
- _T = TypeVar('_T')
186
-
187
-
188
- def _opt(arg: Optional[_T]) -> Union[_T, 'mistralai.types.basemodel.Unset']:
189
- from mistralai.types import UNSET
190
-
191
- return arg if arg is not None else UNSET
192
-
193
-
194
157
  __all__ = local_public_names(__name__)
195
158
 
196
159
 
@@ -50,7 +50,7 @@ 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
53
+ options: Additional options for the Ollama `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
54
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.