From b53bdc818e04f42fe9bcfe80ee17d1334ec00506 Mon Sep 17 00:00:00 2001 From: Hayden Housen Date: Sun, 23 Jul 2023 10:42:01 -0700 Subject: [PATCH] Update prompt --- .../end_to_end/summarization_approaches.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lecture2notes/end_to_end/summarization_approaches.py b/lecture2notes/end_to_end/summarization_approaches.py index 73474b2..00aeabd 100644 --- a/lecture2notes/end_to_end/summarization_approaches.py +++ b/lecture2notes/end_to_end/summarization_approaches.py @@ -822,13 +822,20 @@ def generic_extractive_sumy( def summarize_chatgpt(text, model="gpt-3.5-turbo"): import openai - response = openai.ChatCompletion.create( - model=model, - messages=[ - {"role": "user", "content": f"Can you provide a comprehensive summary of the given transcript? The summary should cover all the key points presented in the original transcript, while also condensing the information into a concise and easy-to-understand format. Please ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition. The length of the summary should be appropriate for the length and complexity of the original transcript, providing a clear and accurate overview without omitting any important information. Write just the summary and nothing else. Do not reference the original transcript.\n\n{text}"}, - ] - ) - summary = response["choices"][0]["message"]["content"] + try: + response = openai.ChatCompletion.create( + model=model, + messages=[ + {"role": "user", "content": f"{text}\n\nCan you provide a comprehensive summary of the given transcript? The summary should cover all the key points presented in the original transcript, while also condensing the information into a concise and easy-to-understand format. Please ensure that the summary includes relevant details and examples that support the main ideas, while avoiding any unnecessary information or repetition. The length of the summary should be significantly shorter than the original transcript while still providing a clear and accurate overview without omitting any important information. Write just the summary and do not reference the original transcript. Write just the main points and do not say introductory phrases. Write in the 1st person."}, + ] + ) + summary = response["choices"][0]["message"]["content"] + except openai.error.InvalidRequestError as e: + if "maximum context length" in str(e): + summary = "This content is too long to be summarized. Please contact support for assistance." + else: + raise e + return summary