fixbug
This commit is contained in:
1 parent
3d8cf52503
commit
c028e46d00
3 files changed
+38
-10
No files matched your search
@@ -20,8 +20,8 @@ SYSTEM_PROMPT = """You are a strict content moderation AI. Your task is to revie
|
||||
|
||||
## Output format:
|
||||
Return ONLY a valid JSON object, no other text.
|
||||
For violation: {{"invalid": "true"}}
|
||||
For safe content: {{"invalid": "false"}}
|
||||
For violation: {{"invalid": true}}
|
||||
For safe content: {{"invalid": false}}
|
||||
|
||||
## Reference examples:
|
||||
{examples}
|
||||
@@ -42,7 +42,7 @@ class ReviewAgent:
|
||||
base_url=os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com"),
|
||||
)
|
||||
self.rag = RAGStore()
|
||||
self.model = os.getenv("DEEPSEEK_MODEL", "deepseek-chat")
|
||||
self.model = os.getenv("DEEPSEEK_MODEL", "deepseek-v4-flash")
|
||||
self.temperature = float(os.getenv("DEEPSEEK_TEMPERATURE", "0.0"))
|
||||
self.max_tokens = int(os.getenv("DEEPSEEK_MAX_TOKENS", "128"))
|
||||
|
||||
@@ -68,7 +68,7 @@ class ReviewAgent:
|
||||
)
|
||||
raw = response.choices[0].message.content.strip()
|
||||
except Exception as e:
|
||||
return {"invalid": "false", "error": "api_error", "detail": str(e)}
|
||||
return {"invalid": "true", "error": "api_error", "detail": str(e)}
|
||||
|
||||
try:
|
||||
result = json.loads(raw)
|
||||
@@ -77,8 +77,8 @@ class ReviewAgent:
|
||||
if '"invalid"' in raw_lower and 'true' in raw_lower:
|
||||
result = {"invalid": "true"}
|
||||
elif '"invalid"' in raw_lower and 'false' in raw_lower:
|
||||
result = {"invalid": "false"}
|
||||
result = {"invalid": "true"}
|
||||
else:
|
||||
result = {"invalid": "false", "error": "parse_failed", "raw": raw}
|
||||
result = {"invalid": "true", "error": "parse_failed", "raw": raw}
|
||||
|
||||
return result
|
||||
+1
-1
@@ -1,3 +1,3 @@
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")" || exit
|
||||
python3 captcha_service.py
|
||||
exec python3 captcha_service.py
|
||||
+31
-3
@@ -100,7 +100,11 @@ def review_content(content: str, timeout: int = 10) -> Dict[str, Any]:
|
||||
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||
resp_data = resp.read().decode("utf-8")
|
||||
data = json.loads(resp_data)
|
||||
return not data['invalid']
|
||||
invalid: bool = data['invalid']
|
||||
return invalid == False
|
||||
#invalid = data
|
||||
#return invalid
|
||||
|
||||
except urllib.error.HTTPError as e:
|
||||
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
||||
error_body = e.read().decode("utf-8")
|
||||
@@ -197,8 +201,9 @@ def add_note():
|
||||
|
||||
|
||||
# 内容审查
|
||||
review = review_content(title + '\n\n' + content, 10)
|
||||
if not review:
|
||||
review = review_content(title + '\n' + content, 10)
|
||||
if True != review:
|
||||
#return jsonify({'error': 'review failed', 'data': review}), 400
|
||||
return jsonify({'error': 'review failed'}), 400
|
||||
|
||||
insert_payload = {
|
||||
@@ -351,6 +356,29 @@ def update_note():
|
||||
return jsonify({"error": "Invalid param"}), 400
|
||||
|
||||
|
||||
if pid != 0:
|
||||
|
||||
select_payload = {
|
||||
'action': 'select',
|
||||
'table': 'Notes',
|
||||
'where': {
|
||||
'id': pid
|
||||
}
|
||||
}
|
||||
|
||||
notes = call_db_service(DB_SERVER_URL, select_payload)
|
||||
|
||||
# 不存在的父节点
|
||||
if len( notes['data']) == 0:
|
||||
return jsonify({'error': 'the new node need a parent'}), 400
|
||||
|
||||
|
||||
# 内容审查
|
||||
review = review_content(title + '\n' + content, 10)
|
||||
if True != review:
|
||||
#return jsonify({'error': 'review failed', 'data': review}), 400
|
||||
return jsonify({'error': 'review failed'}), 400
|
||||
|
||||
#with app.app_context():
|
||||
|
||||
# note = Note.query.get(id)
|
||||
|
||||
Reference in new issue
Block a user