fabricatio 0.2.4.dev2__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.4.dev3__cp312-cp312-manylinux_2_34_x86_64.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.
@@ -13,10 +13,16 @@ from typing import Any, Callable, Dict, List, Optional, Self, Union, Unpack, ove
13
13
  from fabricatio._rust_instances import template_manager
14
14
  from fabricatio.config import configs
15
15
  from fabricatio.journal import logger
16
- from fabricatio.models.kwargs_types import CollectionSimpleConfigKwargs, EmbeddingKwargs, FetchKwargs, LLMKwargs
16
+ from fabricatio.models.kwargs_types import (
17
+ ChooseKwargs,
18
+ CollectionSimpleConfigKwargs,
19
+ EmbeddingKwargs,
20
+ FetchKwargs,
21
+ LLMKwargs,
22
+ )
17
23
  from fabricatio.models.usages import EmbeddingUsage
18
24
  from fabricatio.models.utils import MilvusData
19
- from more_itertools.recipes import flatten
25
+ from more_itertools.recipes import flatten, unique
20
26
  from pydantic import Field, PrivateAttr
21
27
 
22
28
 
@@ -221,9 +227,9 @@ class RAG(EmbeddingUsage):
221
227
 
222
228
  # Step 2: Flatten the search results
223
229
  flattened_results = flatten(search_results)
224
-
230
+ unique_results = unique(flattened_results, key=itemgetter("id"))
225
231
  # Step 3: Sort by distance (descending)
226
- sorted_results = sorted(flattened_results, key=itemgetter("distance"), reverse=True)
232
+ sorted_results = sorted(unique_results, key=itemgetter("distance"), reverse=True)
227
233
 
228
234
  logger.debug(f"Searched similarities: {[t['distance'] for t in sorted_results]}")
229
235
  # Step 4: Extract the entities
@@ -308,3 +314,21 @@ class RAG(EmbeddingUsage):
308
314
  f"{rendered}\n\n{extra_system_message}",
309
315
  **kwargs,
310
316
  )
317
+
318
+ async def arefined_query(self, question: List[str] | str, **kwargs: Unpack[ChooseKwargs]) -> List[str]:
319
+ """Refines the given question using a template.
320
+
321
+ Args:
322
+ question (List[str] | str): The question to be refined.
323
+ **kwargs (Unpack[ChooseKwargs]): Additional keyword arguments for the refinement process.
324
+
325
+ Returns:
326
+ List[str]: A list of refined questions.
327
+ """
328
+ return await self.aliststr(
329
+ template_manager.render_template(
330
+ configs.templates.refined_query_template,
331
+ {"question": [question] if isinstance(question, str) else question},
332
+ ),
333
+ **kwargs,
334
+ )
fabricatio/config.py CHANGED
@@ -209,6 +209,9 @@ class TemplateConfig(BaseModel):
209
209
  liststr_template: str = Field(default="liststr")
210
210
  """The name of the liststr template which will be used to display a list of strings."""
211
211
 
212
+ refined_query_template: str = Field(default="refined_query")
213
+ """The name of the refined query template which will be used to refine a query."""
214
+
212
215
 
213
216
  class MagikaConfig(BaseModel):
214
217
  """Magika configuration class."""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.4.dev2
3
+ Version: 0.2.4.dev3
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,6 +1,6 @@
1
- fabricatio-0.2.4.dev2.dist-info/METADATA,sha256=vhANe4uPf0Sg_UmcfdmjBD9GI44lY6XrlLz0OFf4bQk,8589
2
- fabricatio-0.2.4.dev2.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
- fabricatio-0.2.4.dev2.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
1
+ fabricatio-0.2.4.dev3.dist-info/METADATA,sha256=aL1eAIQviM4LPVRJ4D2HyZT87tbZq47zgG9n8Q7xCzY,8589
2
+ fabricatio-0.2.4.dev3.dist-info/WHEEL,sha256=RIvmwLDYujv60MYBx2jxyP4vdn1DD7X0kBgz1TQvZuc,108
3
+ fabricatio-0.2.4.dev3.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
4
4
  fabricatio/decorators.py,sha256=cJHsxxbnMhc4SzPl4454CPLuDP3H0qbTrzV_U2rLPrs,6372
