bella-openapi 1.0.2.5__py3-none-any.whl → 1.0.3__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/__init__.py CHANGED
@@ -3,19 +3,8 @@ from .log import operation_log, submit_log
3
3
  from .openapi_contexvar import trace_id_context, caller_id_context, request_url_context
4
4
  from .auth_billing import ErrorInfo, async_authenticate_decorator_args, authenticate_user, print_context, \
5
5
  get_context, set_context, clean_context, report
6
- from .entity import (
7
- StandardDomTree,
8
- StandardNode,
9
- SourceFile,
10
- StandardPosition,
11
- StandardImage,
12
- Cell,
13
- StandardRow,
14
- StandardBaseElement,
15
- StandardElement,
16
- StandardTableElement,
17
- StandardImageElement
18
- )
6
+ from .entity import StandardDomTree, StandardNode, SourceFile, StandardPosition, StandardImage, Cell, \
7
+ StandardRow, StandardBaseElement, StandardElement, StandardTableElement, StandardImageElement
19
8
 
20
9
  __all__ = ["validate_token", "operation_log",
21
10
  "support_model",
@@ -306,18 +306,16 @@ class StandardDomTree(BaseModel):
306
306
  # 检查前一个节点
307
307
  if i > 0:
308
308
  prev_sibling = node.children[i - 1]
309
- if prev_sibling.element and prev_sibling.element.type == target_type:
310
- # 找到对应类型的前一个兄弟节点,合并节点
311
- if cls._merge_nodes(prev_sibling, current, target_type):
312
- merged = True
309
+ # 找到对应类型的前一个兄弟节点,合并节点
310
+ merged = ( prev_sibling.element and prev_sibling.element.type == target_type and
311
+ cls._merge_nodes(prev_sibling, current, target_type))
313
312
 
314
313
  # 如果没有与前一个节点合并,检查后一个节点
315
314
  if not merged and i < len(node.children) - 1:
316
315
  next_sibling = node.children[i + 1]
317
- if next_sibling.element and next_sibling.element.type == target_type:
318
- # 找到对应类型的后一个兄弟节点,合并节点
319
- if cls._merge_nodes(next_sibling, current, target_type):
320
- merged = True
316
+ # 找到对应类型的后一个兄弟节点,合并节点
317
+ merged = (next_sibling.element and next_sibling.element.type == target_type and
318
+ cls._merge_nodes(next_sibling, current, target_type))
321
319
 
322
320
  # 如果没有找到对应类型的兄弟节点,将当前节点类型改为 Text
323
321
  if not merged:
@@ -348,23 +346,25 @@ class StandardDomTree(BaseModel):
348
346
  Returns:
349
347
  bool: 是否成功合并
350
348
  """
351
- if node_type == 'Figure' and isinstance(target_node.element, StandardImageElement):
352
- # FigureName 的文本作为 Figure 的 name
349
+ # 定义节点类型与元素类型的映射
350
+ type_element_mapping = {
351
+ 'Figure': StandardImageElement,
352
+ 'Table': StandardTableElement
353
+ }
354
+
355
+ can_merge = (node_type in type_element_mapping and
356
+ isinstance(target_node.element, type_element_mapping[node_type]))
357
+
358
+ # 检查节点类型是否支持且目标节点元素类型匹配
359
+ if can_merge:
360
+ # 将源节点的文本作为目标节点的 name
353
361
  target_node.element.name = source_node.element.text
354
362
  # 更新 tokens 计数
355
363
  target_node.tokens += source_node.tokens
356
- # 将 FigureName 的位置添加到 Figure 中
364
+ # 将源节点的位置添加到目标节点中
357
365
  target_node.element.positions += source_node.element.positions
358
- return True
359
- elif node_type == 'Table' and isinstance(target_node.element, StandardTableElement):
360
- # 将 TableName 的文本作为 Table 的 name
361
- target_node.element.name = source_node.element.text
362
- # 更新 tokens 计数
363
- target_node.tokens += source_node.tokens
364
- # 将 Table 的位置添加到 Figure 中
365
- target_node.element.positions += source_node.element.positions
366
- return True
367
- return False
366
+
367
+ return can_merge
368
368
 
369
369
  @classmethod
370
370
  def _from_domtree_node_to_base_info(cls, node: dict) -> Optional[StandardNode]:
@@ -492,17 +492,17 @@ class StandardDomTree(BaseModel):
492
492
  return standard_node
493
493
 
494
494
  @classmethod
495
- def count_tokens(cls, text: str, model: str = "gpt-4") -> int:
495
+ def count_tokens(cls, text: str) -> int:
496
496
  """
497
497
  计算文本的token数量
498
498
 
499
499
  Args:
500
500
  text: 要计算的文本
501
- model: 使用的模型名称,默认为gpt-4
502
501
 
503
502
  Returns:
504
503
  int: token数量
505
504
  """
505
+ model = "gpt-4" # 使用模型默认为gpt-4
506
506
  if not text:
507
507
  return 0
508
508
  encoding = tiktoken.encoding_for_model(model)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bella-openapi
3
- Version: 1.0.2.5
3
+ Version: 1.0.3
4
4
  Summary: client for openapi service.
5
5
  Home-page:
6
6
  Author: ['tangxiaolong', 'fanqiangwei', 'zhangxiaojia', 'liumin', 'wangyukun']
@@ -1,4 +1,4 @@
1
- bella_openapi/__init__.py,sha256=Iq8YjMYBNWJvQvlu9gFy8uxG8Xf06jPaCyZvXtAW2jA,1462
1
+ bella_openapi/__init__.py,sha256=RBVZURWQwmb8dN7S6cgDej29bcg_EiHhCmpx1qQMgnw,1420
2
2
  bella_openapi/auth_billing.py,sha256=Hn0KS8GuG48etnvnd1Faej4IfFXD3tjzalUzDnpZh7Q,3520
3
3
  bella_openapi/authorize.py,sha256=cO6J-wx9dmmkDAeqpXT7QlyCr13hO-HSC5SWQSw2gZw,2150
4
4
  bella_openapi/config.py,sha256=Dn8vnToDaOesPGboauxCCwNrW5awQLeSkmDjNjXS4bQ,319
@@ -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=EzeYH_UH8MfcVucOcviof8qAIZ5BULVu2DO2EBN7F-c,20510
17
+ bella_openapi/entity/standard_domtree.py,sha256=oN2z_t5uTzO01szVSEnsN_GWYtxKkgvQPgJuOnOOaFs,20270
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.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,,
20
+ bella_openapi-1.0.3.dist-info/licenses/LICENSE,sha256=O-0zMbcEi6wXz1DiSdVgzMlQjJcNqNe5KDv08uYzqR0,1055
21
+ bella_openapi-1.0.3.dist-info/METADATA,sha256=DauqWLJgwkWy0eSl-l_HISwuvEQ1t3NScpBmkZ9qa6c,9375
22
+ bella_openapi-1.0.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ bella_openapi-1.0.3.dist-info/top_level.txt,sha256=EZuq3F6tKeF-vmZQi6_S2XzmES7SPW7HAbGN1Uv9vN8,14
24
+ bella_openapi-1.0.3.dist-info/RECORD,,