原标题: 代码如下:
导读:
```pythonimport openai# Set up the OpenAI API credentialsopenai.api_key = "YOUR_API...
```python
import openai
# Set up the OpenAI API credentials
openai.api_key = "YOUR_API_KEY"
# Define the content prompt for generating SEO titles
content_prompt = """
Content: {content}
SEO Title Suggestions:
1. {keyword} - Discover Everything You Need to Know!
2. Unlock the Secrets of {keyword} and Transform Your Life Today!
3. The Ultimate Guide to Mastering {keyword}: All You Need to Succeed!
4. Learn How to {action} and Achieve Remarkable Results.
5. Uncover the Hidden Benefits of {keyword}: A Comprehensive Analysis.
"""
def generate_seo_title(content, keyword, action):
# Format the content prompt with given inputs
chat_input = content_prompt.format(content=content, keyword=keyword, action=action)
# Generate response from ChatGPT using completion method
response = openai.Completion.create(
engine="text-davinci-003",
prompt=chat_input,
max_tokens=100,
n=1,
stop=None,
temperature=0.6,
top_p=None,
frequency_penalty=None,
presence_penalty=None
)
# Extract suggested title from generated response
generated_title = response.choices[0].text.strip().split('\n')[2][3:]
return generated_title
# Example usage:
content_text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit."
chosen_keyword = "technology"
desired_action = "build a successful business"
generated_seo_title = generate_seo_title(content_text, chosen_keyword, desired_action)
print("Generated SEO Title:", generated_seo_title)
```