INNER CODE UNIT · Python
prompt_image
roboflow/awesome-openai-vision-api-experiments · experiments/hot-dog-not-hot-dog/app.py:78
def prompt_image(api_key: str, image: np.ndarray, prompt: str) -> str:
headers = compose_headers(api_key=api_key)
payload = compose_payload(image=image, prompt=prompt)
response = requests.post(url=API_URL, headers=headers, json=payload).json()
if 'error' in response:
raise ValueError(response['error']['message'])
return response['choices'][0]['message']['content']
def classify_image(api_key: str, image: np.ndarray) -> str:
if not api_key:
raise ValueError(
"API_KEY is not set. "
"Please follow the instructions in the README to set it up.")
image = preprocess_image(image=image)
prompt = compose_classification_prompt(classes=CLASSES)
response = prompt_image(api_key=api_key, image=image, prompt=prompt)