From 82c88174c4d571f1c52b4221c7f391a4c4396edd Mon Sep 17 00:00:00 2001 From: Sal Hagen Date: Tue, 7 Jan 2025 14:18:22 +0100 Subject: [PATCH] Don't try to finish a failed process again in OpenAI prompting --- processors/machine_learning/openai_pompt.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/processors/machine_learning/openai_pompt.py b/processors/machine_learning/openai_pompt.py index baa076b3..269a239f 100644 --- a/processors/machine_learning/openai_pompt.py +++ b/processors/machine_learning/openai_pompt.py @@ -155,12 +155,15 @@ def process(self): consent = self.parameters.get("consent", False) if not consent: self.dataset.finish_with_error("You must consent to your data being sent to OpenAI first") + return + self.dataset.delete_parameter("consent") model = self.parameters.get("model") if model == "custom": if not self.parameters.get("custom_model", ""): self.dataset.finish_with_error("You must provide a valid ID for your custom model") + return else: custom_model_id = self.parameters.get("custom_model", "") self.parameters["model"] = custom_model_id @@ -177,11 +180,13 @@ def process(self): temperature = float(self.parameters.get("temperature")) except ValueError: self.dataset.finish_with_error("Temperature must be a number") + return try: max_tokens = int(self.parameters.get("max_tokens")) except ValueError: self.dataset.finish_with_error("Max tokens must be a number") + return self.dataset.delete_parameter("api_key") # sensitive, delete after use @@ -196,6 +201,7 @@ def process(self): if not replacements: self.dataset.finish_with_error("You need to provide the prompt with input values using [brackets] of " "column names") + return write_annotations = False # todo: update when explorer is integrated @@ -224,18 +230,18 @@ def process(self): prompt = prompt.replace(replacement, field_name) except KeyError as e: self.dataset.finish_with_error("Field %s could not be found in the parent dataset" % str(e)) - + return try: response = self.prompt_gpt(prompt, client, model=model, temperature=temperature, max_tokens=max_tokens) except openai.NotFoundError as e: self.dataset.finish_with_error(e.message) - return 0 + return except openai.BadRequestError as e: self.dataset.finish_with_error(e.message) - return 0 + return except openai.AuthenticationError as e: self.dataset.finish_with_error(e.message) - return 0 + return if "id" in item: item_id = item["id"]