Deprecations and outdated usage - FIX

#24
by NikeZoldyck - opened

BlenderBot is seq2seq, so use text2text-generation not text-generation or conversational, without chat templates as it expects raw text, not message dicts.

chatbot = pipeline(task="text2text-generation",
                   model="facebook/blenderbot-400M-distill")

user_message = "What are some fun activities I can do in the winter?"

result = chatbot(user_message, max_new_tokens=128)
print(result[0]["generated_text"])

HF removed/deprecated the Conversation class since most modern models use chat templates directly. For me, I found the simplest approach to be manual conversation tracking with string concatenation.

class SimpleConversation:
    """Lightweight conversation tracker for seq2seq models."""
    
    def __init__(self):
        self.history: list[dict[str, str]] = []
    
    def add_user_message(self, message: str) -> None:
        self.history.append({"role": "user", "content": message})
    
    def add_bot_response(self, response: str) -> None:
        self.history.append({"role": "assistant", "content": response})
    
    def get_context(self, max_turns: int = 3) -> str:
        """Concatenate recent turns into a single string for the model."""
        recent = self.history[-(max_turns * 2):]  # last N exchanges
        return " ".join(turn["content"] for turn in recent)
    
    def __repr__(self) -> str:
        return "\n".join(f"{t['role']}: {t['content']}" for t in self.history)

Usage:

convo = SimpleConversation()

First turn

convo.add_user_message("What are some fun activities I can do in the winter?")
response = chatbot(convo.get_context(), max_new_tokens=128)[0]["generated_text"]
convo.add_bot_response(response)
print(convo)

Continue conversation:

convo.add_user_message("What else do you recommend?")
response = chatbot(convo.get_context(), max_new_tokens=128)[0]["generated_text"]
convo.add_bot_response(response)
print(convo)

Sign up or log in to comment