bella-openapi 1.0.3.1__tar.gz → 1.0.3.2__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.3.1/src/bella_openapi.egg-info → bella_openapi-1.0.3.2}/PKG-INFO +5 -2
  2. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/README.md +3 -1
  3. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/setup.py +3 -2
  4. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/entity/standard_domtree.py +67 -35
  5. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2/src/bella_openapi.egg-info}/PKG-INFO +5 -2
  6. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi.egg-info/requires.txt +2 -1
  7. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/LICENSE +0 -0
  8. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/setup.cfg +0 -0
  9. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/__init__.py +0 -0
  10. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/auth_billing.py +0 -0
  11. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/authorize.py +0 -0
  12. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/bella_trace/__init__.py +0 -0
  13. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/bella_trace/_context.py +0 -0
  14. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/bella_trace/fastapi_interceptor.py +0 -0
  15. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/bella_trace/record_log.py +0 -0
  16. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/bella_trace/trace_requests.py +0 -0
  17. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/config.py +0 -0
  18. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/console/__init__.py +0 -0
  19. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/console/models.py +0 -0
  20. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/entity/__init__.py +0 -0
  21. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/exception.py +0 -0
  22. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/log.py +0 -0
  23. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/middleware/__init__.py +0 -0
  24. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/middleware/context_middleware.py +0 -0
  25. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/openapi_contexvar.py +0 -0
  26. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi/schema.py +0 -0
  27. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi.egg-info/SOURCES.txt +0 -0
  28. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi.egg-info/dependency_links.txt +0 -0
  29. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/src/bella_openapi.egg-info/not-zip-safe +0 -0
  30. {bella_openapi-1.0.3.1 → bella_openapi-1.0.3.2}/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.3.1
3
+ Version: 1.0.3.2
4
4
  Summary: client for openapi service.
5
5
  Home-page:
6
6
  Author: ['tangxiaolong', 'fanqiangwei', 'zhangxiaojia', 'liumin', 'wangyukun']
@@ -12,7 +12,8 @@ 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
+ Requires-Dist: pydantic==1.10.14
16
+ Requires-Dist: fastapi==0.110.0
16
17
  Dynamic: author
17
18
  Dynamic: classifier
18
19
  Dynamic: description
@@ -260,3 +261,5 @@ get接口地址:/v1/openapi/log/{requestId}
260
261
  * rename 包名
261
262
  * 1.0.2
262
263
  * 修复bug
264
+ * 1.0.3
265
+ * 新增standard domtree
@@ -235,4 +235,6 @@ get接口地址:/v1/openapi/log/{requestId}
235
235
  * 1.0.1
236
236
  * rename 包名
237
237
  * 1.0.2
238
- * 修复bug
238
+ * 修复bug
239
+ * 1.0.3
240
+ * 新增standard domtree
@@ -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.3.1"
6
+ __version__ = "1.0.3.2"
7
7
  __author__ = ["tangxiaolong", "fanqiangwei", "zhangxiaojia", 'liumin', 'wangyukun']
8
8
  __email__ = ''
9
9
  readme_path = 'README.md'
@@ -17,7 +17,8 @@ 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
+ 'pydantic==1.10.14',
21
+ 'fastapi==0.110.0'
21
22
  ],
22
23
  url='',
23
24
  author=__author__,
