I am attempting to extract text from ChatGPT but I need some help with the correct syntax;
_model = "gpt-3.5-turbo-instruct"
# Summarize the text using an AI model (e.g., OpenAI's GPT)
try:
summary = openai.completions.create(
model=_model,
prompt=f"Summarize this text: {text}",
max_tokens=150
)
except Exception as e:
return f"summary: Exception {e}"
_summary = summary.choices[0].message.content
#_summary = summary['choices'][0]['text']
I want to get a summary of the text – is this the best way?
However I find when I debug the code that the text object is located in the following structure within summary[‘choices’][0]:
CompletionChoice(finish_reason='stop', index=0, logprobs=None, text='blah blah blah')
How do I extract the text from this in Python code?