bella-openapi 1.0.2.4__py3-none-any.whl → 1.0.2.5__py3-none-any.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.
- bella_openapi/entity/standard_domtree.py +23 -12
- {bella_openapi-1.0.2.4.dist-info → bella_openapi-1.0.2.5.dist-info}/METADATA +1 -1
- {bella_openapi-1.0.2.4.dist-info → bella_openapi-1.0.2.5.dist-info}/RECORD +6 -6
- {bella_openapi-1.0.2.4.dist-info → bella_openapi-1.0.2.5.dist-info}/WHEEL +0 -0
- {bella_openapi-1.0.2.4.dist-info → bella_openapi-1.0.2.5.dist-info}/licenses/LICENSE +0 -0
- {bella_openapi-1.0.2.4.dist-info → bella_openapi-1.0.2.5.dist-info}/top_level.txt +0 -0
@@ -31,16 +31,7 @@ layout_type_mapping = {
|
|
31
31
|
"TableNote": "Text", # 目前实际解析出来没有
|
32
32
|
}
|
33
33
|
|
34
|
-
|
35
|
-
def count_tokens(text: str, model: str = "gpt-4") -> int:
|
36
|
-
if not text:
|
37
|
-
return 0
|
38
|
-
encoding = tiktoken.encoding_for_model(model)
|
39
|
-
tokens = encoding.encode(text)
|
40
|
-
# 计算标记列表的长度,即标记的数量
|
41
|
-
token_count = len(tokens)
|
42
|
-
# 返回标记的数量
|
43
|
-
return token_count
|
34
|
+
|
44
35
|
|
45
36
|
class SourceFile(BaseModel):
|
46
37
|
id: str # 文件ID,唯一标识符,类型为string
|
@@ -440,7 +431,7 @@ class StandardDomTree(BaseModel):
|
|
440
431
|
cell_data['end_col']],
|
441
432
|
text=cell_text,
|
442
433
|
# 目前只会有一个元素,且是Text类型,Path重新从头编号,相对cell是root
|
443
|
-
nodes=[StandardNode(summary="", tokens=count_tokens(cell_text), path=[1], children=[],
|
434
|
+
nodes=[StandardNode(summary="", tokens=cls.count_tokens(cell_text), path=[1], children=[],
|
444
435
|
element=StandardElement(
|
445
436
|
type='Text',
|
446
437
|
positions=[],
|
@@ -491,7 +482,7 @@ class StandardDomTree(BaseModel):
|
|
491
482
|
standard_node.children.append(standard_child)
|
492
483
|
|
493
484
|
# 计算 token 数量:自身 text 的 token 数量 + 子节点 token 数量
|
494
|
-
tokens = count_tokens(text)
|
485
|
+
tokens = cls.count_tokens(text)
|
495
486
|
for child in standard_node.children:
|
496
487
|
tokens += child.tokens
|
497
488
|
|
@@ -500,3 +491,23 @@ class StandardDomTree(BaseModel):
|
|
500
491
|
|
501
492
|
return standard_node
|
502
493
|
|
494
|
+
@classmethod
|
495
|
+
def count_tokens(cls, text: str, model: str = "gpt-4") -> int:
|
496
|
+
"""
|
497
|
+
计算文本的token数量
|
498
|
+
|
499
|
+
Args:
|
500
|
+
text: 要计算的文本
|
501
|
+
model: 使用的模型名称,默认为gpt-4
|
502
|
+
|
503
|
+
Returns:
|
504
|
+
int: token数量
|
505
|
+
"""
|
506
|
+
if not text:
|
507
|
+
return 0
|
508
|
+
encoding = tiktoken.encoding_for_model(model)
|
509
|
+
tokens = encoding.encode(text)
|
510
|
+
# 计算标记列表的长度,即标记的数量
|
511
|
+
token_count = len(tokens)
|
512
|
+
# 返回标记的数量
|
513
|
+
return token_count
|
@@ -14,11 +14,11 @@ bella_openapi/bella_trace/trace_requests.py,sha256=ADA8J_gbC3TwUo5LWQ3c_yTmCSZRa
|
|
14
14
|
bella_openapi/console/__init__.py,sha256=uSfr5v6JLRSqTlftjK_ZU1pnbkEyxAPbuQbMyYX_phk,64
|
15
15
|
bella_openapi/console/models.py,sha256=Hh1UuYHIxFtF9r5QK-pSJPFrSqbZUHv6spLvPbCeX08,1274
|
16
16
|
bella_openapi/entity/__init__.py,sha256=zzsYYg859pzPSgx1Py2kxB2ozQ0tt4OtTatBtpm2bAw,512
|
17
|
-
bella_openapi/entity/standard_domtree.py,sha256=
|
17
|
+
bella_openapi/entity/standard_domtree.py,sha256=EzeYH_UH8MfcVucOcviof8qAIZ5BULVu2DO2EBN7F-c,20510
|
18
18
|
bella_openapi/middleware/__init__.py,sha256=XWvZG1xO30ZXIn10YVYthmT1BV-9fonMEP_jVRZbAlQ,157
|
19
19
|
bella_openapi/middleware/context_middleware.py,sha256=YawQyKAxMzvlDs_MxcuQKh90pP6VoMKzCBDS94qmlzQ,3870
|
20
|
-
bella_openapi-1.0.2.
|
21
|
-
bella_openapi-1.0.2.
|
22
|
-
bella_openapi-1.0.2.
|
23
|
-
bella_openapi-1.0.2.
|
24
|
-
bella_openapi-1.0.2.
|
20
|
+
bella_openapi-1.0.2.5.dist-info/licenses/LICENSE,sha256=O-0zMbcEi6wXz1DiSdVgzMlQjJcNqNe5KDv08uYzqR0,1055
|
21
|
+
bella_openapi-1.0.2.5.dist-info/METADATA,sha256=ohCbeW5mv4uFMn3NgoscDQxEBKW7zi168nRfIbgltc0,9377
|
22
|
+
bella_openapi-1.0.2.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
bella_openapi-1.0.2.5.dist-info/top_level.txt,sha256=EZuq3F6tKeF-vmZQi6_S2XzmES7SPW7HAbGN1Uv9vN8,14
|
24
|
+
bella_openapi-1.0.2.5.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|