import os
from openai import OpenAI
from dotenv import load_dotenv
defget_openai_key():
_ = load_dotenv('.env文件的路径')return os.environ['OPENAI_API_KEY']
client = OpenAI(
api_key=get_openai_key(),# this is also the default, it can be omitted)
4.给出文本和prompt
text =f"""
You should express what you want a model to do by \
providing instructions that are as clear and \
specific as you can possibly make them. \
This will guide the model towards the desired output, \
and reduce the chances of receiving irrelevant \
or incorrect responses. Don't confuse writing a \
clear prompt with writing a short prompt. \
In many cases, longer prompts provide more clarity \
and context for the model, which can lead to \
more detailed and relevant outputs.
"""
prompt =f"""
Summarize the text delimited by triple backticks \
into a single sentence.
```{text}```
"""