原标题: # -*- coding: utf-8 -*-
导读:
import openaiopenai.api_key = "YOUR_API_KEY"def generate_title(description):pr...
import openai
openai.api_key = "YOUR_API_KEY"
def generate_title(description):
prompt = f"ChatGPT is a language model developed by OpenAI. It can be used to generate personalized SEO titles based on content description.\n\nDescription: {description}\n\nTitle:"
response = openai.Completion.create(
engine="text-davinci-003",
prompt=prompt,
temperature=0.5,
max_tokens=30,
top_p=1.0,
frequency_penalty=0.2,
presence_penalty=0.0
)
title = response.choices[0].text.strip()
return title
description = "This is an article about the benefits of exercise for mental health."
title = generate_title(description)
print("Generated Title:", title)