bella-openapi 1.0.2.5__tar.gz → 1.0.3.1__tar.gz

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 (30) hide show
  1. {bella_openapi-1.0.2.5/src/bella_openapi.egg-info → bella_openapi-1.0.3.1}/PKG-INFO +2 -1
  2. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/setup.py +2 -1
  3. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/__init__.py +2 -13
  4. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/entity/standard_domtree.py +38 -41
  5. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1/src/bella_openapi.egg-info}/PKG-INFO +2 -1
  6. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi.egg-info/requires.txt +1 -0
  7. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/LICENSE +0 -0
  8. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/README.md +0 -0
  9. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/setup.cfg +0 -0
  10. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/auth_billing.py +0 -0
  11. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/authorize.py +0 -0
  12. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/bella_trace/__init__.py +0 -0
  13. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/bella_trace/_context.py +0 -0
  14. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/bella_trace/fastapi_interceptor.py +0 -0
  15. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/bella_trace/record_log.py +0 -0
  16. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/bella_trace/trace_requests.py +0 -0
  17. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/config.py +0 -0
  18. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/console/__init__.py +0 -0
  19. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/console/models.py +0 -0
  20. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/entity/__init__.py +0 -0
  21. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/exception.py +0 -0
  22. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/log.py +0 -0
  23. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/middleware/__init__.py +0 -0
  24. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/middleware/context_middleware.py +0 -0
  25. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/openapi_contexvar.py +0 -0
  26. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi/schema.py +0 -0
  27. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi.egg-info/SOURCES.txt +0 -0
  28. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi.egg-info/dependency_links.txt +0 -0
  29. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi.egg-info/not-zip-safe +0 -0
  30. {bella_openapi-1.0.2.5 → bella_openapi-1.0.3.1}/src/bella_openapi.egg-info/top_level.txt +0 -0
@@ -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.1
4
4
  Summary: client for openapi service.
5
5
  Home-page:
6
6
  Author: ['tangxiaolong', 'fanqiangwei', 'zhangxiaojia', 'liumin', 'wangyukun']
@@ -12,6 +12,7 @@ License-File: LICENSE
12
12
  Requires-Dist: httpx<=0.26.0,>=0.10.0
13
13
  Requires-Dist: Werkzeug==3.0.1
14
14
  Requires-Dist: tiktoken>=0.5.0
15
+ Requires-Dist: pydantic==2.11.7
15
16
  Dynamic: author
16
17
  Dynamic: classifier
17
18
  Dynamic: description
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
3
3
 
4
4
  SHORT = "client for openapi service."
5
5
 
6
- __version__ = "1.0.2.5"
6
+ __version__ = "1.0.3.1"
7
7
  __author__ = ["tangxiaolong", "fanqiangwei", "zhangxiaojia", 'liumin', 'wangyukun']
8
8
  __email__ = ''
9
9
  readme_path = 'README.md'
@@ -17,6 +17,7 @@ setup(
17
17
  'httpx>=0.10.0,<=0.26.0',
18
18
  'Werkzeug==3.0.1',
19
19
  'tiktoken>=0.5.0',
20
+ 'pydantic==2.11.7'
20
21
  ],
21
22
  url='',
22
23
  author=__author__,
@@ -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",
@@ -129,7 +129,7 @@ class StandardDomTree(BaseModel):
129
129
  # 添加表格名称
130
130
  if node.element.name:
131
131
  markdown_res += f"**{node.element.name}**\n\n"
132
- table_md = self._list_to_html_table(node.element.rows)
132
+ table_md = self._list_to_markdown_table(node.element.rows)
133
133
  markdown_res += f"{table_md}\n\n"
134
134
  # 添加表格描述
135
135
  if node.element.description:
@@ -168,28 +168,25 @@ class StandardDomTree(BaseModel):
168
168
  quoted_lines = ['> ' + line for line in lines]
169
169
  return '\n'.join(quoted_lines)
170
170
 
171
- def _list_to_html_table(self, rows: List[StandardRow]) -> str:
172
- """将表格行转换为HTML表格"""
171
+ def _list_to_markdown_table(self, rows: List[StandardRow]) -> str:
172
+ """将表格行转换为 markdown 表格格式"""
173
173
  if not rows:
174
174
  return ""
175
175
 
176
- html_text = "<table>"
176
+ markdown_table = ""
177
+
178
+ # 添加表头
179
+ if rows:
180
+ header_cells = [cell.text or "" for cell in rows[0].cells]
181
+ markdown_table += "| " + " | ".join(header_cells) + " |\n"
182
+ markdown_table += "| " + " | ".join(["---"] * len(header_cells)) + " |\n"
183
+
184
+ # 添加数据行
177
185
  for row in rows:
