Skip to content

Commit

Permalink
Don't try to finish a failed process again in OpenAI prompting
Browse files Browse the repository at this point in the history
  • Loading branch information
sal-uva committed Jan 7, 2025
1 parent 57b6e22 commit 82c8817
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions processors/machine_learning/openai_pompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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"]
Expand Down

0 comments on commit 82c8817

Please sign in to comment.