fabricatio 0.2.6.dev7__cp312-cp312-manylinux_2_34_x86_64.whl → 0.2.6.dev8__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.
fabricatio/actions/rag.py CHANGED
@@ -3,6 +3,7 @@
3
3
  from typing import List, Optional
4
4
 
5
5
  from fabricatio.capabilities.rag import RAG
6
+ from fabricatio.journal import logger
6
7
  from fabricatio.models.action import Action
7
8
  from fabricatio.models.generic import PrepareVectorization
8
9
 
@@ -13,13 +14,13 @@ class InjectToDB(Action, RAG):
13
14
  output_key: str = "collection_name"
14
15
 
15
16
  async def _execute[T: PrepareVectorization](
16
- self, to_inject: T | List[T], collection_name: Optional[str] = "my_collection", **_
17
+ self, to_inject: Optional[T] | List[Optional[T]], collection_name: Optional[str] = "my_collection", **_
17
18
  ) -> Optional[str]:
18
19
  if not isinstance(to_inject, list):
19
20
  to_inject = [to_inject]
20
-
21
+ logger.info(f"Injecting {len(to_inject)} items into the collection '{collection_name}'")
21
22
  await self.view(collection_name, create=True).consume_string(
22
- [t.prepare_vectorization(self.embedding_max_sequence_length) for t in to_inject],
23
+ [t.prepare_vectorization(self.embedding_max_sequence_length) for t in to_inject if isinstance(t,PrepareVectorization)],
23
24
  )
24
25
 
25
26
  return collection_name
@@ -63,10 +63,18 @@ class RAG(EmbeddingUsage):
63
63
  uri=milvus_uri or ok(self.milvus_uri or configs.rag.milvus_uri).unicode_string(),
64
64
  token=milvus_token
65
65
  or (token.get_secret_value() if (token := (self.milvus_token or configs.rag.milvus_token)) else ""),
66
- timeout=milvus_timeout or self.milvus_timeout,
66
+ timeout=milvus_timeout or self.milvus_timeout or configs.rag.milvus_timeout,
67
67
  )
68
68
  return self
69
69
 
70
+ def check_client(self, init: bool = True) -> Self:
71
+ """Check if the client is initialized, and if not, initialize it."""
72
+ if self._client is None and init:
73
+ return self.init_client()
74
+ if self._client is None and not init:
75
+ raise RuntimeError("Client is not initialized. Have you called `self.init_client()`?")
76
+ return self
77
+
70
78
  @overload
