Spaces:
Sleeping
Sleeping
Yukuiii
commited on
Commit
·
8b4026f
1
Parent(s):
8e5d415
fix: 回退版本
Browse files- Dockerfile +1 -13
- app.py +8 -24
Dockerfile
CHANGED
|
@@ -18,9 +18,6 @@ FROM python:3.10-slim
|
|
| 18 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 19 |
ENV PYTHONUNBUFFERED=1
|
| 20 |
|
| 21 |
-
# 创建专用用户和组
|
| 22 |
-
RUN groupadd -r appuser && \
|
| 23 |
-
useradd -r -g appuser appuser
|
| 24 |
|
| 25 |
WORKDIR /app
|
| 26 |
|
|
@@ -30,16 +27,7 @@ COPY --from=builder /requirements_freeze.txt .
|
|
| 30 |
# 安装依赖
|
| 31 |
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements_freeze.txt
|
| 32 |
|
| 33 |
-
|
| 34 |
-
COPY --chown=appuser:appuser . .
|
| 35 |
-
|
| 36 |
-
# 创建可写目录并设置权限
|
| 37 |
-
RUN mkdir -p /app/data && \
|
| 38 |
-
chown -R appuser:appuser /app && \
|
| 39 |
-
chmod 775 -R /app/data # 重点修改这里,添加递归权限设置
|
| 40 |
-
|
| 41 |
-
# 切换用户
|
| 42 |
-
USER appuser
|
| 43 |
|
| 44 |
EXPOSE 7860
|
| 45 |
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
|
|
|
|
| 18 |
ENV PYTHONDONTWRITEBYTECODE=1
|
| 19 |
ENV PYTHONUNBUFFERED=1
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
WORKDIR /app
|
| 23 |
|
|
|
|
| 27 |
# 安装依赖
|
| 28 |
RUN pip install --upgrade pip && pip install --no-cache-dir -r requirements_freeze.txt
|
| 29 |
|
| 30 |
+
COPY . .
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
EXPOSE 7860
|
| 33 |
CMD ["gunicorn", "-w", "4", "-b", "0.0.0.0:7860", "app:app"]
|
app.py
CHANGED
|
@@ -52,24 +52,8 @@ active_accounts = set()
|
|
| 52 |
# -------------------------------------------------------------------
|
| 53 |
# (1) 配置文件的读写函数
|
| 54 |
# -------------------------------------------------------------------
|
| 55 |
-
current_dir = os.path.dirname(os.path.abspath(__file__))
|
| 56 |
-
|
| 57 |
-
# 确保目录存在且可写
|
| 58 |
-
DATA_DIR = os.path.join(current_dir, "data")
|
| 59 |
-
if not os.path.exists(DATA_DIR):
|
| 60 |
-
os.makedirs(DATA_DIR, exist_ok=True, mode=0o775) # 显式设置目录权限
|
| 61 |
-
|
| 62 |
-
CONFIG_PATH = os.path.join(DATA_DIR, "config.json")
|
| 63 |
-
|
| 64 |
-
# 首次运行时创建配置文件
|
| 65 |
-
if not os.path.exists(CONFIG_PATH):
|
| 66 |
-
try:
|
| 67 |
-
with open(CONFIG_PATH, "w") as f:
|
| 68 |
-
json.dump({"keys": [], "accounts": []}, f)
|
| 69 |
-
os.chmod(CONFIG_PATH, 0o664) # 显式设置文件权限
|
| 70 |
-
except Exception as e:
|
| 71 |
-
app.logger.error(f"初始化配置文件失败: {e}")
|
| 72 |
-
|
| 73 |
def load_config():
|
| 74 |
"""从 config.json 加载配置,出错则返回空 dict"""
|
| 75 |
try:
|
|
@@ -482,8 +466,8 @@ def list_models():
|
|
| 482 |
def messages_prepare(messages: list) -> str:
|
| 483 |
"""
|
| 484 |
处理消息列表,合并连续相同角色的消息,并添加角色标签:
|
| 485 |
-
- 对于 assistant 消息,加上 <|Assistant|> 前缀及 结束标签;
|
| 486 |
-
- 对于 user/system 消息(除第一条外)加上
|
| 487 |
- 如果消息 content 为数组,则提取其中 type 为 "text" 的部分;
|
| 488 |
- 最后移除 markdown 图片格式的内容。
|
| 489 |
"""
|
|
@@ -512,17 +496,17 @@ def messages_prepare(messages: list) -> str:
|
|
| 512 |
role = block["role"]
|
| 513 |
text = block["text"]
|
| 514 |
if role == "assistant":
|
| 515 |
-
parts.append(f"<|Assistant|>{text}")
|
| 516 |
elif role in ("user", "system"):
|
| 517 |
if idx > 0:
|
| 518 |
-
parts.append(f"
|
| 519 |
else:
|
| 520 |
parts.append(text)
|
| 521 |
else:
|
| 522 |
parts.append(text)
|
| 523 |
final_prompt = "".join(parts)
|
| 524 |
# 移除 markdown 图片格式:
|
| 525 |
-
final_prompt = re.sub(r"
|
| 526 |
return final_prompt
|
| 527 |
|
| 528 |
# -------------------------------------------------------------------
|
|
@@ -558,7 +542,7 @@ def chat_completions():
|
|
| 558 |
if not model or not messages:
|
| 559 |
return jsonify({"error": "Request must include 'model' and 'messages'."}), 400
|
| 560 |
|
| 561 |
-
#
|
| 562 |
model_lower = model.lower()
|
| 563 |
if model_lower in ["deepseek-v3", "deepseek-chat"]:
|
| 564 |
thinking_enabled = False
|
|
|
|
| 52 |
# -------------------------------------------------------------------
|
| 53 |
# (1) 配置文件的读写函数
|
| 54 |
# -------------------------------------------------------------------
|
| 55 |
+
current_dir = os.path.dirname(os.path.abspath(__file__)) # 新增路径计算
|
| 56 |
+
CONFIG_PATH = os.path.join(current_dir, "config.json") # 修改为绝对路径
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
def load_config():
|
| 58 |
"""从 config.json 加载配置,出错则返回空 dict"""
|
| 59 |
try:
|
|
|
|
| 466 |
def messages_prepare(messages: list) -> str:
|
| 467 |
"""
|
| 468 |
处理消息列表,合并连续相同角色的消息,并添加角色标签:
|
| 469 |
+
- 对于 assistant 消息,加上 <|Assistant|> 前缀及 <|end▁of▁sentence|> 结束标签;
|
| 470 |
+
- 对于 user/system 消息(除第一条外)加上 <|User|> 前缀;
|
| 471 |
- 如果消息 content 为数组,则提取其中 type 为 "text" 的部分;
|
| 472 |
- 最后移除 markdown 图片格式的内容。
|
| 473 |
"""
|
|
|
|
| 496 |
role = block["role"]
|
| 497 |
text = block["text"]
|
| 498 |
if role == "assistant":
|
| 499 |
+
parts.append(f"<|Assistant|>{text}<|end▁of▁sentence|>")
|
| 500 |
elif role in ("user", "system"):
|
| 501 |
if idx > 0:
|
| 502 |
+
parts.append(f"<|User|>{text}")
|
| 503 |
else:
|
| 504 |
parts.append(text)
|
| 505 |
else:
|
| 506 |
parts.append(text)
|
| 507 |
final_prompt = "".join(parts)
|
| 508 |
# 移除 markdown 图片格式:
|
| 509 |
+
final_prompt = re.sub(r"!.+.+", "", final_prompt)
|
| 510 |
return final_prompt
|
| 511 |
|
| 512 |
# -------------------------------------------------------------------
|
|
|
|
| 542 |
if not model or not messages:
|
| 543 |
return jsonify({"error": "Request must include 'model' and 'messages'."}), 400
|
| 544 |
|
| 545 |
+
# 判断是否启用“思考”功能(这里根据模型名称判断)
|
| 546 |
model_lower = model.lower()
|
| 547 |
if model_lower in ["deepseek-v3", "deepseek-chat"]:
|
| 548 |
thinking_enabled = False
|