datachain 0.8.1__py3-none-any.whl → 0.8.2__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 datachain might be problematic. Click here for more details.

datachain/client/gcs.py CHANGED
@@ -33,13 +33,14 @@ class GCSClient(Client):
33
33
  return cast(GCSFileSystem, super().create_fs(**kwargs))
34
34
 
35
35
  def url(self, path: str, expires: int = 3600, **kwargs) -> str:
36
- try:
37
- return self.fs.sign(self.get_full_path(path), expiration=expires, **kwargs)
38
- except AttributeError as exc:
39
- is_anon = self.fs.storage_options.get("token") == "anon"
40
- if is_anon and "you need a private key to sign credentials" in str(exc):
41
- return f"https://storage.googleapis.com/{self.name}/{path}"
42
- raise
36
+ """
37
+ Generate a signed URL for the given path.
38
+ If the client is anonymous, a public URL is returned instead
39
+ (see https://cloud.google.com/storage/docs/access-public-data#api-link).
40
+ """
41
+ if self.fs.storage_options.get("token") == "anon":
42
+ return f"https://storage.googleapis.com/{self.name}/{path}"
43
+ return self.fs.sign(self.get_full_path(path), expiration=expires, **kwargs)
43
44
 
44
45
  @staticmethod
45
46
  def parse_timestamp(timestamp: str) -> datetime:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datachain
3
- Version: 0.8.1
3
+ Version: 0.8.2
4
4
  Summary: Wrangle unstructured AI data at scale
5
5
  Author-email: Dmitry Petrov <support@dvc.org>
6
6
  License: Apache-2.0
@@ -145,6 +145,88 @@ Getting Started
145
145
  Visit `Quick Start <https://docs.datachain.ai/quick-start>`_ and `Docs <https://docs.datachain.ai/>`_
146
146
  to get started with `DataChain` and learn more.
147
147
 
148
+ .. code:: bash
149
+
150
+ pip install datachain
151
+
152
+
153
+ Example: download subset of files based on metadata
154
+ ---------------------------------------------------
155
+
156
+ Sometimes users only need to download a specific subset of files from cloud storage,
157
+ rather than the entire dataset.
158
+ For example, you could use a JSON file's metadata to download just cat images with
159
+ high confidence scores.
160
+
161
+
162
+ .. code:: py
163
+
164
+ from datachain import Column, DataChain
165
+
166
+ meta = DataChain.from_json("gs://datachain-demo/dogs-and-cats/*json", object_name="meta", anon=True)
167
+ images = DataChain.from_storage("gs://datachain-demo/dogs-and-cats/*jpg", anon=True)
168
+
169
+ images_id = images.map(id=lambda file: file.path.split('.')[-2])
170
+ annotated = images_id.merge(meta, on="id", right_on="meta.id")
171
+
172
+ likely_cats = annotated.filter((Column("meta.inference.confidence") > 0.93) \
173
+ & (Column("meta.inference.class_") == "cat"))
174
+ likely_cats.export_files("high-confidence-cats/", signal="file")
175
+
176
+
177
+ Example: LLM based text-file evaluation
178
+ ---------------------------------------
179
+
180
+ In this example, we evaluate chatbot conversations stored in text files
181
+ using LLM based evaluation.
182
+
183
+ .. code:: shell
184
+
185
+ $ pip install mistralai # Requires version >=1.0.0
186
+ $ export MISTRAL_API_KEY=_your_key_
187
+
188
+ Python code:
189
+
190
+ .. code:: py
191
+
192
+ from mistralai import Mistral
193
+ from datachain import File, DataChain, Column
194
+
195
+ PROMPT = "Was this dialog successful? Answer in a single word: Success or Failure."
196
+
197
+ def eval_dialogue(file: File) -> bool:
198
+ client = Mistral()
199
+ response = client.chat.complete(
200
+ model="open-mixtral-8x22b",
201
+ messages=[{"role": "system", "content": PROMPT},
202
+ {"role": "user", "content": file.read()}])
203
+ result = response.choices[0].message.content
204
+ return result.lower().startswith("success")
205
+
206
+ chain = (
207
+ DataChain.from_storage("gs://datachain-demo/chatbot-KiT/", object_name="file", anon=True)
208
+ .settings(parallel=4, cache=True)
209
+ .map(is_success=eval_dialogue)
210
+ .save("mistral_files")
211
+ )
212
+
213
+ successful_chain = chain.filter(Column("is_success") == True)
214
+ successful_chain.export_files("./output_mistral")
215
+
216
+ print(f"{successful_chain.count()} files were exported")
217
+
218
+
219
+
220
+ With the instruction above, the Mistral model considers 31/50 files to hold the successful dialogues:
221
+
222
+ .. code:: shell
223
+
224
+ $ ls output_mistral/datachain-demo/chatbot-KiT/
225
+ 1.txt 15.txt 18.txt 2.txt 22.txt 25.txt 28.txt 33.txt 37.txt 4.txt 41.txt ...
226
+ $ ls output_mistral/datachain-demo/chatbot-KiT/ | wc -l
227
+ 31
228
+
229
+
148
230
  Key Features