5
5
  fabricatio/core.py,sha256=MaEKZ6DDmbdScAY-7F1gwGA6fr7ADX6Mz5rNVi2msFA,6277
6
6
  fabricatio/models/generic.py,sha256=bjAD8g4tz1VjnIfnpTD6sRu1dBuBoswmUrn6pCnL6aY,11504
@@ -21,7 +21,7 @@ fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
21
21
  fabricatio/fs/readers.py,sha256=lqMrM5Nt3l6QJmPDoBno2PSaN2BbFwfUjBqaghrbK3A,1002
22
22
  fabricatio/fs/curd.py,sha256=g74Pc2WPSkPlCXX0cWj2jyiDYTfkLwpwM480eyCkmc8,3851
23
23
  fabricatio/fs/__init__.py,sha256=Jlzk4AvBFgcgQ6nIgGRSUIh2UZHtpl27eyu395lR3c0,448
24
- fabricatio/config.py,sha256=ZUUJ5rb6ZBq8Vrkk9wqfMU8ncomRoHgarW7YuThEJK4,13188
24
+ fabricatio/config.py,sha256=DfGJurqWVoLNgx9-DiCqBhcxgMSBY52atriw2iZsq1E,13341
25
25
  fabricatio/journal.py,sha256=bzxZay48ZWI0VIkkDXm4Wc_Cc9lBQYa2VGx3Hxy_PtA,753
26
26
  fabricatio/__init__.py,sha256=gakP6hzHIQccKu9ByHhUP-cN36wCPEr11s13iTdO6EY,1503
27
27
  fabricatio/actions/rag.py,sha256=tP1uKLq7mo19YhsJzFbGYryrcMx6xcvBc3n_Wzh0hjg,796
@@ -29,11 +29,11 @@ fabricatio/actions/article.py,sha256=ozqEa75_MS4OfCJZzcmF5_s3AJmAUrQGdHORWtZBsE0
29
29
  fabricatio/_rust_instances.py,sha256=JAtO-vL8ihvduf1SHLNf0w7ZSVGCJeIv6zZ9Ekyy1hY,271
30
30
  fabricatio/workflows/articles.py,sha256=KlTaMSnxkQqHAIl-zZ8_wMqheka7IL99nt7XzQxDSF0,462
31
31
  fabricatio/parser.py,sha256=S-4p1mjvJZEgnQW6WKdkmE68MzqqWXGSiLbADdhE-W4,4791
32
- fabricatio/capabilities/rag.py,sha256=bF-SSZRQbG00QjzoAXrWCfzFxHxfvxV3al_G8T4jxL8,12985
32
+ fabricatio/capabilities/rag.py,sha256=OscJ8MVgOViMYps7rp8-MzAfSiog5i7zp7RkFzoSJPI,13805
33
33
  fabricatio/capabilities/rating.py,sha256=E1obAS48B4j3Cf6rC6h-TyzRb4vQ2Hho2IM7630jSoI,13695
34
34
  fabricatio/capabilities/propose.py,sha256=oW9QKpY2mDkVPEvgsgqxXxDR2ylVqN5TEL8E0Wh_vJI,1714
35
35
  fabricatio/capabilities/task.py,sha256=BISAFbMgBI4udW0otE3-iyq0RXc05YN_30N0yI5qLxQ,4504
36
36
  fabricatio/_rust.pyi,sha256=clhcURuiB9zlFo4m3VyoWQ8Xs4tvg6KNHXpF-ok9h4o,1703
37
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=CDyz4oafWsO46rOc8DyHBfDVj4dY2LkheAQTGfSXmgs,1333952
38
- fabricatio-0.2.4.dev2.data/scripts/tdown,sha256=lUUKFHytXf1um4ZhtzvZlMqpBPWN7IjAsKKT9IgDwog,4560064
39
- fabricatio-0.2.4.dev2.dist-info/RECORD,,
37
+ fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=cdj3XswppApEvlov50l7ZgS_MLO3DMj_8B2SFdsWXe0,1350776
38
+ fabricatio-0.2.4.dev3.data/scripts/tdown,sha256=lUUKFHytXf1um4ZhtzvZlMqpBPWN7IjAsKKT9IgDwog,4560064
39
+ fabricatio-0.2.4.dev3.dist-info/RECORD,,