|
|
|
@ -10,6 +10,8 @@ import markdown_to_json
|
|
|
|
|
import json
|
|
|
|
|
import asyncio
|
|
|
|
|
|
|
|
|
|
from AiService.MarkdownToJsonConverter import MarkdownToJsonConverter
|
|
|
|
|
|
|
|
|
|
# 阿里云中用来调用 deepseek v3 的密钥
|
|
|
|
|
MODEL_API_KEY = "sk-01d13a39e09844038322108ecdbd1bbc"
|
|
|
|
|
MODEL_NAME = "qwen-plus"
|
|
|
|
@ -143,37 +145,13 @@ def expand_text_with_ai(json_dict):
|
|
|
|
|
return json_dict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def ConvertMarkdownToJson(markdown_content):
|
|
|
|
|
"""
|
|
|
|
|
生成一个 AsyncIterable,逐行返回 JSON 字符串
|
|
|
|
|
"""
|
|
|
|
|
# 将 Markdown 转换为字典
|
|
|
|
|
json_dict = markdown_to_dict(markdown_content)
|
|
|
|
|
|
|
|
|
|
# 调用 AI 扩写每个有 title 属性的节点
|
|
|
|
|
json_dict = expand_text_with_ai(json_dict)
|
|
|
|
|
|
|
|
|
|
# 提取一级目录
|
|
|
|
|
level1_json = extract_level1(json_dict)
|
|
|
|
|
print(level1_json)
|
|
|
|
|
for item in level1_json:
|
|
|
|
|
yield json.dumps(item, ensure_ascii=False)
|
|
|
|
|
await asyncio.sleep(0.5) # 控制逐行输出的速度
|
|
|
|
|
|
|
|
|
|
# 生成目录部分
|
|
|
|
|
contents_json = extract_contents(json_dict)
|
|
|
|
|
print(contents_json)
|
|
|
|
|
yield json.dumps(contents_json, ensure_ascii=False)
|
|
|
|
|
await asyncio.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
# 提取二级目录及其三级目录内容
|
|
|
|
|
level2_and_level3_json = extract_level2_and_level3(json_dict)
|
|
|
|
|
print(level2_and_level3_json)
|
|
|
|
|
for item in level2_and_level3_json:
|
|
|
|
|
yield json.dumps(item, ensure_ascii=False)
|
|
|
|
|
await asyncio.sleep(0.5)
|
|
|
|
|
|
|
|
|
|
# 添加结束标记
|
|
|
|
|
async def convertMarkdownToJson(markdown_content):
|
|
|
|
|
# 创建转换器实例
|
|
|
|
|
converter = MarkdownToJsonConverter(client)
|
|
|
|
|
# 转换 Markdown 为 JSON
|
|
|
|
|
async for item in converter.convert_markdown_to_json(markdown_content):
|
|
|
|
|
yield item
|
|
|
|
|
# 添加结束标记
|
|
|
|
|
yield '{"type": "end" }'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -265,7 +243,7 @@ async def aippt_outline(
|
|
|
|
|
@app.post("/api/tools/aippt") # 修改为 POST 方法
|
|
|
|
|
async def aippt(content: str = Body(..., embed=True, description="Markdown 内容")): # 使用 Body 接收请求体参数
|
|
|
|
|
return StreamingResponse(
|
|
|
|
|
ConvertMarkdownToJson(content), # 传入 content
|
|
|
|
|
convertMarkdownToJson(content), # 传入 content
|
|
|
|
|
media_type="text/plain", # 使用 text/plain 格式
|
|
|
|
|
headers={
|
|
|
|
|
"Cache-Control": "no-cache",
|
|
|
|
@ -279,26 +257,16 @@ async def aippt(content: str = Body(..., embed=True, description="Markdown 内
|
|
|
|
|
|
|
|
|
|
# 运行应用
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
# # 获取本机所有 IPv4 地址
|
|
|
|
|
# ips = get_local_ips()
|
|
|
|
|
# if not ips:
|
|
|
|
|
# print("无法获取本机 IP 地址,使用默认地址 127.0.0.1")
|
|
|
|
|
# ips = ["127.0.0.1"]
|
|
|
|
|
#
|
|
|
|
|
# # 打印所有 IP 地址
|
|
|
|
|
# print("服务将在以下 IP 地址上运行:")
|
|
|
|
|
# for ip in ips:
|
|
|
|
|
# print(f"http://{ip}:5173")
|
|
|
|
|
#
|
|
|
|
|
# # 启动 FastAPI 应用,绑定到所有 IP 地址
|
|
|
|
|
# uvicorn.run(app, host="0.0.0.0", port=5173)
|
|
|
|
|
|
|
|
|
|
# 读取Sample.md
|
|
|
|
|
with open("Sample.md", "r", encoding="utf-8") as f:
|
|
|
|
|
markdown_content = f.read()
|
|
|
|
|
json_dict = markdown_to_dict(markdown_content)
|
|
|
|
|
|
|
|
|
|
# 调用 AI 扩写每个有 title 属性的节点
|
|
|
|
|
json_dict = expand_text_with_ai(json_dict)
|
|
|
|
|
|
|
|
|
|
print(json_dict)
|
|
|
|
|
# 获取本机所有 IPv4 地址
|
|
|
|
|
ips = get_local_ips()
|
|
|
|
|
if not ips:
|
|
|
|
|
print("无法获取本机 IP 地址,使用默认地址 127.0.0.1")
|
|
|
|
|
ips = ["127.0.0.1"]
|
|
|
|
|
|
|
|
|
|
# 打印所有 IP 地址
|
|
|
|
|
print("服务将在以下 IP 地址上运行:")
|
|
|
|
|
for ip in ips:
|
|
|
|
|
print(f"http://{ip}:5173")
|
|
|
|
|
|
|
|
|
|
# 启动 FastAPI 应用,绑定到所有 IP 地址
|
|
|
|
|
uvicorn.run(app, host="0.0.0.0", port=5173)
|