71
79
  async def pack(
72
80
  self, input_text: List[str], subject: Optional[str] = None, **kwargs: Unpack[EmbeddingKwargs]
@@ -111,8 +119,15 @@ class RAG(EmbeddingUsage):
111
119
  create (bool): Whether to create the collection if it does not exist.
112
120
  **kwargs (Unpack[CollectionConfigKwargs]): Additional keyword arguments for collection configuration.
113
121
  """
114
- if create and collection_name and self.client.has_collection(collection_name):
115
- kwargs["dimension"] = kwargs.get("dimension") or self.milvus_dimensions or configs.rag.milvus_dimensions
122
+ if create and collection_name and not self.check_client().client.has_collection(collection_name):
123
+ kwargs["dimension"] = ok(
124
+ kwargs.get("dimension")
125
+ or self.milvus_dimensions
126
+ or configs.rag.milvus_dimensions
127
+ or self.embedding_dimensions
128
+ or configs.embedding.dimensions,
129
+ "`dimension` is not set at any level.",
130
+ )
116
131
  self.client.create_collection(collection_name, auto_id=True, **kwargs)
117
132
  logger.info(f"Creating collection {collection_name}")
118
133
 
@@ -158,7 +173,7 @@ class RAG(EmbeddingUsage):
158
173
  else:
159
174
  raise TypeError(f"Expected MilvusData or list of MilvusData, got {type(data)}")
160
175
  c_name = collection_name or self.safe_target_collection
161
- self.client.insert(c_name, prepared_data)
176
+ self.check_client().client.insert(c_name, prepared_data)
162
177
 
163
178
  if flush:
164
179
  logger.debug(f"Flushing collection {c_name}")
@@ -219,7 +234,7 @@ class RAG(EmbeddingUsage):
219
234
  List[Dict[str, Any]] | List[Any]: The retrieved data.
220
235
  """
221
236
  # Step 1: Search for vectors
222
- search_results = self.client.search(
237
+ search_results = self.check_client().client.search(
223
238
  collection_name or self.safe_target_collection,
224
239
  vecs,
225
240
  search_params={"radius": similarity_threshold},
fabricatio/config.py CHANGED
@@ -277,7 +277,7 @@ class RagConfig(BaseModel):
277
277
 
278
278
  milvus_uri: Optional[HttpUrl] = Field(default=HttpUrl("http://localhost:19530"))
279
279
  """The URI of the Milvus server."""
280
- milvus_timeout: Optional[PositiveFloat] = Field(default=None)
280
+ milvus_timeout: Optional[PositiveFloat] = Field(default=30.0)
281
281
  """The timeout of the Milvus server."""
282
282
  milvus_token: Optional[SecretStr] = Field(default=None)
283
283
  """The token of the Milvus server."""
@@ -303,11 +303,13 @@ class RoutingConfig(BaseModel):
303
303
 
304
304
  model_config = ConfigDict(use_attribute_docstrings=True)
305
305
 
306
- allowed_fails: Optional[int] = 1
306
+ max_parallel_requests: Optional[int] = 60
307
+ """The maximum number of parallel requests. None means not checked."""
308
+ allowed_fails: Optional[int] = 3
307
309
  """The number of allowed fails before the routing is considered failed."""
308
310
  retry_after: int = 15
309
311
  """The time in seconds to wait before retrying the routing after a fail."""
310
- cooldown_time: Optional[int] = 120
312
+ cooldown_time: Optional[int] = 30
311
313
  """The time in seconds to wait before retrying the routing after a cooldown."""
312
314
 
313
315
 
@@ -216,3 +216,15 @@ class WorkFlow(WithBriefing, ToolBoxUsage):
216
216
  """
217
217
  self.provide_tools_to(self._instances)
218
218
  return self
219
+
220
+ def update_init_context(self, **kwargs) -> Self:
221
+ """Update the initial context with additional key-value pairs.
222
+
223
+ Args:
224
+ **kwargs: Key-value pairs to add to the initial context.
225
+
226
+ Returns:
227
+ Self: The workflow instance for method chaining.
228
+ """
229
+ self.extra_init_context.update(kwargs)
230
+ return self
@@ -109,28 +109,25 @@ class ArticleEssence(ProposedAble, Display, PrepareVectorization):
109
109
 
110
110
  Encodes research artifacts with dual human-machine interpretability.
111
111
  """
112
-
113
112
  title: str = Field(...)
114
- """Complete title with technical specificity (12-18 words).
115
- Must contain:
116
- 1. Methodology focus
117
- 2. Application domain
118
- 3. Performance metric
119
- Example: 'EfficientViT: Multi-Scale Linear Attention for High-Resolution Dense Prediction'"""
113
+ """Exact title of the original article without any modification.
114
+ Must be preserved precisely from the source material without:
115
+ - Translation
116
+ - Paraphrasing
117
+ - Adding/removing words
118
+ - Altering style or formatting
119
+ Example: The exact published title as it appears in the original document"""
120
120
 
121
121
  authors: List[str]
122
- """Author list with institutional annotations.
123
- Format: [First Last¹, First Last²]
124
- Superscripts mapping to affiliations.
125
- Example: ['Yuanhao Zhou¹', 'Lei Chen²']"""
122
+ """Original author names exactly as they appear in the source document. No translation or paraphrasing.
123
+ Extract complete list without any modifications or formatting changes."""
126
124
 
127
125
  keywords: List[str]
128
- """5-8 ACM CCS concepts in camel case.
129
- Example: ['Computing methodologies~Neural networks', 'Hardware~Emerging technologies']"""
126
+ """Original keywords exactly as they appear in the source document. No translation or paraphrasing.
127
+ Extract the complete set without modifying format or terminology."""
130
128
 
131
129
  publication_year: int
132
- """Publication timestamp in ISO 8601 (YYYY format).
133
- Constraint: 2017 ≤ year ≤ current_year"""
130
+ """Publication timestamp in ISO 8601 (YYYY format)."""
134
131
 
135
132
  highlightings: Highlightings = Field(default_factory=Highlightings)
136
133
  """Technical highlight reel containing:
@@ -14,7 +14,7 @@ from fabricatio.models.task import Task
14
14
  from fabricatio.models.tool import Tool, ToolBox
15
15
  from fabricatio.models.utils import Messages, ok
16
16
  from fabricatio.parser import GenericCapture, JsonCapture
17
- from litellm import Router, stream_chunk_builder # pyright: ignore [reportPrivateImportUsage]
17
+ from litellm import RateLimitError, Router, stream_chunk_builder # pyright: ignore [reportPrivateImportUsage]
18
18
  from litellm.types.router import Deployment, LiteLLM_Params, ModelInfo
19
19
  from litellm.types.utils import (
20
20
  Choices,
@@ -33,6 +33,7 @@ if configs.cache.enabled and configs.cache.type:
33
33
 
34
34
  ROUTER = Router(
35
35
  routing_strategy="usage-based-routing-v2",
36
+ default_max_parallel_requests=configs.routing.max_parallel_requests,
36
37
  allowed_fails=configs.routing.allowed_fails,
37
38
  retry_after=configs.routing.retry_after,
38
39
  cooldown_time=configs.routing.cooldown_time,
@@ -305,6 +306,9 @@ class LLMUsage(ScopedConfig):
305
306
  ):
306
307
  logger.debug(f"Successfully validated the co-response at {lap}th attempt.")
307
308
  return validated
309
+ except RateLimitError as e:
310
+ logger.warning(f"Rate limit error: {e}")
311
+ continue
308
312
  except Exception as e: # noqa: BLE001
309
313
  logger.error(f"Error during validation: \n{e}")
310
314
  break
@@ -172,6 +172,10 @@ def override_kwargs[T](kwargs: Dict[str, T], **overrides) -> Dict[str, T]:
172
172
  kwargs.update({k: v for k, v in overrides.items() if v is not None})
173
173
  return kwargs
174
174
 
175
+ def fallback_kwargs[T](kwargs: Dict[str, T], **overrides) -> Dict[str, T]:
176
+ """Fallback the values in kwargs with the provided overrides."""
177
+ kwargs.update({k: v for k, v in overrides.items() if k not in kwargs})
178
+ return kwargs
175
179
 
176
180
  def ok[T](val: Optional[T], msg:str="Value is None") -> T:
177
181
  """Check if a value is None and raise a ValueError with the provided message if it is.
Binary file
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fabricatio
3
- Version: 0.2.6.dev7
3
+ Version: 0.2.6.dev8
4
4
  Classifier: License :: OSI Approved :: MIT License
5
5
  Classifier: Programming Language :: Rust
6
6
  Classifier: Programming Language :: Python :: 3.12
@@ -1,18 +1,18 @@
1
- fabricatio-0.2.6.dev7.dist-info/METADATA,sha256=uKqLHzycJi0fHhq9xKJUCiO-DzWApY-ZBPI4xUmNTek,13693
2
- fabricatio-0.2.6.dev7.dist-info/WHEEL,sha256=7FgAcpQES0h1xhfN9Ugve9FTUilU6sRAr1WJ5ph2cuw,108
3
- fabricatio-0.2.6.dev7.dist-info/licenses/LICENSE,sha256=yDZaTLnOi03bi3Dk6f5IjhLUc5old2yOsihHWU0z-i0,1067
1
+ fabricatio-0.2.6.dev8.dist-info/METADATA,sha256=GTgXD_uf_Sq2d3rQqEDNMSgnoEWI17uRXZqmUF53Ff4,13693
2
+ fabricatio-0.2.6.dev8.dist-info/WHEEL,sha256=7FgAcpQES0h1xhfN9Ugve9FTUilU6sRAr1WJ5ph2cuw,108
3
+ fabricatio-0.2.6.dev8.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=WxT4KBGGZTpqGPSPVwD5mkmhYBjxggZ7n-HKi-Hed4M,13619
7
7
  fabricatio/models/tool.py,sha256=ATwbOyvOTzrfAKcbOmCqdG3je4-T5jrM6FIw4cDPRDY,6863
8
8
  fabricatio/models/role.py,sha256=UgIfGdfIBu4cOug8Nm1a04JCEwjXR_MDZUQhumwMptk,2710
9
- fabricatio/models/extra.py,sha256=JXrLJWOapiu5HwkhJTtvK8bD50IImpRi19DB3HVbsQ0,25605
9
+ fabricatio/models/extra.py,sha256=e6sWvmBG-U_ErxwITJ1wQGE3xsSuC18xnpxlU9gMY6M,25659
10
10
  fabricatio/models/kwargs_types.py,sha256=rqhCG2QLj4iyZ5WnLU4IT0xPdzFWvgsz9g6qau3bD1E,4839
11
- fabricatio/models/utils.py,sha256=snRuH81CQfTr9GZMSV_cW0JZocwfttgsKAqFWPk_Vc8,5480
12
- fabricatio/models/usages.py,sha256=ovuvDab9wvn9no4_a93HVcdo8Da1kF_eOnMoqph7LcY,30145
11
+ fabricatio/models/utils.py,sha256=E1Jz7oodbn09OkBspSpzCgKkv0AiuxyQElqCgHF7bVY,5718
12
+ fabricatio/models/usages.py,sha256=ALB9V0Gfli2T9LDZ_gdvdChXwj6ieDeuK6Qye6NPXgE,30368
13
13
  fabricatio/models/events.py,sha256=UvOc6V3vfjKuvh7irDezJ8EGpsNo5yzLdq4xQexVonw,4063
14
14
  fabricatio/models/task.py,sha256=-EnzpEyM6Z687gF1lPcmA2szEUw6dFpu3lOtseaz95o,10193
15
- fabricatio/models/action.py,sha256=Y8fYLWi28edtmi9KZIlE9E7M9_G4GcWMeraTLPVjp_c,7992
15
+ fabricatio/models/action.py,sha256=E8PELqsP9ZRwI7xQyXe5wqIPTGQsMk0sHKSnsic0S40,8359
16
16
  fabricatio/toolboxes/fs.py,sha256=OQMdeokYxSNVrCZJAweJ0cYiK4k2QuEiNdIbS5IHIV8,705
17
17
  fabricatio/toolboxes/__init__.py,sha256=dYm_Gd8XolSU_h4wnkA09dlaLDK146eeFz0CUgPZ8_c,380
18
18
  fabricatio/toolboxes/arithmetic.py,sha256=sSTPkKI6-mb278DwQKFO9jKyzc9kCx45xNH7V6bGBpE,1307
@@ -20,23 +20,23 @@ fabricatio/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
20
  fabricatio/fs/readers.py,sha256=5bLlpqcdhIwWfysh7gvfVv0PPPVAeDlTPGwNTio6j9M,1156
21
21
  fabricatio/fs/curd.py,sha256=FuG75qco4dX8vhIK27gKz9rKUXbWHOFg5yK3nGLB25s,4469
22
22
  fabricatio/fs/__init__.py,sha256=hTuYtzmvIGtbg7PTdoqLEQJ0E63hOzZltCIrLlDKaSE,559
23
- fabricatio/config.py,sha256=6BXaIUZsfxuIvNOt74lmlBYoS_uBQhcCwGAmmxdvKZk,16232
23
+ fabricatio/config.py,sha256=n5jU6j0SS8x3crJomwF8_6FI-UPGzEDsxL_zkxSZSkk,16352
24
24
  fabricatio/journal.py,sha256=Op0wC-JlZumnAc_aDmYM4ljnSNLoKEEMfcIRbCF69ow,455
25
25
  fabricatio/__init__.py,sha256=6EjK4SxbnvFxdO9ftkXD9rxSuoPEIITNzUkuMO9s3yU,1092
26
26
  fabricatio/actions/output.py,sha256=wNyLNxjqBlms0hyxap8XUPgN53izipJrCOtpX6aluFQ,626
27
- fabricatio/actions/rag.py,sha256=xCCNPM4pgjGlKaIl1J4SpWoNx3oWlSMxq6pQRSquXmc,788
27
+ fabricatio/actions/rag.py,sha256=z1XJ8ZC1oJtVJvpUia8hSb0wnAA1uE61pRDt6QAzC3Y,980
28
28
  fabricatio/actions/article.py,sha256=m3ejPgLX7WXcg-CfqRjQmanc5qSvCsT_u02wW9Jb23w,4435
29
29
  fabricatio/_rust_instances.py,sha256=bQmlhUCcxTmRgvw1SfzYzNNpgW_UCjmkYw5f-VPAyg8,304
30
30
  fabricatio/workflows/articles.py,sha256=oHNV5kNKEcOKP55FA7I1SlxQRlk6N26cpem_QYu05g0,1021
31
31
  fabricatio/workflows/rag.py,sha256=uOZXprD479fUhLA6sYvEM8RWcVcUZXXtP0xRbTMPdHE,509
32
32
  fabricatio/parser.py,sha256=OV6bIAfLJ-GfaKoTeIOqS3X3GqCgyvzSJsgYMO3ogj4,6100
33
33
  fabricatio/capabilities/correct.py,sha256=BiLEAk6e1KbwUMhTexmDfgtlPUct_bG0igDK7CwHqao,5107
34
- fabricatio/capabilities/rag.py,sha256=psRCuKo7vLJXBGrm48FsFIzrawZ2JO5OJsvH05CJ8Tg,15402
34
+ fabricatio/capabilities/rag.py,sha256=FxhbHuEaeZudCSgqJD2S-hVZZAMG1Dro8dmLlRnXnEk,16075
35
35
  fabricatio/capabilities/rating.py,sha256=ZQrKKmmIgnN4zgNnG_GmWa5Nyxpk03JYW32RJ4R5vvQ,14067
36
36
  fabricatio/capabilities/review.py,sha256=TX7av4b2N7MRDHMowsIZfiujXRRNxjUMNHtCFVA1UTM,10824
37
37
  fabricatio/capabilities/propose.py,sha256=4QvONVVUp1rs34Te2Rjams6NioEt6FhEAxDWiveQnSg,1544
38
38
  fabricatio/capabilities/task.py,sha256=llFFKh8MAaTjsp8DtAGD_UUONROfFNxorh6NLys973U,4496
39
39
  fabricatio/_rust.pyi,sha256=1TvnaXK_QKM8Et05LkZ_vOGR4WISVd9X8lU6OTwFFaU,3376
40
- fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=Qv4F28dducNx2GS8L8TmMWuk3MgBivQbzH_UmC-1P2w,1911376
41
- fabricatio-0.2.6.dev7.data/scripts/tdown,sha256=h7dazHQEgymw8fXo1ROyyUfwLMMw7l4JyMlt2xJyN-4,4576688
42
- fabricatio-0.2.6.dev7.dist-info/RECORD,,
40
+ fabricatio/_rust.cpython-312-x86_64-linux-gnu.so,sha256=t1COw3bM_BmYYizdCwuFx_fq0PnhFPZO-zLJTJDkC40,1910320
41
+ fabricatio-0.2.6.dev8.data/scripts/tdown,sha256=Y3fBi2TPyjMz2tt8bXf8yB263OBAHob40owbzNsJZvM,4578912
42
+ fabricatio-0.2.6.dev8.dist-info/RECORD,,
Binary file