PyChatGPT
PyChatGPT copied to clipboard
A Function to respond to CAPTCHA verification
Hey,
is it possible to make a function to respond to CAPTCHA image result (__part_five
in openai.py), instead of using input on the console?
do you mean a function to perform the CAPTCHA verification or a better log to the console?
do you mean a function to perform the CAPTCHA verification or a better log to the console?
The current CAPTCHA checking strategy stores the verification code image locally and waits for the user to recognize and input the code to the console.
I thought it's good to add a function to do this, to provide an alternative.
for example, if the CAPTCHA image hint to enter 'e8A6M', then I could just use the function to respond:
respond_func('e8A6M')
instead of typing 'e8A6M' in console.
you cannot call a function like respond_func('e8A6M')
a when the program is already running. This would need a service like RabbitMQ/ActiveMQ
TL;DR: allow us to pass a captcha solver method and store the authentication information to a file to keep track of it between different runs.
My suggested solution:
- Add a
captcha_solver
parameter to theOptions
object that receives a method to be used to solve captchas - At line 254 in
src/pychatgpt/classes/openai.py
add a check:if captcha_solver:
where the method is called with the result ofreportlab.graphics.renderPM.drawToPIL
- The method does whatever it wants with the Pillow object and returns the string
- Continue execution using the captcha solution obtained programmatically
One problem I see with solving captchas programmatically is that it can take quite some time (some APIs can take up to 20s to reply) and as such if you have no way to await
the method, you would have to either sleep
for an unknown amount of time or use a clunky while
loop that checks if the output is available.
I think that the current authentication implementation is heavily biased towards interactive use, which is totally fine but makes devs lives a bit less colorful. Maybe consider:
- Either make all the necessary information like CSRF token (if it doesn't change every request), Current State and Access Token easily available so developers can tuck it somewhere and write their own logic to renew authentication, or;
- Pickle that information to a file that the library can use to track how the relevant information has changed between multiple sessions.
EDIT:
you cannot call a function like
respond_func('e8A6M')
a when the program is already running. This would need a service like RabbitMQ/ActiveMQ
This should be plenty possible by just awaiting
on it whenever you need to solve captchas, if that ever happens during execution. It would block? Yes. But in this case you want it to block as the information is required to continue execution. Okay, you would need this to be rewritten asynchronously, but sleeping/checking for it in a while loop should be enough I guess.