去评论
dz插件网

ChatGPT批量生成内容Python脚本

哥斯拉
2023/03/08 19:30:28
  1. import openaiimport reopenai.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")
自己改改吧..
自从chatgpt出来后感觉比较焦虑