178
- html_text += "<tr>"
179
- for cell in row.cells:
180
- # 从path中提取rowspan和colspan信息
181
- if len(cell.path) >= 4:
182
- start_row, end_row, start_col, end_col = cell.path[:4]
183
- rowspan = end_row - start_row + 1
184
- colspan = end_col - start_col + 1
185
- else:
186
- rowspan = colspan = 1
186
+ cells = [cell.text or "" for cell in row.cells]
187
+ markdown_table += "| " + " | ".join(cells) + " |\n"
187
188
 
188
- cell_text = cell.text or ""
189
- html_text += f"<td rowspan='{rowspan}' colspan='{colspan}'>{cell_text}</td>"
190
- html_text += "</tr>"
191
- html_text += "</table>"
192
- return html_text
189
+ return markdown_table
193
190
 
194
191
  @classmethod
195
192
  def from_domtree_dict(cls, domtree: dict, file_info):
@@ -306,18 +303,16 @@ class StandardDomTree(BaseModel):
306
303
  # 检查前一个节点
307
304
  if i > 0:
308
305
  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
306
+ # 找到对应类型的前一个兄弟节点,合并节点
307
+ merged = ( prev_sibling.element and prev_sibling.element.type == target_type and
308
+ cls._merge_nodes(prev_sibling, current, target_type))
313
309
 
314
310
  # 如果没有与前一个节点合并,检查后一个节点
315
311
  if not merged and i < len(node.children) - 1:
316
312
  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
313
+ # 找到对应类型的后一个兄弟节点,合并节点
314
+ merged = (next_sibling.element and next_sibling.element.type == target_type and
315
+ cls._merge_nodes(next_sibling, current, target_type))
321
316
 
322
317
  # 如果没有找到对应类型的兄弟节点,将当前节点类型改为 Text
323
318
  if not merged:
@@ -348,23 +343,25 @@ class StandardDomTree(BaseModel):
348
343
  Returns:
349
344
  bool: 是否成功合并
350
345
  """
351
- if node_type == 'Figure' and isinstance(target_node.element, StandardImageElement):
352
- # FigureName 的文本作为 Figure 的 name
353
- target_node.element.name = source_node.element.text
354
- # 更新 tokens 计数
355
- target_node.tokens += source_node.tokens
356
- # 将 FigureName 的位置添加到 Figure 中
357
- 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
346
+ # 定义节点类型与元素类型的映射
347
+ type_element_mapping = {
348
+ 'Figure': StandardImageElement,
349
+ 'Table': StandardTableElement
350
+ }
351
+
352
+ can_merge = (node_type in type_element_mapping and
353
+ isinstance(target_node.element, type_element_mapping[node_type]))
354
+
355
+ # 检查节点类型是否支持且目标节点元素类型匹配
356
+ if can_merge:
357
+ # 将源节点的文本作为目标节点的 name
361
358
  target_node.element.name = source_node.element.text
362
359
  # 更新 tokens 计数
363
360
  target_node.tokens += source_node.tokens
364
- # 将 Table 的位置添加到 Figure 中
361
+ # 将源节点的位置添加到目标节点中
365
362
  target_node.element.positions += source_node.element.positions
366
- return True
367
- return False
363
+
364
+ return can_merge
368
365
 
369
366
  @classmethod
370
367
  def _from_domtree_node_to_base_info(cls, node: dict) -> Optional[StandardNode]:
@@ -492,17 +489,17 @@ class StandardDomTree(BaseModel):
492
489
  return standard_node
493
490
 
494
491
  @classmethod
495
- def count_tokens(cls, text: str, model: str = "gpt-4") -> int:
492
+ def count_tokens(cls, text: str) -> int:
496
493
  """
497
494
  计算文本的token数量
498
495
 
499
496
  Args:
500
497
  text: 要计算的文本
501
- model: 使用的模型名称,默认为gpt-4
502
498
 
503
499
  Returns:
504
500
  int: token数量
505
501
  """
502
+ model = "gpt-4" # 使用模型默认为gpt-4
506
503
  if not text:
507
504
  return 0
508
505
  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.1
4
4
  Summary: client for openapi service.
5
5
  Home-page:
6
6
  Author: ['tangxiaolong', 'fanqiangwei', 'zhangxiaojia', 'liumin', 'wangyukun']
@@ -12,6 +12,7 @@ License-File: LICENSE
12
12
  Requires-Dist: httpx<=0.26.0,>=0.10.0
13
13
  Requires-Dist: Werkzeug==3.0.1
14
14
  Requires-Dist: tiktoken>=0.5.0
15
+ Requires-Dist: pydantic==2.11.7
15
16
  Dynamic: author
16
17
  Dynamic: classifier
17
18
  Dynamic: description
@@ -1,3 +1,4 @@
1
1
  httpx<=0.26.0,>=0.10.0
2
2
  Werkzeug==3.0.1
3
3
  tiktoken>=0.5.0
4
+ pydantic==2.11.7
File without changes