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:
|
## Output format:
|
||||||
Return ONLY a valid JSON object, no other text.
|
Return ONLY a valid JSON object, no other text.
|
||||||
For violation: {{"invalid": "true"}}
|
For violation: {{"invalid": true}}
|
||||||
For safe content: {{"invalid": "false"}}
|
For safe content: {{"invalid": false}}
|
||||||
|
|
||||||
## Reference examples:
|
## Reference examples:
|
||||||
{examples}
|
{examples}
|
||||||
@@ -42,7 +42,7 @@ class ReviewAgent:
|
|||||||
base_url=os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com"),
|
base_url=os.getenv("DEEPSEEK_BASE_URL", "https://api.deepseek.com"),
|
||||||
)
|
)
|
||||||
self.rag = RAGStore()
|
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.temperature = float(os.getenv("DEEPSEEK_TEMPERATURE", "0.0"))
|
||||||
self.max_tokens = int(os.getenv("DEEPSEEK_MAX_TOKENS", "128"))
|
self.max_tokens = int(os.getenv("DEEPSEEK_MAX_TOKENS", "128"))
|
||||||
|
|
||||||
@@ -68,7 +68,7 @@ class ReviewAgent:
|
|||||||
)
|
)
|
||||||
raw = response.choices[0].message.content.strip()
|
raw = response.choices[0].message.content.strip()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return {"invalid": "false", "error": "api_error", "detail": str(e)}
|
return {"invalid": "true", "error": "api_error", "detail": str(e)}
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = json.loads(raw)
|
result = json.loads(raw)
|
||||||
@@ -77,8 +77,8 @@ class ReviewAgent:
|
|||||||
if '"invalid"' in raw_lower and 'true' in raw_lower:
|
if '"invalid"' in raw_lower and 'true' in raw_lower:
|
||||||
result = {"invalid": "true"}
|
result = {"invalid": "true"}
|
||||||
elif '"invalid"' in raw_lower and 'false' in raw_lower:
|
elif '"invalid"' in raw_lower and 'false' in raw_lower:
|
||||||
result = {"invalid": "false"}
|
result = {"invalid": "true"}
|
||||||
else:
|
else:
|
||||||
result = {"invalid": "false", "error": "parse_failed", "raw": raw}
|
result = {"invalid": "true", "error": "parse_failed", "raw": raw}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
cd "$(dirname "$0")" || exit
|
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:
|
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
||||||
resp_data = resp.read().decode("utf-8")
|
resp_data = resp.read().decode("utf-8")
|
||||||
data = json.loads(resp_data)
|
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:
|
except urllib.error.HTTPError as e:
|
||||||
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
# 服务端返回 4xx/5xx 错误时,尝试解析错误正文
|
||||||
error_body = e.read().decode("utf-8")
|
error_body = e.read().decode("utf-8")
|
||||||
@@ -197,8 +201,9 @@ def add_note():
|
|||||||
|
|
||||||
|
|
||||||
# 内容审查
|
# 内容审查
|
||||||
review = review_content(title + '\n\n' + content, 10)
|
review = review_content(title + '\n' + content, 10)
|
||||||
if not review:
|
if True != review:
|
||||||
|
#return jsonify({'error': 'review failed', 'data': review}), 400
|
||||||
return jsonify({'error': 'review failed'}), 400
|
return jsonify({'error': 'review failed'}), 400
|
||||||
|
|
||||||
insert_payload = {
|
insert_payload = {
|
||||||
@@ -351,6 +356,29 @@ def update_note():
|
|||||||
return jsonify({"error": "Invalid param"}), 400
|
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():
|
#with app.app_context():
|
||||||
|
|
||||||
# note = Note.query.get(id)
|
# note = Note.query.get(id)
|
||||||
|
|||||||
Reference in new issue
Block a user