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
50.35k stars 7.22k forks source link

Use API to call dify workflow, error 500 since v0.10.1 #9866

Open songleipu123 opened 1 week ago

songleipu123 commented 1 week ago

Self Checks

Dify version

v0.10.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

  1. use API:data = { "query": query, "inputs": {}, # 如果有其他输入变量,可以在这里添加 "response_mode": "blocking",
    "user": user_id, "conversation_id": conversation_id } headers = { 'Authorization': f'Bearer {self.api_key}', 'Content-Type': 'application/json' } url = f"{self.api_base}/chat-messages" response = requests.post(url, headers=headers, data=json.dumps(data), proxies=self.proxy)
  2. return: Error: {"code": "internal_server_error", "message": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.", "status": 500}
  3. check api log:
   2024-10-25 08:56:13,673.673 WARNING [Thread-24 (_process_future)] [app_generator_tts_publisher.py:42] - Failed to speech the text, detail: [address=0.0.0.0:40239, pid=1708] Parallel generation is not supported by llama-cpp-python.

2024-10-25 08:56:13,713.713 ERROR [Dummy-22] [completion.py:139] - internal server error.

Traceback (most recent call last):

  File "/app/api/controllers/service_api/app/completion.py", line 116, in post

    response = AppGenerateService.generate(

  File "/app/api/services/app_generate_service.py", line 68, in generate

    AdvancedChatAppGenerator().generate(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 146, in generate

    return self._generate(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 263, in _generate

    response = self._handle_advanced_chat_response(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 363, in _handle_advanced_chat_response

    return generate_task_pipeline.process()

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 147, in process

    return self._to_blocking_response(generator)

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 154, in _to_blocking_response

    for stream_response in generator:

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 219, in _wrapper_process_stream_response

    audio_response = self._listen_audio_msg(tts_publisher, task_id=task_id)

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 198, in _listen_audio_msg

    if audio_msg and audio_msg.status != "finish":

  File "/app/api/.venv/lib/python3.10/site-packages/pydantic/main.py", line 856, in __getattr__

    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')

AttributeError: 'MessageQueueMessage' object has no attribute 'status'

2024-10-25 08:56:13,717.717 ERROR [Dummy-22] [app.py:838] - Exception on /v1/chat-messages [POST]

Traceback (most recent call last):

  File "/app/api/controllers/service_api/app/completion.py", line 116, in post

    response = AppGenerateService.generate(

  File "/app/api/services/app_generate_service.py", line 68, in generate

    AdvancedChatAppGenerator().generate(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 146, in generate

    return self._generate(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 263, in _generate

    response = self._handle_advanced_chat_response(

  File "/app/api/core/app/apps/advanced_chat/app_generator.py", line 363, in _handle_advanced_chat_response

    return generate_task_pipeline.process()

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 147, in process

    return self._to_blocking_response(generator)

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 154, in _to_blocking_response

    for stream_response in generator:

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 219, in _wrapper_process_stream_response

    audio_response = self._listen_audio_msg(tts_publisher, task_id=task_id)

  File "/app/api/core/app/apps/advanced_chat/generate_task_pipeline.py", line 198, in _listen_audio_msg

    if audio_msg and audio_msg.status != "finish":

  File "/app/api/.venv/lib/python3.10/site-packages/pydantic/main.py", line 856, in __getattr__

    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')

AttributeError: 'MessageQueueMessage' object has no attribute 'status'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request

    rv = self.dispatch_request()

  File "/app/api/.venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request

    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]

  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 489, in wrapper

    resp = resource(*args, **kwargs)

  File "/app/api/.venv/lib/python3.10/site-packages/flask/views.py", line 110, in view

    return current_app.ensure_sync(self.dispatch_request)(**kwargs)  # type: ignore[no-any-return]

  File "/app/api/.venv/lib/python3.10/site-packages/flask_restful/__init__.py", line 604, in dispatch_request

    resp = meth(*args, **kwargs)

  File "/app/api/controllers/service_api/wraps.py", line 76, in decorated_view

    return view_func(*args, **kwargs)

  File "/app/api/controllers/service_api/app/completion.py", line 140, in post

    raise InternalServerError()

werkzeug.exceptions.InternalServerError: 500 Internal Server Error: The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.

✔️ Expected Behavior

Use API to call dify workflow can normally run

❌ Actual Behavior

Error: {"code": "internal_server_error", "message": "The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.", "status": 500}

dosubot[bot] commented 1 week ago

@songleipu123 Hello there! I'm here to help you with any bugs, questions, or contributions you have with the Dify project. If you need assistance, feel free to ask.

I found a similar issue related to a 500 Internal Server Error when using the Dify API. In Dify version v0.10.1, there was a change where the image upload feature was replaced with a more comprehensive file upload feature. This change might affect workflows that previously relied on the sys.files variable, as it has been marked as LEGACY and is set to be deprecated [1][2].

Additionally, the error you're encountering with the MessageQueueMessage class seems to be due to a missing status attribute. The MessageQueueMessage class should have attributes like task_id, message_id, conversation_id, app_mode, and event, but not status [3].

To resolve this issue, you might need to check the implementation of the MessageQueueMessage class and ensure it aligns with the expected attributes. Also, review any recent changes in the API workflow related to file uploads and adjust your implementation accordingly.

To continue talking to Dosu, mention @dosu.

songleipu123 commented 1 week ago

@songleipu123 Hello there! I'm here to help you with any bugs, questions, or contributions you have with the Dify project. If you need assistance, feel free to ask.

I found a similar issue related to a 500 Internal Server Error when using the Dify API. In Dify version v0.10.1, there was a change where the image upload feature was replaced with a more comprehensive file upload feature. This change might affect workflows that previously relied on the sys.files variable, as it has been marked as LEGACY and is set to be deprecated [1][2].

Additionally, the error you're encountering with the MessageQueueMessage class seems to be due to a missing status attribute. The MessageQueueMessage class should have attributes like task_id, message_id, conversation_id, app_mode, and event, but not status [3].

To resolve this issue, you might need to check the implementation of the MessageQueueMessage class and ensure it aligns with the expected attributes. Also, review any recent changes in the API workflow related to file uploads and adjust your implementation accordingly.

To continue talking to Dosu, mention @dosu.

I use workflow's backup, It can normally running , didn't Report the same error... and I checked backup' setting detail , is the same , I don't know why and what problem in current workflow

lokiwizard commented 1 week ago

I encouter the similar problem. However, I try to remove the dify-api-0.10.1 image and pull the image again, this problem can be solved.

laipz8200 commented 6 days ago

Try deleting the image and pulling it again.