展示了基于 Ollama、Postgres、Python 的完整 Agent 架构,包括 cron 定时调度、controversy gate(内容审查)和 credit gate(额度检查)的实现,适配社交媒体自动发布场景。
我们构建了一个通过 cron 定时运行、基于 Ollama 的自主 Agent。它将 voice profile 作为独立文件管理,并在发布到社交渠道之前设置了争议内容门禁和 credit 门禁。这个 Agent 兼顾安全性与表达能力,下面将详细介绍它的工作原理。
我们的技术栈由用于 LLM 推理的 Ollama、用于数据存储的 Postgres,以及将整个流程串联起来的自定义 Python 脚本组成。Agent 使用 cron 每小时运行一次,处理由其他系统生成并放入队列的语音消息。每条消息在发布到所有社交渠道之前,都要经过争议内容门禁和 credit 门禁的检查。
争议内容门禁由另一个充当分类器的模型实现。它会检查内容是否可能引发争议或造成伤害。如果存在这类风险,消息就会被移入隔离文件夹,等待审核。credit 门禁则会检查用户在 Postiz DB 中是否有足够的 credits 来发布消息。如果 credits 充足,消息就会发布到所有渠道;否则,它同样会被移入隔离区。
下面是我们代码库中 publish_to_all_channels 函数的结构:
def publish_to_all_channels(message_id: str, voice_profile: str, content: str) -> bool:
# Load the message from the queue
message = load_message_from_queue(message_id)
# Check voice profile
if not is_valid_voice_profile(voice_profile):
log(f"Invalid voice profile for message {message_id}")
move_to_quarantine(message_id)
return False
# Controversy gate: check with second model
if is_controversial(content):
log(f"Controversial content detected for message {message_id}")
move_to_quarantine(message_id)
return False
# Credit gate: check Postiz DB
if not has_sufficient_credits(message.user_id):
log(f"Insufficient credits for user {message.user_id}")
move_to_quarantine(message_id)
return False
# Publish to all channels
publish_to_twitter(content)
publish_to_telegram(content)
publish_to_mastodon(content)
log(f"Published message {message_id} successfully")
return True
这个函数依次执行 voice profile 验证、争议内容门禁和 credit 门禁。每一步都是关键检查,用来确保消息在发出之前既安全,又获得了相应授权。隔离文件夹是系统中的重要组成部分,它让我们能够审核未通过任意门禁的消息,并在适当时重新处理这些消息。
我们做出的一个关键取舍,是为争议内容门禁使用第二个模型。虽然这会增加计算开销,但也显著提高了系统的安全性。我们还选择把 voice profile 存储为独立文件,而不是嵌入消息结构中,这样便能更轻松地单独管理和更新它们。
目前,我们正在集成一个实时反馈闭环,让用户可以标记应当隔离或重新发布的消息。我们也在探索如何使用能够在 edge 端运行的轻量级模型,降低争议内容门禁的延迟。对于使用轻量级模型进行实时过滤,你怎么看?
如需采取进一步措施,你可以考虑屏蔽此人和/或举报滥用行为。