junhoyeo / BetterOCR

šŸ” Better text detection by combining multiple OCR engines (EasyOCR, Tesseract, and Pororo) with šŸ§  LLM.
MIT License
475 stars 27 forks source link

Fix Incorrect Inclusion of API_KEY in chat.completions.create Call #3

Closed snacsnoc closed 11 months ago

snacsnoc commented 11 months ago

This PR addresses a bug where the API_KEY was erroneously included in the parameters of the chat.completions.create() method, leading to a TypeError. The error in question:

Traceback (most recent call last):
  File "/Users/easto/Library/Mobile Documents/com~apple~CloudDocs/Projects/spine-reader/better.py", line 4, in <module>
    text = betterocr.detect_text(
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/easto/Library/Mobile Documents/com~apple~CloudDocs/Projects/spine-reader/venv/lib/python3.11/site-packages/betterocr/detect.py", line 83, in detect_text
    completion = client.chat.completions.create(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/easto/Library/Mobile Documents/com~apple~CloudDocs/Projects/spine-reader/venv/lib/python3.11/site-packages/openai/_utils/_utils.py", line 299, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
TypeError: Completions.create() got an unexpected keyword argument 'API_KEY'

The provided fix prioritizes the user-specified API_KEY when initializing the OpenAI client and ensures that the API_KEY is not passed along with other options to the completions.create() call.

junhoyeo commented 11 months ago

omg I missed that, thanks!

snacsnoc commented 11 months ago

@junhoyeo Thanks for merging! :D

junhoyeo commented 11 months ago

@junhoyeo Thanks for merging! :D

šŸ‘šŸ‘ Just shipped https://github.com/junhoyeo/BetterOCR/releases/tag/v1.1.2 to PyPI