123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import json
- import requests
- class GPT4oMini:
- @classmethod
- def get_ai_mini_title(cls, title):
- url = "http://aigc-api.cybertogether.net//aigc/dev/test/gpt"
- payload = json.dumps({
- "imageList": [],
- "model": "gpt-4o-mini-2024-07-18",
- "prompt": (
- "针对微信平台视频类小程序场景"
- "面向人群是中国中老年人,在单聊、群聊场景。为视频生成一个吸引人的标题。每次生成我会提供一个原标题,你通过规则生成一个新的标题。"
- "生成规则:"
- "a.生成的新标题一定不能包含以下风险词。 风险词:“看看”、“全体”、“一定”、“所以人”、“无数人”、“值得一看”、“值得一听”、“99 % ”、“震撼”、“必”、“必看”、“必听”、“必读”、“全场”、“听听”、“一起听听”、“一起”、“快看”、“快来”、“分享”、“转发”、“都看看吧”、“都来”"
- "b.新标题字符不小于15个字,不超过30个字。"
- "c.新标题最前面或最后面必须加上emoij符号。如“🔴”、“⭕️”、“🚩”、“🔥”、“💖”"
- "d.新标题最好只去掉原标题里的低质词,其他句子、语句都保持不变"
- "e.去掉低质词后,根据语意适当加字句,使新标题整句读起来简洁、通顺、有吸引力、并准确反映视频核心内容"
- "请严格按照上述规则,生成对应的新标题。"
- f"请分析该标题,标题为:{title},返回新的标题。"
- ),
- "responseFormat": {
- "type": "json_schema",
- "json_schema": {
- "strict": True,
- "name": "share_script_result",
- "schema": {
- "type": "object",
- "properties": {
- "新标题": {
- "type": "string",
- "description": "生成新的标题"
- }
- },
- "required": ["新标题"],
- "additionalProperties": False
- }
- }
- }
- })
- headers = {'Content-Type': 'application/json'}
- try:
- response = requests.post(url, headers=headers, data=payload)
- response_data = response.json()
- data = json.loads(response_data.get('data', '{}'))
- new_title = data["新标题"]
- return new_title
- except Exception as e:
- return None
- if __name__ == '__main__':
- title = GPT4oMini.get_ai_mini_title("🔴这位美女说的太好了!这就是我们的大中国")
- print(title)
|