Check for API key in multimodal captions

This commit is contained in:
Cohee 2023-11-18 20:58:04 +02:00
parent 7045d242e8
commit 4999fbd97c
1 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { getRequestHeaders } from "../../script.js";
import { extension_settings } from "../extensions.js";
import { SECRET_KEYS, secret_state } from "../secrets.js";
/**
* Generates a caption for an image using a multimodal model.
@ -8,6 +9,14 @@ import { extension_settings } from "../extensions.js";
* @returns {Promise<string>} Generated caption
*/
export async function getMultimodalCaption(base64Img, prompt) {
if (extension_settings.caption.multimodal_api === 'openai' && !secret_state[SECRET_KEYS.OPENAI]) {
throw new Error('OpenAI API key is not set.');
}
if (extension_settings.caption.multimodal_api === 'openrouter' && !secret_state[SECRET_KEYS.OPENROUTER]) {
throw new Error('OpenRouter API key is not set.');
}
const apiResult = await fetch('/api/openai/caption-image', {
method: 'POST',
headers: getRequestHeaders(),