@@ -9,7 +9,7 @@ StandardDomTree - 新的DOM树协议定义
9
9
  """
10
10
 
11
11
  from typing import List, Optional, Literal, Any, Union
12
- from pydantic import BaseModel, Field
12
+ from pydantic import BaseModel, Field, root_validator
13
13
  import tiktoken
14
14
 
15
15
  # 布局类型映射表:将旧解析器的布局类型映射到新的标准类型
@@ -92,6 +92,23 @@ class StandardNode(BaseModel):
92
92
  path: Optional[List[int]] = Field(default_factory=list) # 编号的层级信息,例如:1.2.1
93
93
  element: Optional[Union[StandardElement, StandardImageElement, StandardTableElement]] = None # 元素信息,当前节点的元素详情
94
94
  children: Optional[List["StandardNode"]] = Field(default_factory=list) # 子节点信息,当前节点的所有子节点
95
+
96
+ @root_validator(pre=True)
97
+ def parse_element(cls, values):
98
+ """根据element的type字段正确实例化element"""
99
+ if 'element' in values and values['element'] is not None:
100
+ element_data = values['element']
101
+ # 只有当element是字典时才需要转换,如果已经是正确的实例则保持不变
102
+ if isinstance(element_data, dict):
103
+ element_type = element_data.get('type', '')
104
+ if element_type == 'Figure':
105
+ values['element'] = StandardImageElement(**element_data)
106
+ elif element_type == 'Table':
107
+ values['element'] = StandardTableElement(**element_data)
108
+ else:
109
+ values['element'] = StandardElement(**element_data)
110
+ # 如果element已经是正确的实例类型,则保持不变
111
+ return values
95
112
 
96
113
 
97
114
  class StandardDomTree(BaseModel):
@@ -129,7 +146,7 @@ class StandardDomTree(BaseModel):
129
146
  # 添加表格名称
130
147
  if node.element.name:
131
148
  markdown_res += f"**{node.element.name}**\n\n"
132
- table_md = self._list_to_markdown_table(node.element.rows)
149
+ table_md = self._list_to_html_table(node.element.rows)
133
150
  markdown_res += f"{table_md}\n\n"
134
151
  # 添加表格描述
135
152
  if node.element.description:
@@ -168,25 +185,28 @@ class StandardDomTree(BaseModel):
168
185
  quoted_lines = ['> ' + line for line in lines]
169
186
  return '\n'.join(quoted_lines)
170
187
 
171
- def _list_to_markdown_table(self, rows: List[StandardRow]) -> str:
172
- """将表格行转换为 markdown 表格格式"""
188
+ def _list_to_html_table(self, rows: List[StandardRow]) -> str:
189
+ """将表格行转换为HTML表格"""
173
190
  if not rows:
174
191
  return ""
175
192
 
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
- # 添加数据行
193
+ html_text = "<table>"
185
194
  for row in rows:
186
- cells = [cell.text or "" for cell in row.cells]
187
- markdown_table += "| " + " | ".join(cells) + " |\n"
195
+ html_text += "<tr>"
196
+ for cell in row.cells:
197
+ # 从path中提取rowspan和colspan信息
198
+ if len(cell.path) >= 4:
199
+ start_row, end_row, start_col, end_col = cell.path[:4]
200
+ rowspan = end_row - start_row + 1
201
+ colspan = end_col - start_col + 1
202
+ else:
203
+ rowspan = colspan = 1
188
204
 
189
- return markdown_table
205
+ cell_text = cell.text or ""
206
+ html_text += f"<td rowspan='{rowspan}' colspan='{colspan}'>{cell_text}</td>"
207
+ html_text += "</tr>"
208
+ html_text += "</table>"
209
+ return html_text
190
210
 
191
211
  @classmethod
192
212
  def from_domtree_dict(cls, domtree: dict, file_info):
@@ -397,19 +417,22 @@ class StandardDomTree(BaseModel):
397
417
  url=element['image_link']
398
418
  )
399
419
 
400
- # 创建 StandardNode
401
- standard_node = StandardNode(
420
+ # 创建StandardImageElement实例
421
+ image_element = StandardImageElement(
422
+ type=element_type,
423
+ positions=positions,
424
+ name="",
425
+ description="",
426
+ text=text,
427
+ image=image,
428
+ )
429
+
430
+ # 使用construct方法跳过validator,保持正确的element类型
431
+ standard_node = StandardNode.construct(
402
432
  summary="",
403
433
  tokens=0, # 先设置为 0,后面再计算
404
434
  path=[], # 初始化为空列表,后续再计算
405
- element=StandardImageElement(
406
- type=element_type,
407
- positions=positions,
408
- name="",
409
- description="",
410
- text=text,
411
- image=image,
412
- ),
435
+ element=image_element,
413
436
  children=[]
414
437
  )
415
438
  elif element_type == "Table":
@@ -444,17 +467,21 @@ class StandardDomTree(BaseModel):
444
467
  # 将所有单元格的文本合并,用于计算 token 数量
445
468
  text = " ".join(cell_texts)
446
469
 
447
- standard_node = StandardNode(
470
+ # 创建StandardTableElement实例
471
+ table_element = StandardTableElement(
472
+ type=element_type,
473
+ positions=positions,
474
+ name="",
475
+ description="",
476
+ rows=rows
477
+ )
478
+
479
+ # 使用construct方法跳过validator,保持正确的element类型
480
+ standard_node = StandardNode.construct(
448
481
  summary="",
449
482
  tokens=0, # 先设置为 0,后面再计算
450
483
  path=[], # 初始化为空列表,后续再计算
451
- element=StandardTableElement(
452
- type=element_type,
453
- positions=positions,
454
- name="",
455
- description="",
456
- rows=rows
457
- ),
484
+ element=table_element,
458
485
  children=[]
459
486
  )
460
487
  else:
@@ -507,4 +534,9 @@ class StandardDomTree(BaseModel):
507
534
  # 计算标记列表的长度,即标记的数量
508
535
  token_count = len(tokens)
509
536
  # 返回标记的数量
510
- return token_count
537
+ return token_count
538
+
539
+
540
+ # 更新forward references
541
+ StandardNode.update_forward_refs()
542
+ Cell.update_forward_refs()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bella-openapi
3
- Version: 1.0.3.1
3
+ Version: 1.0.3.2
4
4
  Summary: client for openapi service.
5
5
  Home-page:
6
6
  Author: ['tangxiaolong', 'fanqiangwei', 'zhangxiaojia', 'liumin', 'wangyukun']
@@ -12,7 +12,8 @@ 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
+ Requires-Dist: pydantic==1.10.14
16
+ Requires-Dist: fastapi==0.110.0
16
17
  Dynamic: author
17
18
  Dynamic: classifier
18
19
  Dynamic: description
@@ -260,3 +261,5 @@ get接口地址:/v1/openapi/log/{requestId}
260
261
  * rename 包名
261
262
  * 1.0.2
262
263
  * 修复bug
264
+ * 1.0.3
265
+ * 新增standard domtree
@@ -1,4 +1,5 @@
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
4
+ pydantic==1.10.14
5
+ fastapi==0.110.0
File without changes