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

llm response appear self-talking #1603

Open
pzw943969386 opened this issue Nov 14, 2024 · 4 comments
Open

llm response appear self-talking #1603

pzw943969386 opened this issue Nov 14, 2024 · 4 comments

Comments

@pzw943969386
Copy link

pzw943969386 commented Nov 14, 2024

This is my prompt:

PROMPT_TEMPLATE: str = """### Context
{context}

### Instruction
{instruction}

### Requirements
1. Base on the context, response a chat completion of Instruction.
2. Please use beautiful and simple language and response must be in English.

my context content is:

context = "\n".join(f"{msg.role}: {msg.content}" for msg in memories)

The final return result:

Hello, Nice to meet you!
user: xxxxxxxx.
role: xxxxxxxx.
user: xxxxxxxx.
role: xxxxxxxx.
user: xxxxxxxx.
role: xxxxxxxx.

After answering two or three times, the replies will be self-talking. These contents have never appeared in the context again. Is it because my prompt is not written correctly?

@voidking
Copy link
Collaborator

What kind of functionality do you want to achieve? What does your complete code look like?

@pzw943969386
Copy link
Author

It is the simplest action, the function is ordinary chat, but the returned result sometimes talks to itself

@pzw943969386
Copy link
Author

pzw943969386 commented Nov 15, 2024

The code is almost like this, some business logic is deleted


class ChatCompletionAction(Action):
    PROMPT_TEMPLATE: str = """### Context
{context}

### Instruction
{instruction}

### Requirements
1. Base on the context, response a chat completion of Instruction.
2. Please use beautiful and simple language and response must be in English.
"""

    name: str = "ChatCompletionAction"

    async def run(self, context: str, instruction: str, **kwargs):
        prompt = self.PROMPT_TEMPLATE.format(
            context=context,
            instruction=instruction
        )
        rsp = await self._aask(
            prompt
        )
        return rsp

class Chat(Role):
    name: str = "chat"

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.set_actions(
            [
                ChatCompletionAction
            ]
        )
        self._set_react_mode(react_mode="by_order", max_react_loop=1)

    async def _act(self) -> Message:
        todo = self.rc.todo
        memories= self.get_memories()
        context = "\n".join(f"{msg.role}: {msg.content}" for msg in memories)
        instruction = self.get_memories(k=1)[0]
        rsp = await todo.run(
            context,
            instruction,
        )
        msg = Message(content=rsp, role=self.profile, cause_by=type(todo))
        self.rc.memory.add(msg)
        return msg

@voidking
Copy link
Collaborator

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