149
231
  ============
150
232
 
@@ -25,7 +25,7 @@ datachain/client/__init__.py,sha256=1kDpCPoibMXi1gExR4lTLc5pi-k6M5TANiwtXkPoLhU,
25
25
  datachain/client/azure.py,sha256=ffxs26zm6KLAL1aUWJm-vtzuZP3LSNha7UDGXynMBKo,2234
26
26
  datachain/client/fileslice.py,sha256=bT7TYco1Qe3bqoc8aUkUZcPdPofJDHlryL5BsTn9xsY,3021
27
27
  datachain/client/fsspec.py,sha256=kf1blSGNcEXJ0tra3y5i35jc1aAy-67wMHXkqjlRMXg,12736
28
- datachain/client/gcs.py,sha256=41Q9hxE9CYt-31B9m-ogqrEv4NbF2SWF-j8N_AC3VQ0,4580
28
+ datachain/client/gcs.py,sha256=tAm5CCO86UNuSwTCHVPOiPbj1fBhnEYDoEVLKvv9H5I,4632
29
29
  datachain/client/hf.py,sha256=XeVJVbiNViZCpn3sfb90Fr8SYO3BdLmfE3hOWMoqInE,951
30
30
  datachain/client/local.py,sha256=f2HBqWH8SQM5CyiJ0ljfePVROg2FszWaAn6E2c8RiLE,4596
31
31
  datachain/client/s3.py,sha256=CVHBUZ1Ic2Q3370nl-Bbe69phuWjFlrVv9dTJKBpRT0,6019
@@ -121,9 +121,9 @@ datachain/sql/sqlite/vector.py,sha256=ncW4eu2FlJhrP_CIpsvtkUabZlQdl2D5Lgwy_cbfqR
121
121
  datachain/toolkit/__init__.py,sha256=eQ58Q5Yf_Fgv1ZG0IO5dpB4jmP90rk8YxUWmPc1M2Bo,68
122
122
  datachain/toolkit/split.py,sha256=z3zRJNzjWrpPuRw-zgFbCOBKInyYxJew8ygrYQRQLNc,2930
123
123
  datachain/torch/__init__.py,sha256=gIS74PoEPy4TB3X6vx9nLO0Y3sLJzsA8ckn8pRWihJM,579
124
- datachain-0.8.1.dist-info/LICENSE,sha256=8DnqK5yoPI_E50bEg_zsHKZHY2HqPy4rYN338BHQaRA,11344
125
- datachain-0.8.1.dist-info/METADATA,sha256=iZV5_BcFNOY82HkPBDJ6h2Y895wYy5UQfo_VJaDZN6Q,8437
126
- datachain-0.8.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
127
- datachain-0.8.1.dist-info/entry_points.txt,sha256=0GMJS6B_KWq0m3VT98vQI2YZodAMkn4uReZ_okga9R4,49
128
- datachain-0.8.1.dist-info/top_level.txt,sha256=lZPpdU_2jJABLNIg2kvEOBi8PtsYikbN1OdMLHk8bTg,10
129
- datachain-0.8.1.dist-info/RECORD,,
124
+ datachain-0.8.2.dist-info/LICENSE,sha256=8DnqK5yoPI_E50bEg_zsHKZHY2HqPy4rYN338BHQaRA,11344
125
+ datachain-0.8.2.dist-info/METADATA,sha256=MFVRJVJBLh_Cq3aV_1V4dHKkf15HTZHLUWWQNbRId3I,11066
126
+ datachain-0.8.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
127
+ datachain-0.8.2.dist-info/entry_points.txt,sha256=0GMJS6B_KWq0m3VT98vQI2YZodAMkn4uReZ_okga9R4,49
128
+ datachain-0.8.2.dist-info/top_level.txt,sha256=lZPpdU_2jJABLNIg2kvEOBi8PtsYikbN1OdMLHk8bTg,10
129
+ datachain-0.8.2.dist-info/RECORD,,