Skip to content

[bug] RestrictToTopic validator occurs when disable_classifier is False and disable_llm is True #1192

Closed
@railsstudent

Description

@railsstudent

Describe the bug
When disable_classifier is False and disable_llm is True, the _inference_local method returns error on

candidate_topics = model_input["valid_topics"] + model_input["invalid_topics"]

The error message is

TypeError: unsupported operand type(s) for +: 'set' and 'set'

It is because

        valid_topics = set(metadata.get('valid_topics', self._valid_topics))
        invalid_topics = set(metadata.get('invalid_topics', self._invalid_topics))

return two sets and + operator cannot form a new array

To Reproduce
Steps to reproduce the behavior:

restrictToTopic = RestrictToTopic(
    valid_topics=["environment"],
    invalid_topics=["conspiracy", "food", "entertainment", "politics", "religion", "violence", "hate"],
    disable_classifier=False,
    disable_llm=True,
    on_fail=OnFailAction.EXCEPTION
)

result = restrictToTopic.validate(value="Large corporations should act responsibly socially and environmentally.  They should reduce carbon emission. One way to monitor their behavior is by reading their ESG Report.")
print(result.outcome)

Expected behavior
The _inference_local should return a found_topics array.

Library version:
Version 0.5.2

Additional context
Add any other context about the problem here.

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions