fabricatio 0.2.13.dev2__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.
- fabricatio/__init__.py +3 -3
- fabricatio/actions/article.py +32 -34
- fabricatio/actions/article_rag.py +89 -69
- fabricatio/actions/output.py +22 -21
- fabricatio/actions/rag.py +4 -3
- fabricatio/capabilities/check.py +29 -30
- fabricatio/capabilities/correct.py +23 -23
- fabricatio/capabilities/extract.py +36 -32
- fabricatio/capabilities/rag.py +34 -35
- fabricatio/capabilities/rating.py +77 -72
- fabricatio/capabilities/review.py +12 -11
- fabricatio/capabilities/task.py +4 -5
- fabricatio/core.py +22 -24
- fabricatio/decorators.py +10 -10
- fabricatio/fs/__init__.py +1 -2
- fabricatio/journal.py +2 -9
- fabricatio/models/action.py +2 -1
- fabricatio/models/extra/aricle_rag.py +10 -9
- fabricatio/models/extra/article_base.py +30 -6
- fabricatio/models/extra/article_main.py +11 -10
- fabricatio/models/extra/article_outline.py +5 -36
- fabricatio/models/generic.py +31 -59
- fabricatio/models/role.py +5 -3
- fabricatio/models/task.py +9 -9
- fabricatio/models/tool.py +5 -4
- fabricatio/models/usages.py +170 -161
- fabricatio/parser.py +2 -2
- fabricatio/rust.cp312-win_amd64.pyd +0 -0
- fabricatio/rust.pyi +496 -14
- fabricatio-0.3.13.data/scripts/tdown.exe +0 -0
- fabricatio-0.3.13.data/scripts/ttm.exe +0 -0
- {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/METADATA +1 -3
- fabricatio-0.3.13.dist-info/RECORD +63 -0
- fabricatio/config.py +0 -430
- fabricatio/constants.py +0 -20
- fabricatio/models/events.py +0 -120
- fabricatio/rust_instances.py +0 -10
- fabricatio-0.2.13.dev2.data/scripts/tdown.exe +0 -0
- fabricatio-0.2.13.dev2.data/scripts/ttm.exe +0 -0
- fabricatio-0.2.13.dev2.dist-info/RECORD +0 -67
- {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/WHEEL +0 -0
- {fabricatio-0.2.13.dev2.dist-info → fabricatio-0.3.13.dist-info}/licenses/LICENSE +0 -0
fabricatio/models/usages.py
CHANGED
@@ -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.
|
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
|
-
|
33
|
-
|
34
|
-
|
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=
|
39
|
-
allowed_fails=
|
40
|
-
retry_after=
|
41
|
-
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
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
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
|
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
|
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
|
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
|
103
|
-
rpm=self.llm_rpm or
|
104
|
-
max_retries=kwargs.get("max_retries") or self.llm_max_retries or
|
105
|
-
timeout=kwargs.get("timeout") or self.llm_timeout or
|
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
|
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
|
115
|
-
stop=kwargs.get("stop") or self.llm_stop_sign or
|
116
|
-
top_p=kwargs.get("top_p") or self.llm_top_p or
|
117
|
-
max_tokens=kwargs.get("max_tokens") or self.llm_max_tokens or
|
118
|
-
stream=ok(kwargs.get("stream") or self.llm_stream or
|
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
|
-
|
127
|
-
|
120
|
+
or self.llm_presence_penalty
|
121
|
+
or CONFIG.llm.presence_penalty,
|
128
122
|
frequency_penalty=kwargs.get("frequency_penalty")
|
129
|
-
|
130
|
-
|
123
|
+
or self.llm_frequency_penalty
|
124
|
+
or CONFIG.llm.frequency_penalty,
|
131
125
|
)
|
132
126
|
|
133
127
|
async def ainvoke(
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
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
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
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
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
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
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
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
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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))[
|
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)}"
|
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
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
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
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
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
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
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
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
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
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
373
|
-
|
374
|
-
|
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
|
-
|
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
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
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
|
-
|
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
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
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
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
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
|
-
|
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
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
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
|
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
|
537
|
-
dimensions=dimensions or self.embedding_dimensions or
|
538
|
-
model=model or self.embedding_model or
|
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
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
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
|
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
|
555
|
+
or CONFIG.embedding.api_endpoint
|
550
556
|
or self.llm_api_endpoint
|
551
|
-
or
|
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
|
-
|
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
|
-
|
601
|
-
|
602
|
-
|
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
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
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
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
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
|
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
|