crewAIInc / crewAI-examples

A collection of examples that show how to use CrewAI framework to automate workflows.
2.86k stars 1.09k forks source link

act more generously on GPT-4 rate limiting #8

Closed sokoow closed 10 months ago

sokoow commented 10 months ago

I keep getting this when I use the stock market example with IonQ as a research parameter:

-----------------Retrying langchain.chat_models.openai.ChatOpenAI.completion_with_retry.<locals>._completion_with_retry in 4.0 seconds as it raised RateLimitError: Rate limit reached for gpt-4 in organization org-1rhDRxvm3VH1zRPJ8PupLYK9 on tokens_usage_based per min: Limit 10000, Used 8437, Requested 2629. Please try again in 6.396s. Visit https://platform.openai.com/account/rate-limits to learn more..
Traceback (most recent call last):
  File "/home/crewai/stock_analysis/./main.py", line 54, in <module>
    result = financial_crew.run()
  File "/home/crewai/stock_analysis/./main.py", line 42, in run
    result = crew.kickoff()
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/crew.py", line 63, in kickoff
    return self.__sequential_loop()
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/crew.py", line 81, in __sequential_loop
    task_outcome = task.execute(task_outcome)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/task.py", line 36, in execute
    return self.agent.execute_task(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/agent.py", line 102, in execute_task
    return self.agent_executor.invoke({
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 87, in invoke
    return self(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 310, in __call__
    raise e
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 304, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1167, in _call
    next_step_output = self._take_next_step(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1017, in _take_next_step
    observation = tool.run(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/tools/base.py", line 365, in run
    raise e
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/tools/base.py", line 337, in run
    self._run(*tool_args, run_manager=run_manager, **tool_kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/tools/base.py", line 516, in _run
    else self.func(*args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/tools/agent_tools.py", line 38, in delegate_work
    return self.__execute(command)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/tools/agent_tools.py", line 60, in __execute
    result = agent.execute_task(task, information)  
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/crewai/agent.py", line 102, in execute_task
    return self.agent_executor.invoke({
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 87, in invoke
    return self(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 310, in __call__
    raise e
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chains/base.py", line 304, in __call__
    self._call(inputs, run_manager=run_manager)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 1167, in _call
    next_step_output = self._take_next_step(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 954, in _take_next_step
    output = self.agent.plan(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/agents/agent.py", line 389, in plan
    output = self.runnable.invoke(inputs, config={"callbacks": callbacks})
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/schema/runnable/base.py", line 1427, in invoke
    input = step.invoke(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/schema/runnable/base.py", line 2765, in invoke
    return self.bound.invoke(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/base.py", line 142, in invoke
    self.generate_prompt(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/base.py", line 459, in generate_prompt
    return self.generate(prompt_messages, stop=stop, callbacks=callbacks, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/base.py", line 349, in generate
    raise e
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/base.py", line 339, in generate
    self._generate_with_cache(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/base.py", line 492, in _generate_with_cache
    return self._generate(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/openai.py", line 417, in _generate
    response = self.completion_with_retry(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/openai.py", line 347, in completion_with_retry
    return _completion_with_retry(**kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 289, in wrapped_f
    return self(f, *args, **kw)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 379, in __call__
    do = self.iter(retry_state=retry_state)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 325, in iter
    raise retry_exc.reraise()
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 158, in reraise
    raise self.last_attempt.result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 451, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/tenacity/__init__.py", line 382, in __call__
    result = fn(*args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/langchain/chat_models/openai.py", line 345, in _completion_with_retry
    return self.client.create(**kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/openai/api_resources/chat_completion.py", line 25, in create
    return super().create(*args, **kwargs)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 155, in create
    response, _, api_key = requestor.request(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/openai/api_requestor.py", line 299, in request
    resp, got_stream = self._interpret_response(result, stream)
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/openai/api_requestor.py", line 710, in _interpret_response
    self._interpret_response_line(
  File "/root/.cache/pypoetry/virtualenvs/stock-analysis-crew-jF_CJZer-py3.10/lib/python3.10/site-packages/openai/api_requestor.py", line 775, in _interpret_response_line
    raise self.handle_error_response(
openai.error.RateLimitError: Rate limit reached for gpt-4 in organization org-1rhDRxvm3VH1zRPJ8PupLYK9 on tokens_usage_based per min: Limit 10000, Used 7709, Requested 2629. Please try again in 2.027s. Visit https://platform.openai.com/account/rate-limits to learn more.

any way to work around that that you can think of?

sokoow commented 10 months ago

duplicate of https://github.com/joaomdmoura/crewAI/issues/32