rxn4chemistry / biocatalysis-model

RXN for biochemical reactions
MIT License
60 stars 14 forks source link

Error on predict_automatic_retrosynthesis #2

Closed liuxuan99 closed 2 years ago

liuxuan99 commented 2 years ago

Hello, when I tried to predict a retrosynthesis pathway, I got an error 'status': 429, 'error': 'Too Many Requests'. get_predict_reaction_results and paragraph_to_actions are able to get correct results under the same API. I tried to generate a new API, but the error persist.

Here are my code and return.

api_key = {my_api}
from rxn4chemistry import RXN4ChemistryWrapper

rxn4chemistry_wrapper = RXN4ChemistryWrapper(api_key=api_key)
rxn4chemistry_wrapper.create_project('new_wrapper')
response = rxn4chemistry_wrapper.predict_automatic_retrosynthesis(
    'NC(=O)C[C@@H](N)C(=O)O', ai_model='enzymatic-2021-04-16'
)
results = rxn4chemistry_wrapper.get_predict_automatic_retrosynthesis_results(
    response['prediction_id']
)
print(results)

Return

{'response': {'timestamp': 1654933936548, 'status': 429, 'error': 'Too Many Requests', 'message': 'Too many requests', 'path': '/rxn/api/api/v1/retrosynthesis/62a449af114bfa0001e590f6'}}
drugilsberg commented 2 years ago

Hi @liuxuan99, thanks for using our model. The error you are seeing is due to the limitations we impose on the API calls from a single key. Please, try waiting at least 500ms between requests and limit your requests to 3-4 per minutes. You should not see the error and since the retro predictions are anyway taking on average 2 minutes performance will not be impacted.

drugilsberg commented 2 years ago

Hi @liuxuan99, thanks for using our model. The error you are seeing is due to the limitations we impose on the API calls from a single key. Please, try waiting at least 500ms between requests and limit your requests to 3-4 per minutes. You should not see the error and since the retro predictions are anyway taking on average 2 minutes performance will not be impacted.

liuxuan99 commented 2 years ago

Hi @drugilsberg, thank you so much for your help! This issue is solved after I split all of the code belowed response = ... to a new cell. In Colab, results = ... was executed right after response = ..., which caused the issue Too Many Requests. For people who use Colab or Jupyter, the modified code below should work.

response = rxn4chemistry_wrapper.predict_automatic_retrosynthesis(
    'NC(=O)C[C@@H](N)C(=O)O', ai_model='enzymatic-2021-04-16'
)

while True:
    time.sleep(5)
    results = rxn4chemistry_wrapper.get_predict_automatic_retrosynthesis_results(
    response['prediction_id']
    )
    if results['status'] == 'SUCCESS':
        break
print(results['retrosynthetic_paths'][0])