From 42543de895cae8641582dd3499cc3113cc4c8789 Mon Sep 17 00:00:00 2001 From: Franklin-F Date: Sat, 19 Jul 2025 16:49:58 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E8=A7=86=E9=A2=91?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E8=AF=8D=E7=94=9F=E6=88=90=E5=8A=A9=E6=89=8B?= =?UTF-8?q?=EF=BC=8C=E6=94=AF=E6=8C=81=E6=A0=B9=E6=8D=AE=E4=B8=AD=E6=96=87?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E7=94=9F=E6=88=90=E9=80=82=E5=90=88=E8=8B=B1?= =?UTF-8?q?=E6=96=87=E8=A7=86=E9=A2=91=E7=BD=91=E7=AB=99=E7=9A=84=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E5=85=B3=E9=94=AE=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- participle.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 participle.py diff --git a/participle.py b/participle.py new file mode 100644 index 0000000..2958020 --- /dev/null +++ b/participle.py @@ -0,0 +1,56 @@ +import requests + +url = "https://api.siliconflow.cn/v1/chat/completions" +kw = "朝雪录" +rn = "US" +payload = { + "model": "Qwen/Qwen3-14B", + "max_tokens": 512, + "enable_thinking": True, + "thinking_budget": 4096, + "min_p": 0.05, + "temperature": 0.7, + "top_p": 0.7, + "top_k": 50, + "frequency_penalty": 0.5, + "n": 1, + "stream": False, + "stop": [], + "messages": [ + { + "role": "user", + "content": """你是一个视频搜索优化助手。用户给你一个中文视频标题或关键词,请你翻译并联想出 10 个适合用于英文视频网站(如 Dailymotion)搜索的关键词,结果用英文逗号分隔输出,仅返回关键词列表,不加说明。 + +示例输入:朝雪录 +示例输出:Coroner's Diary,Coroners Diary, Coroners Diary episode,Coroners Diary season 1,Coroners Diary full episode,coroners diary +""" + }, + { + "role": "user", + "content": f"请推理:{kw} 并输出 10 个地区缩写为{rn}的适合用于视频网站搜索的关键词,地区缩写不在关键词内,。" + } + ] +} + +headers = { + "Authorization": "Bearer sk-isvydeloxqhoiwoiojleghdsuhagryjbxzphfhxneevxeoeh", + "Content-Type": "application/json" +} + +response = requests.post(url, json=payload, headers=headers, timeout=30) + +def parse_keywords_from_response(resp_json): + try: + # 取出文本内容 + content = resp_json["choices"][0]["message"]["content"] + # 按英文逗号分隔 + keywords = [kw.strip() for kw in content.split(",") if kw.strip()] + return keywords + except Exception as e: + print("解析失败:", e) + return [] + +kws = parse_keywords_from_response(response.json()) + +print(kws) +print(len(kws)) \ No newline at end of file