fabricatio 0.2.13.dev3__cp312-cp312-win_amd64.whl → 0.3.13__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.
Files changed (41) hide show
  1. fabricatio/__init__.py +3 -3
  2. fabricatio/actions/article.py +32 -34
  3. fabricatio/actions/article_rag.py +58 -58
  4. fabricatio/actions/output.py +22 -21
  5. fabricatio/actions/rag.py +4 -3
  6. fabricatio/capabilities/check.py +29 -30
  7. fabricatio/capabilities/correct.py +23 -23
  8. fabricatio/capabilities/extract.py +36 -32
  9. fabricatio/capabilities/rag.py +34 -35
  10. fabricatio/capabilities/rating.py +77 -72
  11. fabricatio/capabilities/review.py +12 -11
  12. fabricatio/capabilities/task.py +4 -5
  13. fabricatio/core.py +22 -24
  14. fabricatio/decorators.py +10 -10
  15. fabricatio/fs/__init__.py +1 -2
  16. fabricatio/journal.py +2 -9
  17. fabricatio/models/action.py +2 -1
  18. fabricatio/models/extra/aricle_rag.py +10 -9
  19. fabricatio/models/extra/article_base.py +5 -6
  20. fabricatio/models/extra/article_main.py +11 -10
  21. fabricatio/models/generic.py +31 -59
  22. fabricatio/models/role.py +5 -3
  23. fabricatio/models/task.py +9 -9
  24. fabricatio/models/tool.py +5 -4
  25. fabricatio/models/usages.py +170 -161
  26. fabricatio/parser.py +2 -2
  27. fabricatio/rust.cp312-win_amd64.pyd +0 -0
  28. fabricatio/rust.pyi +435 -17
  29. fabricatio-0.3.13.data/scripts/tdown.exe +0 -0
  30. fabricatio-0.3.13.data/scripts/ttm.exe +0 -0
  31. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
  32. fabricatio-0.3.13.dist-info/RECORD +63 -0
  33. fabricatio/config.py +0 -430
  34. fabricatio/constants.py +0 -20
  35. fabricatio/models/events.py +0 -120
  36. fabricatio/rust_instances.py +0 -10
  37. fabricatio-0.2.13.dev3.data/scripts/tdown.exe +0 -0
  38. fabricatio-0.2.13.dev3.data/scripts/ttm.exe +0 -0
  39. fabricatio-0.2.13.dev3.dist-info/RECORD +0 -67
  40. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
  41. {fabricatio-0.2.13.dev3.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
@@ -6,16 +6,7 @@ from typing import Callable, Dict, Iterable, List, Literal, Optional, Self, Sequ
6
6
 
7
7
  import asyncstdlib
8
8
  import litellm
9
- from fabricatio.config import configs
10
- from fabricatio.decorators import logging_exec_time
11
- from fabricatio.journal import logger
12
- from fabricatio.models.generic import ScopedConfig, WithBriefing
13
- from fabricatio.models.kwargs_types import ChooseKwargs, EmbeddingKwargs, GenerateKwargs, LLMKwargs, ValidateKwargs
14
- from fabricatio.models.task import Task
15
- from fabricatio.models.tool import Tool, ToolBox
16
- from fabricatio.parser import GenericCapture, JsonCapture
17
- from fabricatio.rust_instances import TEMPLATE_MANAGER
18
- from fabricatio.utils import ok
9
+ from fabricatio.rust import CONFIG, TEMPLATE_MANAGER
19
10
  from litellm import RateLimitError, Router, stream_chunk_builder # pyright: ignore [reportPrivateImportUsage]
20
11
  from litellm.types.router import Deployment, LiteLLM_Params, ModelInfo
21
12
  from litellm.types.utils import (
@@ -29,18 +20,21 @@ from litellm.utils import CustomStreamWrapper, token_counter # pyright: ignore
29
20
  from more_itertools import duplicates_everseen
30
21
  from pydantic import BaseModel, ConfigDict, Field, NonNegativeInt, PositiveInt
31
22
 
32
- if configs.cache.enabled and configs.cache.type:
33
- litellm.enable_cache(type=configs.cache.type, **configs.cache.params)
34
- logger.debug(f"{configs.cache.type.name} Cache enabled")
23
+ from fabricatio.decorators import logging_exec_time
24
+ from fabricatio.journal import logger
25
+ from fabricatio.models.generic import ScopedConfig, WithBriefing
26
+ from fabricatio.models.kwargs_types import ChooseKwargs, EmbeddingKwargs, GenerateKwargs, LLMKwargs, ValidateKwargs
27
+ from fabricatio.models.task import Task
28
+ from fabricatio.models.tool import Tool, ToolBox
29
+ from fabricatio.parser import GenericCapture, JsonCapture
30
+ from fabricatio.utils import ok
35
31
 
36
32
  ROUTER = Router(
37
33
  routing_strategy="usage-based-routing-v2",
38
- default_max_parallel_requests=configs.routing.max_parallel_requests,
39
- allowed_fails=configs.routing.allowed_fails,
40
- retry_after=configs.routing.retry_after,
41
- cooldown_time=configs.routing.cooldown_time,
42
- cache_responses=configs.cache.enabled,
43
- cache_kwargs=configs.cache.params,
34
+ default_max_parallel_requests=CONFIG.routing.max_parallel_requests,
35
+ allowed_fails=CONFIG.routing.allowed_fails,
36
+ retry_after=CONFIG.routing.retry_after,
37
+ cooldown_time=CONFIG.routing.cooldown_time,
44
38
  )
45
39
 
46
40
 
@@ -65,10 +59,10 @@ class LLMUsage(ScopedConfig):
65
59
 
66
60
  # noinspection PyTypeChecker,PydanticTypeChecker,t
67
61
  async def aquery(
68
- self,
69
- messages: List[Dict[str, str]],
70
- n: PositiveInt | None = None,
71
- **kwargs: Unpack[LLMKwargs],
62
+ self,
63
+ messages: List[Dict[str, str]],
64
+ n: PositiveInt | None = None,
65
+ **kwargs: Unpack[LLMKwargs],
72
66
  ) -> ModelResponse | CustomStreamWrapper:
73
67
  """Asynchronously queries the language model to generate a response based on the provided messages and parameters.
74
68
 
@@ -86,36 +80,36 @@ class LLMUsage(ScopedConfig):
86
80
  Deployment(
87
81
  model_name=(
88
82
  m_name := ok(
89
- kwargs.get("model") or self.llm_model or configs.llm.model, "model name is not set at any place"
83
+ kwargs.get("model") or self.llm_model or CONFIG.llm.model, "model name is not set at any place"
90
84
  )
91
85
  ), # pyright: ignore [reportCallIssue]
92
86
  litellm_params=(
93
87
  p := LiteLLM_Params(
94
88
  api_key=ok(
95
- self.llm_api_key or configs.llm.api_key, "llm api key is not set at any place"
89
+ self.llm_api_key or CONFIG.llm.api_key, "llm api key is not set at any place"
96
90
  ).get_secret_value(),
97
91
  api_base=ok(
98
- self.llm_api_endpoint or configs.llm.api_endpoint,
92
+ self.llm_api_endpoint or CONFIG.llm.api_endpoint,
99
93
  "llm api endpoint is not set at any place",
100
94
  ).unicode_string(),
101
95
  model=m_name,
102
- tpm=self.llm_tpm or configs.llm.tpm,
103
- rpm=self.llm_rpm or configs.llm.rpm,
104
- max_retries=kwargs.get("max_retries") or self.llm_max_retries or configs.llm.max_retries,
105
- timeout=kwargs.get("timeout") or self.llm_timeout or configs.llm.timeout,
96
+ tpm=self.llm_tpm or CONFIG.llm.tpm,
97
+ rpm=self.llm_rpm or CONFIG.llm.rpm,
98
+ max_retries=kwargs.get("max_retries") or self.llm_max_retries or CONFIG.llm.max_retries,
99
+ timeout=kwargs.get("timeout") or self.llm_timeout or CONFIG.llm.timeout,
106
100
  )
107
101
  ),
108
102
  model_info=ModelInfo(id=hash(m_name + p.model_dump_json(exclude_none=True))),
109
103
  )
110
104
  ).acompletion(
111
105
  messages=messages, # pyright: ignore [reportArgumentType]
112
- n=n or self.llm_generation_count or configs.llm.generation_count,
106
+ n=n or self.llm_generation_count or CONFIG.llm.generation_count,
113
107
  model=m_name,
114
- temperature=kwargs.get("temperature") or self.llm_temperature or configs.llm.temperature,
115
- stop=kwargs.get("stop") or self.llm_stop_sign or configs.llm.stop_sign,
116
- top_p=kwargs.get("top_p") or self.llm_top_p or configs.llm.top_p,
117
- max_tokens=kwargs.get("max_tokens") or self.llm_max_tokens or configs.llm.max_tokens,
118
- stream=ok(kwargs.get("stream") or self.llm_stream or configs.llm.stream, "stream is not set at any place"),
108
+ temperature=kwargs.get("temperature") or self.llm_temperature or CONFIG.llm.temperature,
109
+ stop=kwargs.get("stop") or self.llm_stop_sign or CONFIG.llm.stop_sign,
110
+ top_p=kwargs.get("top_p") or self.llm_top_p or CONFIG.llm.top_p,
111
+ max_tokens=kwargs.get("max_tokens") or self.llm_max_tokens or CONFIG.llm.max_tokens,
112
+ stream=ok(kwargs.get("stream") or self.llm_stream or CONFIG.llm.stream, "stream is not set at any place"),
119
113
  cache={
120
114
  "no-cache": kwargs.get("no_cache"),
121
115
  "no-store": kwargs.get("no_store"),
@@ -123,19 +117,19 @@ class LLMUsage(ScopedConfig):
123
117
  "s-maxage": kwargs.get("s_maxage"),
124
118
  },
125
119
  presence_penalty=kwargs.get("presence_penalty")
126
- or self.llm_presence_penalty
127
- or configs.llm.presence_penalty,
120
+ or self.llm_presence_penalty
121
+ or CONFIG.llm.presence_penalty,
128
122
  frequency_penalty=kwargs.get("frequency_penalty")
129
- or self.llm_frequency_penalty
130
- or configs.llm.frequency_penalty,
123
+ or self.llm_frequency_penalty
124
+ or CONFIG.llm.frequency_penalty,
131
125
  )
132
126
 
133
127
  async def ainvoke(
134
- self,
135
- question: str,
136
- system_message: str = "",
137
- n: PositiveInt | None = None,
138
- **kwargs: Unpack[LLMKwargs],
128
+ self,
129
+ question: str,
130
+ system_message: str = "",
131
+ n: PositiveInt | None = None,
132
+ **kwargs: Unpack[LLMKwargs],
139
133
  ) -> Sequence[TextChoices | Choices | StreamingChoices]:
140
134
  """Asynchronously invokes the language model with a question and optional system message.
141
135
 
@@ -156,8 +150,6 @@ class LLMUsage(ScopedConfig):
156
150
  if isinstance(resp, ModelResponse):
157
151
  return resp.choices
158
152
  if isinstance(resp, CustomStreamWrapper):
159
- if not configs.debug.streaming_visible and (pack := stream_chunk_builder(await asyncstdlib.list())):
160
- return pack.choices
161
153
  if pack := stream_chunk_builder(await asyncstdlib.list(resp)):
162
154
  return pack.choices
163
155
  logger.critical(err := f"Unexpected response type: {type(resp)}")
@@ -165,40 +157,46 @@ class LLMUsage(ScopedConfig):
165
157
 
166
158
  @overload
167
159
  async def aask(
168
- self,
169
- question: List[str],
170
- system_message: List[str],
171
- **kwargs: Unpack[LLMKwargs],
172
- ) -> List[str]: ...
160
+ self,
161
+ question: List[str],
162
+ system_message: List[str],
163
+ **kwargs: Unpack[LLMKwargs],
164
+ ) -> List[str]:
165
+ ...
166
+
173
167
  @overload
174
168
  async def aask(
175
- self,
176
- question: str,
177
- system_message: List[str],
178
- **kwargs: Unpack[LLMKwargs],
179
- ) -> List[str]: ...
169
+ self,
170
+ question: str,
171
+ system_message: List[str],
172
+ **kwargs: Unpack[LLMKwargs],
173
+ ) -> List[str]:
174
+ ...
175
+
180
176
  @overload
