|
|
@@ -2,7 +2,7 @@ from fastapi import APIRouter, HTTPException
|
|
|
from datetime import datetime
|
|
|
|
|
|
from ..core.ark_client import config, client
|
|
|
-from ..schemas.chat import ChatMessage, ChatResponse, CircleRequest, CirclePromptConfig, HistoricalFigure, RephraseRequest, FigureUpsert
|
|
|
+from ..schemas.chat import ChatMessage, ChatResponse, CommentRequest, CirclePromptConfig, HistoricalFigure, RephraseRequest, FigureUpsert
|
|
|
from ..db.souyue_mongo import get_mblog_by_id
|
|
|
from ..db.mongo import get_circle_prompt, upsert_circle_prompt, get_all_figures, get_figure_by_id, insert_figure, update_figure, delete_figure
|
|
|
|
|
|
@@ -52,8 +52,8 @@ async def save_circle_prompt(promptcfg: CirclePromptConfig):
|
|
|
|
|
|
|
|
|
# 评论帖子的马甲机器人,无状态,支持批量对多个帖子智能回复
|
|
|
-@router.post("/airesp", response_model=ChatResponse)
|
|
|
-async def generate_circle_comment(request: CircleRequest):
|
|
|
+@router.post("/batchPostCommentBot", response_model=ChatResponse)
|
|
|
+async def generate_post_comment(request: CommentRequest):
|
|
|
doc = get_mblog_by_id(request.id)
|
|
|
if not doc:
|
|
|
raise HTTPException(status_code=404, detail="帖子不存在")
|
|
|
@@ -65,17 +65,21 @@ async def generate_circle_comment(request: CircleRequest):
|
|
|
images: list = doc.get("images") or []
|
|
|
|
|
|
product_text = f"主题:{title}\n摘要:{brief}\n发布者:{nickname}"
|
|
|
+ file_list = []
|
|
|
if images:
|
|
|
- product_text += "\n图片:\n" + "\n".join(images)
|
|
|
+ for img_url in images:
|
|
|
+ file_list.append({"type": "input_image", "file_url": img_url})
|
|
|
+
|
|
|
|
|
|
prompt_config = get_circle_prompt(app_name)
|
|
|
- prompt = _build_prompt(product_text, prompt_config)
|
|
|
+ input_text = _build_prompt(product_text, prompt_config)
|
|
|
|
|
|
+ content = file_list + [{"type": "input_text", "text": input_text}]
|
|
|
+ print(f"concat text: {content}")
|
|
|
response = client.responses.create(
|
|
|
model=config.MODEL_NAME,
|
|
|
- input=[{"role": "user", "content": prompt}],
|
|
|
- stream=False,
|
|
|
- store=False,
|
|
|
+ input=[{"role": "user", "content": content}],
|
|
|
+
|
|
|
)
|
|
|
|
|
|
message_content = ""
|