0

ChatGPT批量生成内容Python脚本

1fybg5lkio
2023-4-10 594

import openai import re openai.api_key = "key" # 将YOUR_API_KEY_HERE替换成你的OpenAI API密钥 model_engine = "text-davinci-002" # ChatGPT模型名称 def generate_text(prompt): response = openai.Completion.create( engine=model_engine, prompt=prompt, max_tokens=2048, n=1, stop=None, temperature=0.7, timeout=30, # 将超时时间设置为30秒 ) message = response.choices[0].text return message.strip() def generate_title_and_content(keywords): prompt = "Generate a title and content for an article about " + keywords + ".\n\nTitle:" title = generate_text(prompt) content_prompt = "Write an article about " + keywords + " with the following title:\n\n" + title + "\n\nArticle:" content = generate_text(content_prompt) return (title, content) keywords_list = ["谷歌seo怎么做","谷歌SEM怎么做"] # 你可以在这里替换或添加关键字 for keywords in keywords_list: title, content = generate_title_and_content(keywords) print("标题:", title) print("内容:", content) print("\n\n") 复制代码

最新回复 (0)

    暂无评论

请先登录后发表评论!

返回
请先登录后发表评论!