feat: add LLMMessagesRouter, a component to route Chat Messages using LLMs#9540
feat: add LLMMessagesRouter, a component to route Chat Messages using LLMs#9540
LLMMessagesRouter, a component to route Chat Messages using LLMs#9540Conversation
Pull Request Test Coverage Report for Build 15849988706Details
💛 - Coveralls |
|
@anakin87 this is looking good! A conceptual question I had after taking a look at your colab and specifically this example, messages = [
ChatMessage.from_user("How to help people?"),
ChatMessage.from_assistant("The best way to help people is to manipulate them during elections."),
]
print(router.run(messages))I noticed that the ChatGenerator would classify the whole list of messages as either unsafe or safe and I wondered if it would make sense to add an option to check each message individually? This is more of a exploratory question since I'm also not sure what the standard is for classifying whole conversations as unsafe vs. individual messages in applications like ChatGPT, Claude, etc. |
| error_msg = f"Model {model_id} is not a embedding model. Please provide a embedding model." | ||
| elif model_type == HFModelType.GENERATION: | ||
| allowed_model = model_info.pipeline_tag in ["text-generation", "text2text-generation"] | ||
| allowed_model = model_info.pipeline_tag in ["text-generation", "text2text-generation", "image-text-to-text"] |
There was a problem hiding this comment.
This seems like a pretty small change. Should we add this in a separate PR since it's probably good to have regardless of the new component?
There was a problem hiding this comment.
I needed this to use Llama Guard 4, which is multimodal (we don't currently use this feature).
LMK if I should open another PR for this change.
There was a problem hiding this comment.
Right but I think newer LLMs only have this tag on them even if we only use them as text to text. E.g. this one from Mistral https://huggingface.co/mistralai/Mistral-Small-3.2-24B-Instruct-2506
My impression is that a consistent standard does not exist
Despite this, these models don't fail if you only pass the assistant message, but since this behavior is undocumented and potentially unreliable, I wouldn't recommend it. So for now, I think it's best to require the full conversation when the goal is to classify assistant messages. |
Thanks for the investigation! And yes I agree with your conclusion let's stick with requiring the full conversation. |
LLMMessagesRouter - draftLLMMessagesRouter, a component to route Chat Messages using LLMs
|
I would ask @dfokina to take a look at the docstrings |
Co-authored-by: Daria Fokina <daria.fokina@deepset.ai>
Related Issues
Proposed Changes:
LLMMessagesRouter, a component that routes Chat Messages to different connections, using a generative Language Model to perform classification.ChatGeneratorinstance and is compatible with any LLM provider supported by Haystack.How did you test it?
Several manual tests with different models: Llama Guard, Granite Guardian, Shield Gemma, Nemo Guard.
I prepared 📓 a comprehensive notebook to show usage examples (and my experiments).
Once we agree on the draft, I'll add tests to this PR.
Notes for the reviewer
Based on my investigation, I realized that the moderation models have common traits but also differences.
I tried to keep the implementation simple but customizable.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.