Using the jinareader tool, BUG in multi-round conversations #4021

Closed
opened 2026-02-21 18:04:27 -05:00 by yindo · 3 comments
Owner

Originally created by @burniceberg on GitHub (Jun 9, 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.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

0 1

✔️ Expected Behavior

No response

Actual Behavior

No response

Originally created by @burniceberg on GitHub (Jun 9, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.6.10 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce <img width="1276" alt="0" src="https://github.com/langgenius/dify/assets/72774035/92c128b1-cebf-4263-8887-b46c692bc566"> <img width="1275" alt="1" src="https://github.com/langgenius/dify/assets/72774035/833e7f45-db9d-4dfb-a497-f46b9028f0a9"> ### ✔️ Expected Behavior _No response_ ### ❌ Actual Behavior _No response_
yindo added the 🐞 bug label 2026-02-21 18:04:27 -05:00
yindo closed this issue 2026-02-21 18:04:27 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Jun 9, 2024):

Hello @burniceberg! I'm here to assist you with any bugs, questions, or contributions you might need help with. Let's work together to resolve the issue you're facing!

To resolve the "unknown type role" error related to PromptMessageRole.TOOL in multi-round conversations using the JinaReader tool, ensure the following:

  1. Enum Definition: Verify that the PromptMessageRole enum includes the TOOL type. The definition should look like this:

    class PromptMessageRole(Enum):
        SYSTEM = "system"
        USER = "user"
        ASSISTANT = "assistant"
        TOOL = "tool"
    
        @classmethod
        def value_of(cls, value: str) -> 'PromptMessageRole':
            for mode in cls:
                if mode.value == value:
                    return mode
            raise ValueError(f'invalid prompt message type value {value}')
    
  2. ToolPromptMessage Class: Ensure that the ToolPromptMessage class is correctly defined and used in your code:

    class ToolPromptMessage(PromptMessage):
        role: PromptMessageRole = PromptMessageRole.TOOL
        tool_call_id: str
    
        def is_empty(self) -> bool:
            if not super().is_empty() and not self.tool_call_id:
                return False
            return True
    
  3. PromptMessageUtil Class: Make sure the PromptMessageUtil class handles the TOOL role correctly when converting prompt messages for saving:

    class PromptMessageUtil:
        @staticmethod
        def prompt_messages_to_prompt_for_saving(model_mode: str, prompt_messages: list[PromptMessage]) -> list[dict]:
            prompts = []
            if model_mode == ModelMode.CHAT.value:
                tool_calls = []
                for prompt_message in prompt_messages:
                    if prompt_message.role == PromptMessageRole.USER:
                        role = 'user'
                    elif prompt_message.role == PromptMessageRole.ASSISTANT:
                        role = 'assistant'
                        if isinstance(prompt_message, AssistantPromptMessage):
                            tool_calls = [{
                                'id': tool_call.id,
                                'type': 'function',
                                'function': {
                                    'name': tool_call.function.name,
                                    'arguments': tool_call.function.arguments,
                                }
                            } for tool_call in prompt_message.tool_calls]
                    elif prompt_message.role == PromptMessageRole.SYSTEM:
                        role = 'system'
                    elif prompt_message.role == PromptMessageRole.TOOL:
                        role = 'tool'
                    else:
                        continue
                    text = ''
                    files = []
                    if isinstance(prompt_message.content, list):
                        for content in prompt_message.content:
                            if content.type == PromptMessageContentType.TEXT:
                                content = cast(TextPromptMessageContent, content)
                                text += content.data
                            else:
                                content = cast(ImagePromptMessageContent, content)
                                files.append({
                                    "type": 'image',
                                    "data": content.data[:10] + '...[TRUNCATED]...' + content.data[-10:],
                                    "detail": content.detail.value
                                })
                    else:
                        text = prompt_message.content
    
                    prompt = {
                        "role": role,
                        "text": text,
                        "files": files
                    }
    
                    if tool_calls:
                        prompt['tool_calls'] = tool_calls
    
                    prompts.append(prompt)
            else:
                prompt_message = prompt_messages[0]
                text = ''
                files = []
                if isinstance(prompt_message.content, list):
                    for content in prompt_message.content:
                        if content.type == PromptMessageContentType.TEXT:
                            content = cast(TextPromptMessageContent, content)
                            text += content.data
                        else:
                            content = cast(ImagePromptMessageContent, content)
                            files.append({
                                "type": 'image',
                                "data": content.data[:10] + '...[TRUNCATED]...' + content.data[-10:],
                                "detail": content.detail.value
                            })
                else:
                    text = prompt_message.content
                params = {
                    "role": 'user',
                    "text": text,
                }
    
                if files:
                    params['files'] = files
    
                prompts.append(params)
    
            return prompts
    

These steps should help resolve the "unknown type role" error in your multi-round conversations with the JinaReader tool [1][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Jun 9, 2024): <!-- Greeting --> Hello @burniceberg! I'm here to assist you with any bugs, questions, or contributions you might need help with. Let's work together to resolve the issue you're facing! <!-- Answer --> To resolve the "unknown type role" error related to `PromptMessageRole.TOOL` in multi-round conversations using the JinaReader tool, ensure the following: 1. **Enum Definition**: Verify that the `PromptMessageRole` enum includes the `TOOL` type. The definition should look like this: ```python class PromptMessageRole(Enum): SYSTEM = "system" USER = "user" ASSISTANT = "assistant" TOOL = "tool" @classmethod def value_of(cls, value: str) -> 'PromptMessageRole': for mode in cls: if mode.value == value: return mode raise ValueError(f'invalid prompt message type value {value}') ``` 2. **ToolPromptMessage Class**: Ensure that the `ToolPromptMessage` class is correctly defined and used in your code: ```python class ToolPromptMessage(PromptMessage): role: PromptMessageRole = PromptMessageRole.TOOL tool_call_id: str def is_empty(self) -> bool: if not super().is_empty() and not self.tool_call_id: return False return True ``` 3. **PromptMessageUtil Class**: Make sure the `PromptMessageUtil` class handles the `TOOL` role correctly when converting prompt messages for saving: ```python class PromptMessageUtil: @staticmethod def prompt_messages_to_prompt_for_saving(model_mode: str, prompt_messages: list[PromptMessage]) -> list[dict]: prompts = [] if model_mode == ModelMode.CHAT.value: tool_calls = [] for prompt_message in prompt_messages: if prompt_message.role == PromptMessageRole.USER: role = 'user' elif prompt_message.role == PromptMessageRole.ASSISTANT: role = 'assistant' if isinstance(prompt_message, AssistantPromptMessage): tool_calls = [{ 'id': tool_call.id, 'type': 'function', 'function': { 'name': tool_call.function.name, 'arguments': tool_call.function.arguments, } } for tool_call in prompt_message.tool_calls] elif prompt_message.role == PromptMessageRole.SYSTEM: role = 'system' elif prompt_message.role == PromptMessageRole.TOOL: role = 'tool' else: continue text = '' files = [] if isinstance(prompt_message.content, list): for content in prompt_message.content: if content.type == PromptMessageContentType.TEXT: content = cast(TextPromptMessageContent, content) text += content.data else: content = cast(ImagePromptMessageContent, content) files.append({ "type": 'image', "data": content.data[:10] + '...[TRUNCATED]...' + content.data[-10:], "detail": content.detail.value }) else: text = prompt_message.content prompt = { "role": role, "text": text, "files": files } if tool_calls: prompt['tool_calls'] = tool_calls prompts.append(prompt) else: prompt_message = prompt_messages[0] text = '' files = [] if isinstance(prompt_message.content, list): for content in prompt_message.content: if content.type == PromptMessageContentType.TEXT: content = cast(TextPromptMessageContent, content) text += content.data else: content = cast(ImagePromptMessageContent, content) files.append({ "type": 'image', "data": content.data[:10] + '...[TRUNCATED]...' + content.data[-10:], "detail": content.detail.value }) else: text = prompt_message.content params = { "role": 'user', "text": text, } if files: params['files'] = files prompts.append(params) return prompts ``` These steps should help resolve the "unknown type role" error in your multi-round conversations with the JinaReader tool <sup>[[1]](https://github.com/langgenius/dify/blob/main/api/core/model_runtime/entities/message_entities.py)</sup><sup>[[2]](https://github.com/langgenius/dify/blob/main/api/core/prompt/utils/prompt_message_util.py)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@sinomoe commented on GitHub (Jun 15, 2024):

the issue has been fixed in #5245

@sinomoe commented on GitHub (Jun 15, 2024): the issue has been fixed in #5245
Author
Owner

@ghost commented on GitHub (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.10

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

0 1

✔️ Expected Behavior

No response

Actual Behavior

No response

@ghost commented on GitHub (Jun 17, 2024): > ### Self Checks > * [x] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). > * [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. > * [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). > * [x] Please do not modify this template :) and fill in all the required fields. > > ### Dify version > 0.6.10 > > ### Cloud or Self Hosted > Self Hosted (Docker) > > ### Steps to reproduce > <img alt="0" width="1276" src="https://private-user-images.githubusercontent.com/72774035/338030103-92c128b1-cebf-4263-8887-b46c692bc566.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg2MTE0NzMsIm5iZiI6MTcxODYxMTE3MywicGF0aCI6Ii83Mjc3NDAzNS8zMzgwMzAxMDMtOTJjMTI4YjEtY2ViZi00MjYzLTg4ODctYjQ2YzY5MmJjNTY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE3VDA3NTkzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQyMDYzOWQ5NTM0ZjBjZDQ3YzIyOWNhNjEyZjRlNDdkZTRiNGE4ZTM0MzkzMzIyNTIzYTA5MDc2MTdlOWNhNzUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.AC8n07pfH7oXZ3LsMyfxvjFpb1IicwxeSD3-3yKw0yw"> <img alt="1" width="1275" src="https://private-user-images.githubusercontent.com/72774035/338030118-833e7f45-db9d-4dfb-a497-f46b9028f0a9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTg2MTE0NzMsIm5iZiI6MTcxODYxMTE3MywicGF0aCI6Ii83Mjc3NDAzNS8zMzgwMzAxMTgtODMzZTdmNDUtZGI5ZC00ZGZiLWE0OTctZjQ2YjkwMjhmMGE5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA2MTclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNjE3VDA3NTkzM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQzZmNkNWVhMmI4NDNkOTZjNDUzOTVkMTUzYzNjZWJlMjU5MGUzODg2MGZhNmQ3ODUwZTQxMmU0NzRhZTFiZGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.RQ6ubt4yLfS25LsppdKQ_HPv4YZpU2RqvZsA9XjUKKg"> > ### ✔️ Expected Behavior > _No response_ > > ### ❌ Actual Behavior > _No response_
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#4021