from openai import OpenAI client = OpenAI() base_prompt = "This image describes a word in the theme 'magic' (for example: wizard, druid or spellbinding). Which word? Give your three best guesses. The word consists of this many letters: " def doChatGPT(prompt, image_url): response = client.chat.completions.create( model="gpt-4-vision-preview", messages=[ { "role": "user", "content": [ {"type": "text", "text": prompt}, { "type": "image_url", "image_url": { "url": image_url, }, }, ], } ], max_tokens=400, ) return response.choices[0] # Define your array with image URLs and descriptions image_data = [ ["https://matth-ijs.nl/paaspuzzel/2024/01.jpg", "transmutation"], ["https://matth-ijs.nl/paaspuzzel/2024/02.jpg", "seance"], ["https://matth-ijs.nl/paaspuzzel/2024/03.jpg", "warlock"], ["https://matth-ijs.nl/paaspuzzel/2024/04.jpg", "mantra"], ["https://matth-ijs.nl/paaspuzzel/2024/05.jpg", "mermaid"], ["https://matth-ijs.nl/paaspuzzel/2024/06.jpg", "troll"], ["https://matth-ijs.nl/paaspuzzel/2024/07.jpg", "hobbits"], ["https://matth-ijs.nl/paaspuzzel/2024/08.jpg", "divination"], ["https://matth-ijs.nl/paaspuzzel/2024/09.jpg", "fairy"], ["https://matth-ijs.nl/paaspuzzel/2024/10.jpg", "witch"], ["https://matth-ijs.nl/paaspuzzel/2024/11.jpg", "banshee"], ["https://matth-ijs.nl/paaspuzzel/2024/12.jpg", "angels"], ["https://matth-ijs.nl/paaspuzzel/2024/13.jpg", "wand"], ["https://matth-ijs.nl/paaspuzzel/2024/14.jpg", "centaur"], ["https://matth-ijs.nl/paaspuzzel/2024/15.jpg", "elves"], ["https://matth-ijs.nl/paaspuzzel/2024/16.jpg", "harrypotter"], ["https://matth-ijs.nl/paaspuzzel/2024/17.jpg", "illustion"], ["https://matth-ijs.nl/paaspuzzel/2024/18.jpg", "medium"], ["https://matth-ijs.nl/paaspuzzel/2024/19.jpg", "ouija"], ["https://matth-ijs.nl/paaspuzzel/2024/20.jpg", "hocuspocus"] ] # Print the array to verify for item in image_data: url = item[0] description = item[1] ai_answer = doChatGPT(base_prompt + str(len(description)), url) print("## Puzzle", description) print("The AI response:") print(ai_answer) if description in ai_answer: print("The LLM **solved the puzzle!**")