How to use open ai library for creating email summaries for long emails stored in a dataframe

Hi, I am having trouble in using open ai, to get summary of emails stored in a pandas dataframe. I used the following function #Standard function to get summaries, currently running into errors potentially due to api key
def generate_summary(email):
prompt = “Summarize the following email:\n\n” + email + “\n\nSummary:”
response = client.chat.completions.create(
model=“text-davinci-004”, # You can also use “text-davinci-004” for GPT-3.5-turbo
prompt=prompt,
max_tokens=150
)
return response.choices[0].text.strip()

I ended up with either Name errors or that the version is not available or the error APIRemovedInV1 . I am using gpt 3.5 turbo with api keys. can someone help me with a finction, that I can apply to a pandas column to get email summaries stored in the dataset?

:thinking:

It’s probably a good idea to go back to the basics. If you go here, you’ll find the official documentation with a working example: https://platform.openai.com/docs/api-reference/completions

But if you’re just getting started you could try this: test your prompts here: https://platform.openai.com/playground/chat (you can also select complete on the left), and then top right, there’s a button labeled “view code”

if you click on that, you’ll be presented with code that should work with the newest version of the openai library.