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

glm-4 multi-round session error reporting #5304

Closed
4 tasks done
cjdxhjj opened this issue Jun 17, 2024 · 2 comments
Closed
4 tasks done

glm-4 multi-round session error reporting #5304

cjdxhjj opened this issue Jun 17, 2024 · 2 comments
Labels
🐞 bug Something isn't working

Comments

@cjdxhjj
Copy link

cjdxhjj commented Jun 17, 2024

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.6.11

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

use glm-4 model, talk with llm several times

✔️ Expected Behavior

No response

❌ Actual Behavior

Got unknown type role=<PromptMessageRole.TOOL: 'tool'> content='{"code": "0", "errMsg": null, "data": [{"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3556, "indexName": "猪瘟", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3557, "indexName": "流感", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3558, "indexName": "猪口蹄疫", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3559, "indexName": "圆环病", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3560, "indexName": "猪伪狂犬病", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3561, "indexName": "蓝耳病", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3562, "indexName": "猪流行性腹泻", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3563, "indexName": "猪链球菌病", "indexValue": "0.6667", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3564, "indexName": "猪传染性胸膜肺炎", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3565, "indexName": "发病指数", "indexValue": "0.0000", "dataDate": "2024-06-02"}, {"catalogId": 106, "catalogName": "猪病发病指数", "indexId": 3592, "indexName": "发病指数", "indexValue": "0.66670000", "dataDate": "2024-06-02"}]}' name='get_aigcbasic_pighealth_widthdata_list_all' tool_call_id='95cdb6fe-5735-43bb-9461-3499c37147a3'

@dosubot dosubot bot added the 🐞 bug Something isn't working label Jun 17, 2024
Copy link

dosubot bot commented Jun 17, 2024

The error you're encountering, "Got unknown type role=<PromptMessageRole.TOOL: 'tool'>", indicates that the system is not recognizing the PromptMessageRole.TOOL type. This issue can be traced to the _convert_one_message_to_text function, which raises a ValueError when it encounters an unknown type.

To resolve this, ensure that the PromptMessageRole.TOOL type is correctly handled in the code. Here is the relevant part of the function that needs to be updated:

def _convert_one_message_to_text(self, message: PromptMessage) -> str:
    """
    Convert a single message to a string.

    :param message: PromptMessage to convert.
    :return: String representation of the message.
    """
    human_prompt = "\n\nuser:"
    ai_prompt = "\n\nmodel:"

    content = message.content
    if isinstance(content, list):
        content = "".join(
            c.data for c in content if c.type != PromptMessageContentType.IMAGE
        )

    if isinstance(message, UserPromptMessage):
        message_text = f"{human_prompt} {content}"
    elif isinstance(message, AssistantPromptMessage):
        message_text = f"{ai_prompt} {content}"
    elif isinstance(message, SystemPromptMessage):
        message_text = f"{human_prompt} {content}"
    elif isinstance(message, ToolPromptMessage):  # Ensure this case is handled
        message_text = f"{human_prompt} {content}"
    else:
        raise ValueError(f"Got unknown type {message}")

    return message_text

Make sure that the ToolPromptMessage type is properly defined and handled in your code. This should prevent the "unknown type" error from occurring during multi-round sessions [1].

To continue talking to Dosu, mention @dosu.

@crazywoola
Copy link
Member

See this PR #5245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants