pixeltable 0.3.14__py3-none-any.whl → 0.5.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.
- pixeltable/__init__.py +42 -8
- pixeltable/{dataframe.py → _query.py} +470 -206
- pixeltable/_version.py +1 -0
- pixeltable/catalog/__init__.py +5 -4
- pixeltable/catalog/catalog.py +1785 -432
- pixeltable/catalog/column.py +190 -113
- pixeltable/catalog/dir.py +2 -4
- pixeltable/catalog/globals.py +19 -46
- pixeltable/catalog/insertable_table.py +191 -98
- pixeltable/catalog/path.py +63 -23
- pixeltable/catalog/schema_object.py +11 -15
- pixeltable/catalog/table.py +843 -436
- pixeltable/catalog/table_metadata.py +103 -0
- pixeltable/catalog/table_version.py +978 -657
- pixeltable/catalog/table_version_handle.py +72 -16
- pixeltable/catalog/table_version_path.py +112 -43
- pixeltable/catalog/tbl_ops.py +53 -0
- pixeltable/catalog/update_status.py +191 -0
- pixeltable/catalog/view.py +134 -90
- pixeltable/config.py +134 -22
- pixeltable/env.py +471 -157
- pixeltable/exceptions.py +6 -0
- pixeltable/exec/__init__.py +4 -1
- pixeltable/exec/aggregation_node.py +7 -8
- pixeltable/exec/cache_prefetch_node.py +83 -110
- pixeltable/exec/cell_materialization_node.py +268 -0
- pixeltable/exec/cell_reconstruction_node.py +168 -0
- pixeltable/exec/component_iteration_node.py +4 -3
- pixeltable/exec/data_row_batch.py +8 -65
- pixeltable/exec/exec_context.py +16 -4
- pixeltable/exec/exec_node.py +13 -36
- pixeltable/exec/expr_eval/evaluators.py +11 -7
- pixeltable/exec/expr_eval/expr_eval_node.py +27 -12
- pixeltable/exec/expr_eval/globals.py +8 -5
- pixeltable/exec/expr_eval/row_buffer.py +1 -2
- pixeltable/exec/expr_eval/schedulers.py +106 -56
- pixeltable/exec/globals.py +35 -0
- pixeltable/exec/in_memory_data_node.py +19 -19
- pixeltable/exec/object_store_save_node.py +293 -0
- pixeltable/exec/row_update_node.py +16 -9
- pixeltable/exec/sql_node.py +351 -84
- pixeltable/exprs/__init__.py +1 -1
- pixeltable/exprs/arithmetic_expr.py +27 -22
- pixeltable/exprs/array_slice.py +3 -3
- pixeltable/exprs/column_property_ref.py +36 -23
- pixeltable/exprs/column_ref.py +213 -89
- pixeltable/exprs/comparison.py +5 -5
- pixeltable/exprs/compound_predicate.py +5 -4
- pixeltable/exprs/data_row.py +164 -54
- pixeltable/exprs/expr.py +70 -44
- pixeltable/exprs/expr_dict.py +3 -3
- pixeltable/exprs/expr_set.py +17 -10
- pixeltable/exprs/function_call.py +100 -40
- pixeltable/exprs/globals.py +2 -2
- pixeltable/exprs/in_predicate.py +4 -4
- pixeltable/exprs/inline_expr.py +18 -32
- pixeltable/exprs/is_null.py +7 -3
- pixeltable/exprs/json_mapper.py +8 -8
- pixeltable/exprs/json_path.py +56 -22
- pixeltable/exprs/literal.py +27 -5
- pixeltable/exprs/method_ref.py +2 -2
- pixeltable/exprs/object_ref.py +2 -2
- pixeltable/exprs/row_builder.py +167 -67
- pixeltable/exprs/rowid_ref.py +25 -10
- pixeltable/exprs/similarity_expr.py +58 -40
- pixeltable/exprs/sql_element_cache.py +4 -4
- pixeltable/exprs/string_op.py +5 -5
- pixeltable/exprs/type_cast.py +3 -5
- pixeltable/func/__init__.py +1 -0
- pixeltable/func/aggregate_function.py +8 -8
- pixeltable/func/callable_function.py +9 -9
- pixeltable/func/expr_template_function.py +17 -11
- pixeltable/func/function.py +18 -20
- pixeltable/func/function_registry.py +6 -7
- pixeltable/func/globals.py +2 -3
- pixeltable/func/mcp.py +74 -0
- pixeltable/func/query_template_function.py +29 -27
- pixeltable/func/signature.py +46 -19
- pixeltable/func/tools.py +31 -13
- pixeltable/func/udf.py +18 -20
- pixeltable/functions/__init__.py +16 -0
- pixeltable/functions/anthropic.py +123 -77
- pixeltable/functions/audio.py +147 -10
- pixeltable/functions/bedrock.py +13 -6
- pixeltable/functions/date.py +7 -4
- pixeltable/functions/deepseek.py +35 -43
- pixeltable/functions/document.py +81 -0
- pixeltable/functions/fal.py +76 -0
- pixeltable/functions/fireworks.py +11 -20
- pixeltable/functions/gemini.py +195 -39
- pixeltable/functions/globals.py +142 -14
- pixeltable/functions/groq.py +108 -0
- pixeltable/functions/huggingface.py +1056 -24
- pixeltable/functions/image.py +115 -57
- pixeltable/functions/json.py +1 -1
- pixeltable/functions/llama_cpp.py +28 -13
- pixeltable/functions/math.py +67 -5
- pixeltable/functions/mistralai.py +18 -55
- pixeltable/functions/net.py +70 -0
- pixeltable/functions/ollama.py +20 -13
- pixeltable/functions/openai.py +240 -226
- pixeltable/functions/openrouter.py +143 -0
- pixeltable/functions/replicate.py +4 -4
- pixeltable/functions/reve.py +250 -0
- pixeltable/functions/string.py +239 -69
- pixeltable/functions/timestamp.py +16 -16
- pixeltable/functions/together.py +24 -84
- pixeltable/functions/twelvelabs.py +188 -0
- pixeltable/functions/util.py +6 -1
- pixeltable/functions/uuid.py +30 -0
- pixeltable/functions/video.py +1515 -107
- pixeltable/functions/vision.py +8 -8
- pixeltable/functions/voyageai.py +289 -0
- pixeltable/functions/whisper.py +16 -8
- pixeltable/functions/whisperx.py +179 -0
- pixeltable/{ext/functions → functions}/yolox.py +2 -4
- pixeltable/globals.py +362 -115
- pixeltable/index/base.py +17 -21
- pixeltable/index/btree.py +28 -22
- pixeltable/index/embedding_index.py +100 -118
- pixeltable/io/__init__.py +4 -2
- pixeltable/io/datarows.py +8 -7
- pixeltable/io/external_store.py +56 -105
- pixeltable/io/fiftyone.py +13 -13
- pixeltable/io/globals.py +31 -30
- pixeltable/io/hf_datasets.py +61 -16
- pixeltable/io/label_studio.py +74 -70
- pixeltable/io/lancedb.py +3 -0
- pixeltable/io/pandas.py +21 -12
- pixeltable/io/parquet.py +25 -105
- pixeltable/io/table_data_conduit.py +250 -123
- pixeltable/io/utils.py +4 -4
- pixeltable/iterators/__init__.py +2 -1
- pixeltable/iterators/audio.py +26 -25
- pixeltable/iterators/base.py +9 -3
- pixeltable/iterators/document.py +112 -78
- pixeltable/iterators/image.py +12 -15
- pixeltable/iterators/string.py +11 -4
- pixeltable/iterators/video.py +523 -120
- pixeltable/metadata/__init__.py +14 -3
- pixeltable/metadata/converters/convert_13.py +2 -2
- pixeltable/metadata/converters/convert_18.py +2 -2
- pixeltable/metadata/converters/convert_19.py +2 -2
- pixeltable/metadata/converters/convert_20.py +2 -2
- pixeltable/metadata/converters/convert_21.py +2 -2
- pixeltable/metadata/converters/convert_22.py +2 -2
- pixeltable/metadata/converters/convert_24.py +2 -2
- pixeltable/metadata/converters/convert_25.py +2 -2
- pixeltable/metadata/converters/convert_26.py +2 -2
- pixeltable/metadata/converters/convert_29.py +4 -4
- pixeltable/metadata/converters/convert_30.py +34 -21
- pixeltable/metadata/converters/convert_34.py +2 -2
- pixeltable/metadata/converters/convert_35.py +9 -0
- pixeltable/metadata/converters/convert_36.py +38 -0
- pixeltable/metadata/converters/convert_37.py +15 -0
- pixeltable/metadata/converters/convert_38.py +39 -0
- pixeltable/metadata/converters/convert_39.py +124 -0
- pixeltable/metadata/converters/convert_40.py +73 -0
- pixeltable/metadata/converters/convert_41.py +12 -0
- pixeltable/metadata/converters/convert_42.py +9 -0
- pixeltable/metadata/converters/convert_43.py +44 -0
- pixeltable/metadata/converters/util.py +20 -31
- pixeltable/metadata/notes.py +9 -0
- pixeltable/metadata/schema.py +140 -53
- pixeltable/metadata/utils.py +74 -0
- pixeltable/mypy/__init__.py +3 -0
- pixeltable/mypy/mypy_plugin.py +123 -0
- pixeltable/plan.py +382 -115
- pixeltable/share/__init__.py +1 -1
- pixeltable/share/packager.py +547 -83
- pixeltable/share/protocol/__init__.py +33 -0
- pixeltable/share/protocol/common.py +165 -0
- pixeltable/share/protocol/operation_types.py +33 -0
- pixeltable/share/protocol/replica.py +119 -0
- pixeltable/share/publish.py +257 -59
- pixeltable/store.py +311 -194
- pixeltable/type_system.py +373 -211
- pixeltable/utils/__init__.py +2 -3
- pixeltable/utils/arrow.py +131 -17
- pixeltable/utils/av.py +298 -0
- pixeltable/utils/azure_store.py +346 -0
- pixeltable/utils/coco.py +6 -6
- pixeltable/utils/code.py +3 -3
- pixeltable/utils/console_output.py +4 -1
- pixeltable/utils/coroutine.py +6 -23
- pixeltable/utils/dbms.py +32 -6
- pixeltable/utils/description_helper.py +4 -5
- pixeltable/utils/documents.py +7 -18
- pixeltable/utils/exception_handler.py +7 -30
- pixeltable/utils/filecache.py +6 -6
- pixeltable/utils/formatter.py +86 -48
- pixeltable/utils/gcs_store.py +295 -0
- pixeltable/utils/http.py +133 -0
- pixeltable/utils/http_server.py +2 -3
- pixeltable/utils/iceberg.py +1 -2
- pixeltable/utils/image.py +17 -0
- pixeltable/utils/lancedb.py +90 -0
- pixeltable/utils/local_store.py +322 -0
- pixeltable/utils/misc.py +5 -0
- pixeltable/utils/object_stores.py +573 -0
- pixeltable/utils/pydantic.py +60 -0
- pixeltable/utils/pytorch.py +5 -6
- pixeltable/utils/s3_store.py +527 -0
- pixeltable/utils/sql.py +26 -0
- pixeltable/utils/system.py +30 -0
- pixeltable-0.5.7.dist-info/METADATA +579 -0
- pixeltable-0.5.7.dist-info/RECORD +227 -0
- {pixeltable-0.3.14.dist-info → pixeltable-0.5.7.dist-info}/WHEEL +1 -1
- pixeltable-0.5.7.dist-info/entry_points.txt +2 -0
- pixeltable/__version__.py +0 -3
- pixeltable/catalog/named_function.py +0 -40
- pixeltable/ext/__init__.py +0 -17
- pixeltable/ext/functions/__init__.py +0 -11
- pixeltable/ext/functions/whisperx.py +0 -77
- pixeltable/utils/media_store.py +0 -77
- pixeltable/utils/s3.py +0 -17
- pixeltable-0.3.14.dist-info/METADATA +0 -434
- pixeltable-0.3.14.dist-info/RECORD +0 -186
- pixeltable-0.3.14.dist-info/entry_points.txt +0 -3
- {pixeltable-0.3.14.dist-info → pixeltable-0.5.7.dist-info/licenses}/LICENSE +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"""
|
|
2
|
-
Pixeltable
|
|
2
|
+
Pixeltable UDFs
|
|
3
3
|
that wrap various endpoints from the Mistral AI API. In order to use them, you must
|
|
4
4
|
first `pip install mistralai` and configure your Mistral AI credentials, as described in
|
|
5
|
-
the [Working with Mistral AI](https://pixeltable.
|
|
5
|
+
the [Working with Mistral AI](https://docs.pixeltable.com/notebooks/integrations/working-with-mistralai) tutorial.
|
|
6
6
|
"""
|
|
7
7
|
|
|
8
|
-
from typing import TYPE_CHECKING,
|
|
8
|
+
from typing import TYPE_CHECKING, Any
|
|
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
|
|
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: dict[str, Any] | None = 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
|
-
|
|
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
|
-
|
|
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: dict[str, Any] | None = 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
|
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Pixeltable UDF for converting media file URIs to presigned HTTP URLs.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from pixeltable import exceptions as excs
|
|
6
|
+
from pixeltable.func.udf import udf
|
|
7
|
+
from pixeltable.utils.code import local_public_names
|
|
8
|
+
from pixeltable.utils.object_stores import ObjectOps, ObjectPath, StorageTarget
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@udf
|
|
12
|
+
def presigned_url(uri: str, expiration_seconds: int) -> str:
|
|
13
|
+
"""
|
|
14
|
+
Convert a blob storage URI to a presigned HTTP URL for direct access.
|
|
15
|
+
|
|
16
|
+
Generates a time-limited, publicly accessible URL from cloud storage URIs
|
|
17
|
+
(S3, GCS, Azure, etc.) that can be used to serve media files over HTTP.
|
|
18
|
+
|
|
19
|
+
Note:
|
|
20
|
+
This function uses presigned URLs from storage providers. Provider-specific
|
|
21
|
+
limitations apply:
|
|
22
|
+
|
|
23
|
+
- Google Cloud Storage: maximum 7-day expiration
|
|
24
|
+
- AWS S3: requires proper region configuration
|
|
25
|
+
- Azure: subject to storage account access policies
|
|
26
|
+
|
|
27
|
+
Args:
|
|
28
|
+
uri: The media file URI (e.g., `s3://bucket/path`, `gs://bucket/path`, `azure://container/path`)
|
|
29
|
+
expiration_seconds: How long the URL remains valid
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
A presigned HTTP URL for accessing the file
|
|
33
|
+
|
|
34
|
+
Raises:
|
|
35
|
+
Error: If the URI is a local file:// path
|
|
36
|
+
|
|
37
|
+
Examples:
|
|
38
|
+
Generate a presigned URL for a video column with 1-hour expiration:
|
|
39
|
+
|
|
40
|
+
>>> tbl.select(
|
|
41
|
+
... original_url=tbl.video.fileurl,
|
|
42
|
+
... presigned_url=pxtf.net.presigned_url(tbl.video.fileurl, 3600)
|
|
43
|
+
... ).collect()
|
|
44
|
+
"""
|
|
45
|
+
if not uri:
|
|
46
|
+
return uri
|
|
47
|
+
|
|
48
|
+
# Parse the object storage address from the URI
|
|
49
|
+
soa = ObjectPath.parse_object_storage_addr(uri, allow_obj_name=True)
|
|
50
|
+
|
|
51
|
+
# HTTP/HTTPS URLs are already publicly accessible
|
|
52
|
+
if soa.storage_target == StorageTarget.HTTP_STORE:
|
|
53
|
+
return uri
|
|
54
|
+
|
|
55
|
+
# For file:// URLs, we can't generate presigned URLs
|
|
56
|
+
if soa.storage_target == StorageTarget.LOCAL_STORE:
|
|
57
|
+
raise excs.Error(
|
|
58
|
+
'Cannot generate presigned URL for local file:// URLs. '
|
|
59
|
+
'Please use cloud storage (S3, GCS, Azure) for presigned URLs.'
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
store = ObjectOps.get_store(soa, allow_obj_name=True)
|
|
63
|
+
return store.create_presigned_url(soa, expiration_seconds)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
__all__ = local_public_names(__name__)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def __dir__() -> list[str]:
|
|
70
|
+
return __all__
|
pixeltable/functions/ollama.py
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
"""
|
|
2
|
+
Pixeltable UDFs for Ollama local models.
|
|
3
|
+
|
|
4
|
+
Provides integration with Ollama for running large language models locally,
|
|
5
|
+
including chat completions and embeddings.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
2
9
|
|
|
3
10
|
import numpy as np
|
|
4
11
|
|
|
@@ -18,7 +25,7 @@ def _(host: str) -> 'ollama.Client':
|
|
|
18
25
|
return ollama.Client(host=host)
|
|
19
26
|
|
|
20
27
|
|
|
21
|
-
def _ollama_client() ->
|
|
28
|
+
def _ollama_client() -> 'ollama.Client | None':
|
|
22
29
|
try:
|
|
23
30
|
return env.Env.get().get_client('ollama')
|
|
24
31
|
except Exception:
|
|
@@ -33,10 +40,10 @@ def generate(
|
|
|
33
40
|
suffix: str = '',
|
|
34
41
|
system: str = '',
|
|
35
42
|
template: str = '',
|
|
36
|
-
context:
|
|
43
|
+
context: list[int] | None = None,
|
|
37
44
|
raw: bool = False,
|
|
38
|
-
format:
|
|
39
|
-
options:
|
|
45
|
+
format: str | None = None,
|
|
46
|
+
options: dict | None = None,
|
|
40
47
|
) -> dict:
|
|
41
48
|
"""
|
|
42
49
|
Generate a response for a given prompt with a provided model.
|
|
@@ -50,9 +57,9 @@ def generate(
|
|
|
50
57
|
template: Prompt template to use.
|
|
51
58
|
context: The context parameter returned from a previous call to `generate()`.
|
|
52
59
|
raw: If `True`, no formatting will be applied to the prompt.
|
|
53
|
-
options: Additional options
|
|
60
|
+
options: Additional options for the Ollama `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
54
61
|
`top_k`. For details, see the
|
|
55
|
-
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.
|
|
62
|
+
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.mdx#valid-parameters-and-values)
|
|
56
63
|
section of the Ollama documentation.
|
|
57
64
|
"""
|
|
58
65
|
env.Env.get().require_package('ollama')
|
|
@@ -77,9 +84,9 @@ def chat(
|
|
|
77
84
|
messages: list[dict],
|
|
78
85
|
*,
|
|
79
86
|
model: str,
|
|
80
|
-
tools:
|
|
81
|
-
format:
|
|
82
|
-
options:
|
|
87
|
+
tools: list[dict] | None = None,
|
|
88
|
+
format: str | None = None,
|
|
89
|
+
options: dict | None = None,
|
|
83
90
|
) -> dict:
|
|
84
91
|
"""
|
|
85
92
|
Generate the next message in a chat with a provided model.
|
|
@@ -91,7 +98,7 @@ def chat(
|
|
|
91
98
|
format: The format of the response; must be one of `'json'` or `None`.
|
|
92
99
|
options: Additional options to pass to the `chat` call, such as `max_tokens`, `temperature`, `top_p`, and
|
|
93
100
|
`top_k`. For details, see the
|
|
94
|
-
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.
|
|
101
|
+
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.mdx#valid-parameters-and-values)
|
|
95
102
|
section of the Ollama documentation.
|
|
96
103
|
"""
|
|
97
104
|
env.Env.get().require_package('ollama')
|
|
@@ -103,7 +110,7 @@ def chat(
|
|
|
103
110
|
|
|
104
111
|
@pxt.udf(batch_size=16)
|
|
105
112
|
def embed(
|
|
106
|
-
input: Batch[str], *, model: str, truncate: bool = True, options:
|
|
113
|
+
input: Batch[str], *, model: str, truncate: bool = True, options: dict | None = None
|
|
107
114
|
) -> Batch[pxt.Array[(None,), pxt.Float]]:
|
|
108
115
|
"""
|
|
109
116
|
Generate embeddings from a model.
|
|
@@ -115,7 +122,7 @@ def embed(
|
|
|
115
122
|
Returns error if false and context length is exceeded.
|
|
116
123
|
options: Additional options to pass to the `embed` call.
|
|
117
124
|
For details, see the
|
|
118
|
-
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.
|
|
125
|
+
[Valid Parameters and Values](https://github.com/ollama/ollama/blob/main/docs/modelfile.mdx#valid-parameters-and-values)
|
|
119
126
|
section of the Ollama documentation.
|
|
120
127
|
"""
|
|
121
128
|
env.Env.get().require_package('ollama')
|