1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
| import json from openai import OpenAI
client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
AI_LABELS = [ 'model_release', 'developer_tool', 'agent_workflow', 'research_paper', 'industry_news', 'funding', 'open_source', 'tutorial' ]
NOISE_KEYWORDS = [ '娱乐', '八卦', '明星', '电商', '购物', '优惠', '促销', '抽奖', '直播带货' ]
def ai_score(title: str, summary: str) -> dict: """0-1 评分 + ai_label 分类""" if any(k in title for k in NOISE_KEYWORDS): return {'ai_score': 0, 'ai_label': 'noise', 'reason': '噪音词'}
prompt = f""" 给这篇 AI 内容打 0-1 分(重要性 + 相关性),并分类。 标题:{title} 摘要:{summary[:500]} 标签:{', '.join(AI_LABELS)} 返回 JSON:{{"ai_score": float, "ai_label": str, "ai_signals": [str], "reason": str}} """
try: resp = client.chat.completions.create( model="gpt-4o-mini", messages=[{"role": "user", "content": prompt}], response_format={"type": "json_object"} ) return json.loads(resp.choices[0].message.content) except Exception as e: return {'ai_score': 0.5, 'ai_label': 'unknown', 'reason': f'评分失败: {e}'}
|