181
177
  async def aask(
182
- self,
183
- question: List[str],
184
- system_message: Optional[str] = None,
185
- **kwargs: Unpack[LLMKwargs],
186
- ) -> List[str]: ...
178
+ self,
179
+ question: List[str],
180
+ system_message: Optional[str] = None,
181
+ **kwargs: Unpack[LLMKwargs],
182
+ ) -> List[str]:
183
+ ...
187
184
 
188
185
  @overload
189
186
  async def aask(
190
- self,
191
- question: str,
192
- system_message: Optional[str] = None,
193
- **kwargs: Unpack[LLMKwargs],
194
- ) -> str: ...
187
+ self,
188
+ question: str,
189
+ system_message: Optional[str] = None,
190
+ **kwargs: Unpack[LLMKwargs],
191
+ ) -> str:
192
+ ...
195
193
 
196
194
  @logging_exec_time
197
195
  async def aask(
198
- self,
199
- question: str | List[str],
200
- system_message: Optional[str | List[str]] = None,
201
- **kwargs: Unpack[LLMKwargs],
196
+ self,
197
+ question: str | List[str],
198
+ system_message: Optional[str | List[str]] = None,
199
+ **kwargs: Unpack[LLMKwargs],
202
200
  ) -> str | List[str]:
203
201
  """Asynchronously asks the language model a question and returns the response content.
204
202
 
@@ -226,60 +224,68 @@ class LLMUsage(ScopedConfig):
226
224
  res = await gather(*[self.ainvoke(n=1, question=q, system_message=sm, **kwargs) for sm in sm_seq])
227
225
  out = [r[0].message.content for r in res] # pyright: ignore [reportAttributeAccessIssue]
228
226
  case (str(q), str(sm)):
229
- out = ((await self.ainvoke(n=1, question=q, system_message=sm, **kwargs))[0]).message.content # pyright: ignore [reportAttributeAccessIssue]
227
+ out = ((await self.ainvoke(n=1, question=q, system_message=sm, **kwargs))[
228
+ 0]).message.content # pyright: ignore [reportAttributeAccessIssue]
230
229
  case _:
231
230
  raise RuntimeError("Should not reach here.")
232
231
 
233
232
  logger.debug(
234
- f"Response Token Count: {token_counter(text=out) if isinstance(out, str) else sum(token_counter(text=o) for o in out)}" # pyright: ignore [reportOptionalIterable]
233
+ f"Response Token Count: {token_counter(text=out) if isinstance(out, str) else sum(token_counter(text=o) for o in out)}"
234
+ # pyright: ignore [reportOptionalIterable]
235
235
  )
236
236
  return out # pyright: ignore [reportReturnType]
237
237
 
238
238
  @overload
239
239
  async def aask_validate[T](
240
- self,
241
- question: str,
242
- validator: Callable[[str], T | None],
243
- default: T = ...,
244
- max_validations: PositiveInt = 2,
245
- **kwargs: Unpack[GenerateKwargs],
246
- ) -> T: ...
240
+ self,
241
+ question: str,
242
+ validator: Callable[[str], T | None],
243
+ default: T = ...,
244
+ max_validations: PositiveInt = 2,
245
+ **kwargs: Unpack[GenerateKwargs],
246
+ ) -> T:
247
+ ...
248
+
247
249
  @overload
248
250
  async def aask_validate[T](
249
- self,
250
- question: List[str],
251
- validator: Callable[[str], T | None],
252
- default: T = ...,
253
- max_validations: PositiveInt = 2,
254
- **kwargs: Unpack[GenerateKwargs],
255
- ) -> List[T]: ...
251
+ self,
252
+ question: List[str],
253
+ validator: Callable[[str], T | None],
254
+ default: T = ...,
255
+ max_validations: PositiveInt = 2,
256
+ **kwargs: Unpack[GenerateKwargs],
257
+ ) -> List[T]:
258
+ ...
259
+
256
260
  @overload
257
261
  async def aask_validate[T](
258
- self,
259
- question: str,
260
- validator: Callable[[str], T | None],
261
- default: None = None,
262
- max_validations: PositiveInt = 2,
263
- **kwargs: Unpack[GenerateKwargs],
264
- ) -> Optional[T]: ...
262
+ self,
263
+ question: str,
264
+ validator: Callable[[str], T | None],
265
+ default: None = None,
266
+ max_validations: PositiveInt = 2,
267
+ **kwargs: Unpack[GenerateKwargs],
268
+ ) -> Optional[T]:
269
+ ...
265
270
 
266
271
  @overload
267
272
  async def aask_validate[T](
268
- self,
269
- question: List[str],
270
- validator: Callable[[str], T | None],
271
- default: None = None,
272
- max_validations: PositiveInt = 2,
273
- **kwargs: Unpack[GenerateKwargs],
274
- ) -> List[Optional[T]]: ...
273
+ self,
274
+ question: List[str],
275
+ validator: Callable[[str], T | None],
276
+ default: None = None,
277
+ max_validations: PositiveInt = 2,
278
+ **kwargs: Unpack[GenerateKwargs],
279
+ ) -> List[Optional[T]]:
280
+ ...
275
281
 
276
282
  async def aask_validate[T](
277
- self,
278
- question: str | List[str],
279
- validator: Callable[[str], T | None],
280
- default: Optional[T] = None,
281
- max_validations: PositiveInt = 3,
282
- **kwargs: Unpack[GenerateKwargs],
283
+ self,
284
+ question: str | List[str],
285
+ validator: Callable[[str], T | None],
286
+ default: Optional[T] = None,
287
+ max_validations: PositiveInt = 3,
288
+ **kwargs: Unpack[GenerateKwargs],
283
289
  ) -> Optional[T] | List[Optional[T]] | List[T] | T:
284
290
  """Asynchronously asks a question and validates the response using a given validator.
