Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to submit a form #1079

Open
6open opened this issue Jan 15, 2025 · 1 comment
Open

Error when trying to submit a form #1079

6open opened this issue Jan 15, 2025 · 1 comment

Comments

@6open
Copy link

6open commented Jan 15, 2025

Describe the bug
在代码实现中,for 循环用于最多尝试 10 次调用 API,但 return 在第一次调用时就被触发,导致循环未完成,无法进行多次尝试。

To Reproduce
Steps to reproduce the behavior:

  1. Go to https://github.com/assafelovic/gpt-researcher/blob/master/gpt_researcher/utils/llm.py

  2. `for _ in range(10): # maximum of 10 attempts
    response = await provider.get_chat_response(
    messages, stream, websocket
    )

    if cost_callback:
    llm_costs = estimate_llm_cost(str(messages), response)
    cost_callback(llm_costs)

    return response

logging.error(f"Failed to get response from {llm_provider} API")
raise RuntimeError(f"Failed to get response from {llm_provider} API")`

注意到 return response 在第一次循环时直接退出了循环。
重现尝试的逻辑场景:即使 API 第一次调用失败,循环没有继续尝试,而是跳过后续逻辑。

Expected behavior
A clear and concise description of what you expected to happen.
循环应最多尝试 10 次调用 API,而不是在第一次调用后直接返回。期望逻辑如下:

如果前几次调用失败,循环会继续,直到达到最大尝试次数。
如果成功,返回 response。
如果所有尝试都失败,记录日志并引发异常。

@ElishaKay
Copy link
Collaborator

Welcome @6open

Green light for the PR

10 seems like a lot - how about 3 retries?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants