bella-openapi 1.0.2.5__py3-none-any.whl → 1.0.3.1__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 +2 -13
- bella_openapi/entity/standard_domtree.py +38 -41
- {bella_openapi-1.0.2.5.dist-info → bella_openapi-1.0.3.1.dist-info}/METADATA +2 -1
- {bella_openapi-1.0.2.5.dist-info → bella_openapi-1.0.3.1.dist-info}/RECORD +7 -7
- {bella_openapi-1.0.2.5.dist-info → bella_openapi-1.0.3.1.dist-info}/WHEEL +0 -0
- {bella_openapi-1.0.2.5.dist-info → bella_openapi-1.0.3.1.dist-info}/licenses/LICENSE +0 -0
- {bella_openapi-1.0.2.5.dist-info → bella_openapi-1.0.3.1.dist-info}/top_level.txt +0 -0
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
|
-
|
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.
|
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
|
172
|
-
"""将表格行转换为
|
171
|
+
def _list_to_markdown_table(self, rows: List[StandardRow]) -> str:
|
172
|
+
"""将表格行转换为 markdown 表格格式"""
|
173
173
|
if not rows:
|
174
174
|
return ""
|
175
175
|
|
176
|
-
|
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
|
-
|
179
|
-
|
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
|
-
|
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
|
-
|
310
|
-
|
311
|
-
|
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
|
-
|
318
|
-
|
319
|
-
|
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
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
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
|
-
#
|
361
|
+
# 将源节点的位置添加到目标节点中
|
365
362
|
target_node.element.positions += source_node.element.positions
|
366
|
-
|
367
|
-
return
|
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
|
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.
|
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,4 +1,4 @@
|
|
1
|
-
bella_openapi/__init__.py,sha256=
|
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=
|
17
|
+
bella_openapi/entity/standard_domtree.py,sha256=yJ2FN3xwhT_SPbQSuvMlIvESmjNdQgcu2hzalDq9Gcs,20099
|
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.
|
21
|
-
bella_openapi-1.0.
|
22
|
-
bella_openapi-1.0.
|
23
|
-
bella_openapi-1.0.
|
24
|
-
bella_openapi-1.0.
|
20
|
+
bella_openapi-1.0.3.1.dist-info/licenses/LICENSE,sha256=O-0zMbcEi6wXz1DiSdVgzMlQjJcNqNe5KDv08uYzqR0,1055
|
21
|
+
bella_openapi-1.0.3.1.dist-info/METADATA,sha256=9td_a-VIyt3wOFv03zo5b_reHr8qLleSxGM9wJflCno,9409
|
22
|
+
bella_openapi-1.0.3.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
23
|
+
bella_openapi-1.0.3.1.dist-info/top_level.txt,sha256=EZuq3F6tKeF-vmZQi6_S2XzmES7SPW7HAbGN1Uv9vN8,14
|
24
|
+
bella_openapi-1.0.3.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|