285
291
 
@@ -319,7 +325,7 @@ class LLMUsage(ScopedConfig):
319
325
  return await (gather(*[_inner(q) for q in question]) if isinstance(question, list) else _inner(question))
320
326
 
321
327
  async def alist_str(
322
- self, requirement: str, k: NonNegativeInt = 0, **kwargs: Unpack[ValidateKwargs[List[str]]]
328
+ self, requirement: str, k: NonNegativeInt = 0, **kwargs: Unpack[ValidateKwargs[List[str]]]
323
329
  ) -> Optional[List[str]]:
324
330
  """Asynchronously generates a list of strings based on a given requirement.
325
331
 
@@ -333,7 +339,7 @@ class LLMUsage(ScopedConfig):
333
339
  """
334
340
  return await self.aask_validate(
335
341
  TEMPLATE_MANAGER.render_template(
336
- configs.templates.liststr_template,
342
+ CONFIG.templates.liststr_template,
337
343
  {"requirement": requirement, "k": k},
338
344
  ),
339
345
  lambda resp: JsonCapture.validate_with(resp, target_type=list, elements_type=str, length=k),
@@ -352,7 +358,7 @@ class LLMUsage(ScopedConfig):
352
358
  """
353
359
  return await self.alist_str(
354
360
  TEMPLATE_MANAGER.render_template(
355
- configs.templates.pathstr_template,
361
+ CONFIG.templates.pathstr_template,
356
362
  {"requirement": requirement},
357
363
  ),
358
364
  **kwargs,
@@ -369,9 +375,9 @@ class LLMUsage(ScopedConfig):
369
375
  Optional[str]: The validated response as a single string.
370
376
  """
371
377
  if paths := await self.apathstr(
372
- requirement,
373
- k=1,
374
- **kwargs,
378
+ requirement,
379
+ k=1,
380
+ **kwargs,
375
381
  ):
376
382
  return paths.pop()
377
383
 
@@ -389,7 +395,7 @@ class LLMUsage(ScopedConfig):
389
395
  """
390
396
  return await self.aask_validate( # pyright: ignore [reportReturnType]
391
397
  TEMPLATE_MANAGER.render_template(
392
- configs.templates.generic_string_template,
398
+ CONFIG.templates.generic_string_template,
393
399
  {"requirement": requirement, "language": GenericCapture.capture_type},
394
400
  ),
395
401
  validator=lambda resp: GenericCapture.capture(resp),
@@ -397,11 +403,11 @@ class LLMUsage(ScopedConfig):
397
403
  )
398
404
 
399
405
  async def achoose[T: WithBriefing](
400
- self,
401
- instruction: str,
402
- choices: List[T],
403
- k: NonNegativeInt = 0,
404
- **kwargs: Unpack[ValidateKwargs[List[T]]],
406
+ self,
407
+ instruction: str,
408
+ choices: List[T],
409
+ k: NonNegativeInt = 0,
410
+ **kwargs: Unpack[ValidateKwargs[List[T]]],
405
411
  ) -> Optional[List[T]]:
406
412
  """Asynchronously executes a multi-choice decision-making process, generating a prompt based on the instruction and options, and validates the returned selection results.
407
413
 
@@ -418,7 +424,7 @@ class LLMUsage(ScopedConfig):
418
424
  logger.error(err := f"Redundant choices: {dup}")
419
425
  raise ValueError(err)
420
426
  prompt = TEMPLATE_MANAGER.render_template(
421
- configs.templates.make_choice_template,
427
+ CONFIG.templates.make_choice_template,
422
428
  {
423
429
  "instruction": instruction,
424
430
  "options": [m.model_dump(include={"name", "briefing"}) for m in choices],
@@ -444,10 +450,10 @@ class LLMUsage(ScopedConfig):
444
450
  )
445
451
 
446
452
  async def apick[T: WithBriefing](
447
- self,
448
- instruction: str,
449
- choices: List[T],
450
- **kwargs: Unpack[ValidateKwargs[List[T]]],
453
+ self,
454
+ instruction: str,
455
+ choices: List[T],
456
+ **kwargs: Unpack[ValidateKwargs[List[T]]],
451
457
  ) -> T:
452
458
  """Asynchronously picks a single choice from a list of options using AI validation.
453
459
 
@@ -472,11 +478,11 @@ class LLMUsage(ScopedConfig):
472
478
  )[0]
473
479
 
474
480
  async def ajudge(
475
- self,
476
- prompt: str,
477
- affirm_case: str = "",
478
- deny_case: str = "",
479
- **kwargs: Unpack[ValidateKwargs[bool]],
481
+ self,
482
+ prompt: str,
483
+ affirm_case: str = "",
484
+ deny_case: str = "",
485
+ **kwargs: Unpack[ValidateKwargs[bool]],
480
486
  ) -> Optional[bool]:
481
487
  """Asynchronously judges a prompt using AI validation.
482
488
 
@@ -491,7 +497,7 @@ class LLMUsage(ScopedConfig):
491
497
  """
492
498
  return await self.aask_validate(
493
499
  question=TEMPLATE_MANAGER.render_template(
494
- configs.templates.make_judgment_template,
500
+ CONFIG.templates.make_judgment_template,
495
501
  {"prompt": prompt, "affirm_case": affirm_case, "deny_case": deny_case},
496
502
  ),
497
503
  validator=lambda resp: JsonCapture.validate_with(resp, target_type=bool),
@@ -506,12 +512,12 @@ class EmbeddingUsage(LLMUsage):
506
512
  """
507
513
 
508
514
  async def aembedding(
509
- self,
510
- input_text: List[str],
511
- model: Optional[str] = None,
512
- dimensions: Optional[int] = None,
513
- timeout: Optional[PositiveInt] = None,
514
- caching: Optional[bool] = False,
515
+ self,
516
+ input_text: List[str],
517
+ model: Optional[str] = None,
518
+ dimensions: Optional[int] = None,
519
+ timeout: Optional[PositiveInt] = None,
520
+ caching: Optional[bool] = False,
515
521
  ) -> EmbeddingResponse:
516
522
  """Asynchronously generates embeddings for the given input text.
517
523
 
@@ -526,29 +532,29 @@ class EmbeddingUsage(LLMUsage):
526
532
  EmbeddingResponse: The response containing the embeddings.
527
533
  """
528
534
  # check seq length
529
- max_len = self.embedding_max_sequence_length or configs.embedding.max_sequence_length
535
+ max_len = self.embedding_max_sequence_length or CONFIG.embedding.max_sequence_length
530
536
  if max_len and any(length := (token_counter(text=t)) > max_len for t in input_text):
531
537
  logger.error(err := f"Input text exceeds maximum sequence length {max_len}, got {length}.")
532
538
  raise ValueError(err)
533
539
 
534
540
  return await litellm.aembedding(
535
541
  input=input_text,
536
- caching=caching or self.embedding_caching or configs.embedding.caching,
537
- dimensions=dimensions or self.embedding_dimensions or configs.embedding.dimensions,
538
- model=model or self.embedding_model or configs.embedding.model or self.llm_model or configs.llm.model,
542
+ caching=caching or self.embedding_caching or CONFIG.embedding.caching,
543
+ dimensions=dimensions or self.embedding_dimensions or CONFIG.embedding.dimensions,
544
+ model=model or self.embedding_model or CONFIG.embedding.model or self.llm_model or CONFIG.llm.model,
539
545
  timeout=timeout
540
- or self.embedding_timeout
541
- or configs.embedding.timeout
542
- or self.llm_timeout
543
- or configs.llm.timeout,
546
+ or self.embedding_timeout
547
+ or CONFIG.embedding.timeout
548
+ or self.llm_timeout
549
+ or CONFIG.llm.timeout,
544
550
  api_key=ok(
545
- self.embedding_api_key or configs.embedding.api_key or self.llm_api_key or configs.llm.api_key
551
+ self.embedding_api_key or CONFIG.embedding.api_key or self.llm_api_key or CONFIG.llm.api_key
546
552
  ).get_secret_value(),
547
553
  api_base=ok(
548
554
  self.embedding_api_endpoint
549
- or configs.embedding.api_endpoint
555
+ or CONFIG.embedding.api_endpoint
550
556
  or self.llm_api_endpoint
551
- or configs.llm.api_endpoint
557
+ or CONFIG.llm.api_endpoint
552
558
  )
553
559
  .unicode_string()
554
560
  .rstrip("/"),
@@ -556,12 +562,15 @@ class EmbeddingUsage(LLMUsage):
556
562
  )
557
563
 
558
564
  @overload
559
- async def vectorize(self, input_text: List[str], **kwargs: Unpack[EmbeddingKwargs]) -> List[List[float]]: ...
565
+ async def vectorize(self, input_text: List[str], **kwargs: Unpack[EmbeddingKwargs]) -> List[List[float]]:
566
+ ...
567
+
560
568
  @overload
561
- async def vectorize(self, input_text: str, **kwargs: Unpack[EmbeddingKwargs]) -> List[float]: ...
569
+ async def vectorize(self, input_text: str, **kwargs: Unpack[EmbeddingKwargs]) -> List[float]:
570
+ ...
562
571
 
563
572
  async def vectorize(
564
- self, input_text: List[str] | str, **kwargs: Unpack[EmbeddingKwargs]
573
+ self, input_text: List[str] | str, **kwargs: Unpack[EmbeddingKwargs]
565
574
  ) -> List[List[float]] | List[float]:
566
575
  """Asynchronously generates vector embeddings for the given input text.
567
576
 
@@ -597,9 +606,9 @@ class ToolBoxUsage(LLMUsage):
597
606
  return [toolbox.name for toolbox in self.toolboxes]
598
607
 
599
608
  async def choose_toolboxes(
600
- self,
601
- task: Task,
602
- **kwargs: Unpack[ChooseKwargs[List[ToolBox]]],
609
+ self,
610
+ task: Task,
611
+ **kwargs: Unpack[ChooseKwargs[List[ToolBox]]],
603
612
  ) -> Optional[List[ToolBox]]:
604
613
  """Asynchronously executes a multi-choice decision-making process to choose toolboxes.
605
614
 
@@ -620,10 +629,10 @@ class ToolBoxUsage(LLMUsage):
620
629
  )
621
630
 
622
631
  async def choose_tools(
623
- self,
624
- task: Task,
625
- toolbox: ToolBox,
626
- **kwargs: Unpack[ChooseKwargs[List[Tool]]],
632
+ self,
633
+ task: Task,
634
+ toolbox: ToolBox,
635
+ **kwargs: Unpack[ChooseKwargs[List[Tool]]],
627
636
  ) -> Optional[List[Tool]]:
628
637
  """Asynchronously executes a multi-choice decision-making process to choose tools.
629
638
 
@@ -645,10 +654,10 @@ class ToolBoxUsage(LLMUsage):
645
654
  )
646
655
 
647
656
  async def gather_tools_fine_grind(
648
- self,
649
- task: Task,
650
- box_choose_kwargs: Optional[ChooseKwargs] = None,
651
- tool_choose_kwargs: Optional[ChooseKwargs] = None,
657
+ self,
658
+ task: Task,
659
+ box_choose_kwargs: Optional[ChooseKwargs] = None,
660
+ tool_choose_kwargs: Optional[ChooseKwargs] = None,
652
661
  ) -> List[Tool]:
653
662
  """Asynchronously gathers tools based on the provided task and toolbox and tool selection criteria.
654
663
 
fabricatio/parser.py CHANGED
@@ -6,10 +6,10 @@ from re import Pattern, compile
6
6
  from typing import Any, Callable, Iterable, List, Optional, Self, Tuple, Type
7
7
 
8
8
  import ujson
9
+ from fabricatio.rust import CONFIG
9
10
  from json_repair import repair_json
10
11
  from pydantic import BaseModel, ConfigDict, Field, PositiveInt, PrivateAttr, ValidationError
11
12
 
12
- from fabricatio.config import configs
13
13
  from fabricatio.journal import logger
14
14
 
15
15
 
@@ -46,7 +46,7 @@ class Capture(BaseModel):
46
46
  str | List[str]: The fixed text with the same type as input.
47
47
  """
48
48
  match self.capture_type:
49
- case "json" if configs.general.use_json_repair:
49
+ case "json" if CONFIG.general.use_json_repair:
50
50
  logger.debug("Applying json repair to text.")
51
51
  if isinstance(text, str):
52
52
  return repair_json(text, ensure_ascii=False) # pyright: ignore [reportReturnType]
Binary file