初始化仅前端版本
This commit is contained in:
18
backend/Dockerfile
Normal file
18
backend/Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
||||
# 使用 Python 3.11 基础镜像
|
||||
FROM python:3.11-slim
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制依赖文件并安装
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
# 复制所有代码
|
||||
COPY app/ ./app/
|
||||
|
||||
# 暴露端口
|
||||
EXPOSE 8000
|
||||
|
||||
# 启动命令
|
||||
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|
||||
29
backend/app/nodes/Start.py
Normal file
29
backend/app/nodes/Start.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import base64
|
||||
from core.node_base import BaseNode
|
||||
from typing import Any, Dict
|
||||
|
||||
|
||||
class StartNode(BaseNode):
|
||||
name = "开始节点"
|
||||
inputs = {} # 没有输入参数
|
||||
outputs = {
|
||||
"text": "string", # 文本内容
|
||||
"image": "string" # 图片以 Base64 编码的字符串传递
|
||||
}
|
||||
|
||||
async def run(self, text: str = None, image: bytes = None, **kwargs) -> Dict[str, Any]:
|
||||
# 查空:文本不能为空字符串
|
||||
if not text or text.strip() == "":
|
||||
raise ValueError("文本输入不能为空")
|
||||
|
||||
# 查空:图片数据不能为空
|
||||
if image is None or len(image) == 0:
|
||||
raise ValueError("图片输入不能为空")
|
||||
|
||||
# 将图片字节转换为 Base64 字符串,便于在节点间传递
|
||||
image_base64 = base64.b64encode(image).decode('utf-8')
|
||||
|
||||
return {
|
||||
"text": text,
|
||||
"image": image_base64
|
||||
}
|
||||
0
backend/app/nodes/__init__.py
Normal file
0
backend/app/nodes/__init__.py
Normal file
56
backend/app/nodes/text_splitter_node.py
Normal file
56
backend/app/nodes/text_splitter_node.py
Normal file
@@ -0,0 +1,56 @@
|
||||
import re
|
||||
from core.node_base import BaseNode
|
||||
from typing import List, Dict, Any
|
||||
|
||||
|
||||
class TextSplitterNode(BaseNode):
|
||||
name = "文本分割节点"
|
||||
inputs = {"text": "string"}
|
||||
outputs = {
|
||||
"outline": "list", # 大纲部分列表
|
||||
"requirement": "list", # 要求部分列表
|
||||
"dialogue": "list", # 对话部分列表
|
||||
"weak_guidance": "list" # 弱指引部分列表
|
||||
}
|
||||
|
||||
async def run(self, text: str) -> Dict[str, List[str]]:
|
||||
# 正则匹配三种括号内的内容
|
||||
# 注意:此正则假设括号不嵌套,且没有转义字符
|
||||
pattern = r'\{([^{}]*)\}|\(([^()]*)\)|“([^”]*)”'
|
||||
|
||||
outline = []
|
||||
requirement = []
|
||||
dialogue = []
|
||||
weak_guidance = []
|
||||
|
||||
pos = 0
|
||||
for match in re.finditer(pattern, text):
|
||||
start, end = match.span()
|
||||
# 处理匹配前的普通文本(弱指引)
|
||||
if start > pos:
|
||||
weak_part = text[pos:start].strip()
|
||||
if weak_part:
|
||||
weak_guidance.append(weak_part)
|
||||
|
||||
# 根据捕获组确定类型
|
||||
if match.group(1) is not None: # 大括号
|
||||
outline.append(match.group(1).strip())
|
||||
elif match.group(2) is not None: # 小括号
|
||||
requirement.append(match.group(2).strip())
|
||||
elif match.group(3) is not None: # 中文引号
|
||||
dialogue.append(match.group(3).strip())
|
||||
|
||||
pos = end
|
||||
|
||||
# 处理剩余的普通文本
|
||||
if pos < len(text):
|
||||
weak_part = text[pos:].strip()
|
||||
if weak_part:
|
||||
weak_guidance.append(weak_part)
|
||||
|
||||
return {
|
||||
"outline": outline,
|
||||
"requirement": requirement,
|
||||
"dialogue": dialogue,
|
||||
"weak_guidance": weak_guidance
|
||||
}
|
||||
3
backend/requirements.txt
Normal file
3
backend/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
fastapi==0.104.1
|
||||
uvicorn[standard]==0.24.0
|
||||
python-multipart==0.0.6
|
||||
Reference in New Issue
Block a user