diff --git a/classes/DataSet_OpenAIChatImage.py b/classes/DataSet_OpenAIChatImage.py index 292a578..294d66d 100644 --- a/classes/DataSet_OpenAIChatImage.py +++ b/classes/DataSet_OpenAIChatImage.py @@ -19,7 +19,6 @@ class DataSet_OpenAIChatImage: "prompt": ("STRING", {"multiline": True, "default": ""}), "model": (["gpt-4o","gpt-4", "gpt-4-32k", "gpt-3.5-turbo", "gpt-4-0125-preview", "gpt-4-turbo-preview", "gpt-4-1106-preview", "gpt-4-0613"], {"default": "gpt-4o"}), "api_url": ("STRING", {"multiline": False, "default": "https://api.openai.com/v1"}), - # "api_key": ("STRING", {"multiline": False}), "token_length": ("INT", {"default": 1024}) } } @@ -36,7 +35,7 @@ class DataSet_OpenAIChatImage: img.save(buffered, format="PNG") return base64.b64encode(buffered.getvalue()).decode("utf-8") - def generate(self, image, image_detail, model, api_url, prompt, token_length): + def generate(self, image, image_detail, prompt, model, api_url, token_length): try: api_key = os.environ.get("OPENAI_API_KEY") diff --git a/classes/DataSet_OpenAIChatImageBatch.py b/classes/DataSet_OpenAIChatImageBatch.py index 2adbfe8..aef341f 100644 --- a/classes/DataSet_OpenAIChatImageBatch.py +++ b/classes/DataSet_OpenAIChatImageBatch.py @@ -37,33 +37,30 @@ class DataSet_OpenAIChatImageBatch: img.save(buffered, format="PNG") return base64.b64encode(buffered.getvalue()).decode("utf-8") - def generate(self, images, image_detail, model, api_url, prompt, token_length): + def generate(self, images, image_detail, prompt, model, api_url, token_length): try: image_detail = image_detail[0] model = model[0] api_url = api_url[0] - api_key = api_key[0] prompt = prompt[0] token_length = token_length[0] answers = [] - for image in images: + api_key = os.environ.get("OPENAI_API_KEY") + ai = OpenAI(api_key=api_key, base_url=api_url) - api_key = os.environ.get("OPENAI_API_KEY") - ai = OpenAI(api_key=api_key, base_url=api_url) + for image in images: base64img = self.to_base64(image) if not api_key: return "OpenAI API key is required." - request = [{"role": "system","content": "You are GPT-4."}] request.append({"role": "user","content": [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{base64img}", "detail": image_detail}}]}) request.append({"role": "user","content": prompt}) response = ai.chat.completions.create(model=model,messages=request,max_tokens=token_length) answer = response.choices[0].message.content - answers.append(answer) return (answers,)