openai.error.InvalidRequestError: Engine not found

Viewed 686

Tried accessing the OpenAPI example - Explain code But it shows error as -

InvalidRequestError: Engine not found

enter code response = openai.Completion.create(
engine="code-davinci-002",
prompt="class Log:\n    def __init__(self, path):\n        dirname = os.path.dirname(path)\n        os.makedirs(dirname, exist_ok=True)\n        f = open(path, \"a+\")\n\n        # Check that the file is newline-terminated\n        size = os.path.getsize(path)\n        if size > 0:\n            f.seek(size - 1)\n            end = f.read(1)\n            if end != \"\\n\":\n                f.write(\"\\n\")\n        self.f = f\n        self.path = path\n\n    def log(self, event):\n        event[\"_event_id\"] = str(uuid.uuid4())\n        json.dump(event, self.f)\n        self.f.write(\"\\n\")\n\n    def state(self):\n        state = {\"complete\": set(), \"last\": None}\n        for line in open(self.path):\n            event = json.loads(line)\n            if event[\"type\"] == \"submit\" and event[\"success\"]:\n                state[\"complete\"].add(event[\"id\"])\n                state[\"last\"] = event\n        return state\n\n\"\"\"\nHere's what the above class is doing:\n1.",
      temperature=0,
      max_tokens=64,
      top_p=1.0,
      frequency_penalty=0.0,
      presence_penalty=0.0,
      stop=["\"\"\""]
    )
3 Answers

Please note that your code is not very readable.

However, from the given error, I think it has to do with the missing colon : in the engine name.

Change this line from:

engine="code-davinci-002",

to

engine="code-davinci:002",

If you are using a finetuned model instead of an engine, you'd want to use model= instead of engine=.

response = openai.Completion.create(
  model="<finetuned model>",
  prompt=
Related