From ee6603641f8e5366f733212cbe0d8dc429609703 Mon Sep 17 00:00:00 2001 From: Tristan Stevens <58224357+tristan-deep@users.noreply.github.com> Date: Sat, 18 Nov 2023 18:41:17 +0100 Subject: [PATCH] redo chat prompt if bad response --- narrator.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/narrator.py b/narrator.py index cd086f7..8eb6a40 100644 --- a/narrator.py +++ b/narrator.py @@ -54,22 +54,27 @@ def generate_new_line(base64_image): def analyze_image(base64_image, script): - response = client.chat.completions.create( - model="gpt-4-vision-preview", - messages=[ - { - "role": "system", - "content": """ - You are Sir David Attenborough. Narrate the picture of the human as if it is a nature documentary. - Make it snarky and funny. Don't repeat yourself. Make it short. If I do anything remotely interesting, make a big deal about it! - """, - }, - ] - + script - + generate_new_line(base64_image), - max_tokens=500, - ) - response_text = response.choices[0].message.content + while True: + response = client.chat.completions.create( + model="gpt-4-vision-preview", + messages=[ + { + "role": "system", + "content": """ + You are Sir David Attenborough. Narrate the picture of the human as if it is a nature documentary. + Make it snarky and funny. Don't repeat yourself. Make it short. Max two sentence. If I do anything remotely interesting, make a big deal about it! + """, + }, + ] + + script + + generate_new_line(base64_image), + max_tokens=200, + ) + response_text = response.choices[0].message.content + + if not response_text.startswith("I'm sorry"): + break + return response_text