SuffolkLITLab / FormFyxer

A tool for learning about and pre-processing forms
MIT License
11 stars 1 forks source link

Migrate to the stable OpenAI Python client (1.0) #129

Closed nonprofittechy closed 7 months ago

nonprofittechy commented 8 months ago

A simple migration of text_complete() code to the stable OpenAI 1.0 release.

  1. I made the default OpenAI text files empty, rather than putting in placeholder text. Currently, if you use the empty OpenAI() initialization with an invalid API key, it will raise an error right away. This solves that issue.
  2. This now works with an environment variable, which is the expected way that OpenAI documents to provide an API key in the new client.
  3. It still allows you to pass the credentials manually, so it should be compatible with the previous code we had.

@BryceStevenWilley I don't know why, but some new typing issues cropped up with your field recognition code. Shouldn't have mattered at run time (we weren't doing anything that depended on lists or tuples), but perhaps a new mypy release is stricter. To solve the typing error message, I made sure we use tuples rather than lists for the internal function I modified below. It should be identical, but please take a look. Using tuples everywhere, including default returns, seemed a better option than converting the outputs to a list.