langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.16k stars 7.37k forks source link

Error when I using the [zhipuai] LLM in the workflow. #8566

Closed albert9yang closed 1 month ago

albert9yang commented 1 month ago

Self Checks

Dify version

0.8.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

1.Create any new workflow, 2.Use the configured [zhipuai] large model (this large model has been verified to be usable in the chatbot), 3.An error occurs during runtime. [zhipuai] Error: RetryError[<Future at 0x7fed8d8abac0 state=finished raised APIRequestFailedError>]

image

✔️ Expected Behavior

I expect the workflow to run normally.

❌ Actual Behavior

The result is an error.

[zhipuai] Error: RetryError[<Future at 0x7fed8d8abac0 state=finished raised APIRequestFailedError>]

dosubot[bot] commented 1 month ago

Hello @13939060358! 👋 I'm here to assist you with any bugs, questions, or contributions you have for the project. I'm Dosu, a bot designed to help you out while you wait for a human maintainer. Let's squash those bugs together!

I found a similar solved discussion that might help you with the issue you're facing:

  1. 调用智谱AI出错问题,聊天助手类型中工作流编排可用,但使用工作流类型就报错。 - This discussion addresses a similar error when using the [zhipuai] LLM in a workflow. The solution involved ensuring that the user role is added to the message, as having only the system role can cause issues [1].

To resolve the RetryError[<Future at 0x7fed8d8abac0 state=finished raised APIRequestFailedError>] when using the [zhipuai] LLM in a self-hosted Dify 0.8.2 workflow, you can adjust the retry settings and ensure proper error handling in the HttpClient class. Specifically, you can increase the number of retry attempts or adjust the timeout settings.

Here is the relevant code snippet from the HttpClient class that shows how retries are configured:

from tenacity import retry
from tenacity.stop import stop_after_attempt

ZHIPUAI_DEFAULT_MAX_RETRIES = 3

@retry(stop=stop_after_attempt(ZHIPUAI_DEFAULT_MAX_RETRIES))
def request(
    self,
    *,
    cast_type: type[ResponseT],
    params: ClientRequestParam,
    enable_stream: bool = False,
    stream_cls: type[StreamResponse[Any]] | None = None,
) -> ResponseT | StreamResponse:
    request = self._prepare_request(params)

    try:
        response = self._client.send(
            request,
            stream=enable_stream,
        )
        response.raise_for_status()
    except httpx.TimeoutException as err:
        raise APITimeoutError(request=request) from err
    except httpx.HTTPStatusError as err:
        err.response.read()
        raise self._make_status_error(err.response) from None
    except Exception as err:
        raise err

    return self._parse_response(
        cast_type=cast_type,
        request_param=params,
        response=response,
        enable_stream=enable_stream,
        stream_cls=stream_cls,
    )

To increase the number of retry attempts, you can modify the ZHIPUAI_DEFAULT_MAX_RETRIES value:

ZHIPUAI_DEFAULT_MAX_RETRIES = 5  # Increase the number of retries

Additionally, you can adjust the timeout settings to ensure that the requests have sufficient time to complete:

ZHIPUAI_DEFAULT_TIMEOUT = httpx.Timeout(timeout=600.0, connect=8.0)  # Increase the timeout duration

By increasing the retry attempts and adjusting the timeout settings, you can mitigate the RetryError and improve the reliability of your requests to the [zhipuai] LLM [2].

To continue talking to Dosu, mention @dosu.

albert9yang commented 1 month ago

Hello,[dosubot],https://github.com/langgenius/dify/discussions/3579#discussioncomment-10155286 -This issue is different from my question. The specific error is different. Thank you for providing the information, but the information you provided cannot solve my problem. Please ask a real person to help solve it. Thank you very much.

QiongsK commented 1 month ago

@albert9yang I have the same question when I use zhipu api. Then I found that if I only set system prompt, it will occur an error. But if I set user prompt at same time, it's running well.