redo chat prompt if bad response

This commit is contained in:
Tristan Stevens 2023-11-18 18:41:17 +01:00 committed by GitHub
parent 1174275b5b
commit ee6603641f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 16 deletions

View File

@ -54,22 +54,27 @@ def generate_new_line(base64_image):
def analyze_image(base64_image, script): def analyze_image(base64_image, script):
response = client.chat.completions.create( while True:
model="gpt-4-vision-preview", response = client.chat.completions.create(
messages=[ model="gpt-4-vision-preview",
{ messages=[
"role": "system", {
"content": """ "role": "system",
You are Sir David Attenborough. Narrate the picture of the human as if it is a nature documentary. "content": """
Make it snarky and funny. Don't repeat yourself. Make it short. If I do anything remotely interesting, make a big deal about it! 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), + script
max_tokens=500, + generate_new_line(base64_image),
) max_tokens=200,
response_text = response.choices[0].message.content )
response_text = response.choices[0].message.content
if not response_text.startswith("I'm sorry"):
break
return response_text return response_text