fabricatio 0.2.4.dev2__cp312-cp312-win_amd64.whl → 0.2.4.dev3__cp312-cp312-win_amd64.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.
Binary file
@@ -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,13 +1,13 @@
1
- fabricatio-0.2.4.dev2.dist-info/METADATA,sha256=YUalxhNAZsg0MtzLphoGT-eQdAjp0sk07vr_4aGqsOU,8861
2
- fabricatio-0.2.4.dev2.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
- fabricatio-0.2.4.dev2.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
1
+ fabricatio-0.2.4.dev3.dist-info/METADATA,sha256=ylm4KBEqXPqU0YJT7HpEaLhwMuWEPU3YaDcTMsleHEE,8861
2
+ fabricatio-0.2.4.dev3.dist-info/WHEEL,sha256=tpW5AN9B-9qsM9WW2FXG2r193YXiqexDadpKp0A2daI,96
3
+ fabricatio-0.2.4.dev3.dist-info/licenses/LICENSE,sha256=do7J7EiCGbq0QPbMAL_FqLYufXpHnCnXBOuqVPwSV8Y,1088
4
4
  fabricatio/actions/article.py,sha256=xrY04lIbq2ol_eW0kw0l9GmZsOXSlTCpjuR38t_bzEE,2026
5
5
  fabricatio/actions/rag.py,sha256=lZfw9SZ8oxbWPK_bvWsEpVkWJbGP8HUnlNbxLh11Wdg,821
6
6
  fabricatio/capabilities/propose.py,sha256=nahXjB6_nP0Fru880oh_9oINrjrL0Qs-SLHA-d3CFUE,1769
7
- fabricatio/capabilities/rag.py,sha256=paq2zUOfw6whIBFkKDo1Kg5Ft5YXgWiJBNKq-6uGhuU,13295
7
+ fabricatio/capabilities/rag.py,sha256=UWRUQtlhGUT9Zz3c5iErWjpiTr4LWUV184uMSMhrC_g,14139
8
8
  fabricatio/capabilities/rating.py,sha256=PcUpKxPfVO-vitgA6py1xg9iLJZdf7Fru--18ZUFKKA,14026
9
9
  fabricatio/capabilities/task.py,sha256=s6FiC9Wg_l-qSa2LgsoKV9f6wXZN6Q_FlWn3XbSnrys,4618
10
- fabricatio/config.py,sha256=yPJjrGhvoWyXfLBTJp2pMvHt9F-0uskE-va7QDo0rxI,13525
10
+ fabricatio/config.py,sha256=dbVwH1ZEkBSt1wiO7q4gl6U5_72y6AKkcwswPYXEQCc,13681
11
11
  fabricatio/core.py,sha256=VQ_JKgUGIy2gZ8xsTBZCdr_IP7wC5aPg0_bsOmjQ588,6458
12
12
  fabricatio/decorators.py,sha256=uzsP4tFKQNjDHBkofsjjoJA0IUAaYOtt6YVedoyOqlo,6551
13
13
  fabricatio/fs/curd.py,sha256=faMstgGUiQ4k2AW3OXfvvWWTldTtKXco7QINYaMjmyA,3981
@@ -34,6 +34,6 @@ fabricatio/workflows/articles.py,sha256=gZlmC2tS1YnSajZft6jN0VTSj6rcuT8367nBYD8e
34
34
  fabricatio/_rust.pyi,sha256=0wCqtwWkVxxoqprvk8T27T8QYKIAKHS7xgsmdMNjQKc,1756
35
35
  fabricatio/_rust_instances.py,sha256=dl0-yZ4UvT5g20tQgnPJpmqtkjFGXNG_YK4eLfi_ugQ,279
36
36
  fabricatio/__init__.py,sha256=lIjAvhmypC8kZNpymjmYByJtZjzJNXDmNzY36x1o7h8,1554
37
- fabricatio/_rust.cp312-win_amd64.pyd,sha256=7rUG_4XSeuPJ3ohjbxqO82_v-Uzz6thtmnJHLkkHXP8,1256448
38
- fabricatio-0.2.4.dev2.data/scripts/tdown.exe,sha256=SgyRf4z5d_TsM5rWtd9dvyrELP4lSYAm689xzwqPIm8,3397632
39
- fabricatio-0.2.4.dev2.dist-info/RECORD,,
37
+ fabricatio/_rust.cp312-win_amd64.pyd,sha256=awkdolid46gR8FEGI9Hxx04KPmXs35jZdXaauhazzoM,1277952
38
+ fabricatio-0.2.4.dev3.data/scripts/tdown.exe,sha256=OhB53d4Eswjsw9TEcNsQCkd5D32BVEME6yRGsti1PTU,3397632
39
+ fabricatio-0.2.4.dev3.dist-info/RECORD,,