Find answers from the community

Updated 2 months ago

Using An Extractor To Extract Sentiment From Nodes

At a glance

The community member is trying to use a SentimentExtractor class that inherits from BaseExtractor, but is encountering an error where the SentimentExtractor object has no field named "me". The community members suggest that the SentimentExtractor should be defined as a pydantic class with proper fields, or the super().__init__() method should be called before accessing self. The community members provide a solution where the SentimentExtractor class is defined with a me field, and an instance of the class is created with the me parameter. There is no explicitly marked answer in the comments.

Help: I'm trying to use an Extractor as so:

class SentimentExtractor(BaseExtractor): def __init__(self, me, str): print("here") self.me = me self.str = str async def aextract(self, nodes: Sequence) -> List[Dict]: metadata_list = [] for node in nodes: generated_sentiment = {"sentiment": "Positive"} # Replace with actual LLM call metadata_list.append(generated_sentiment) return metadata_list

when I instanciate the class
sentiment_extractor = SentimentExtractor(me = "zsdfsadf", str="hello")

I get errors:
ValueError: "SentimentExtractor" object has no field "me"

If I define my own BaseExtractor just as a replacement, I don't get the error

I'm trying to actually pass in an LLM and custom prompt to extract the sentiment out of nodes and add to the metadata but seem to be running into something odd. Anything with dependencies?
L
S
5 comments
Its a pydantic class, you should either define proper pydantic fields, or use super().__init__() before accessing self
Thanks, I just tried that but it didn't work and got the same error
mmm more pydantic goodness probably
Lets use proper pydantic field-defs

Plain Text
class SentimentExtractor(BaseExtractor):
    me: str    

    async def aextract(self, nodes: Sequence) -> List[Dict]:
        metadata_list = []
        for node in nodes:
            generated_sentiment = {"sentiment": "Positive"}  # Replace with actual LLM call
            metadata_list.append(generated_sentiment)
        return metadata_list

extractor = SentimentExtractor(me="zsdfsadf")
One more question, do you know that You Da Man?
Thanks for your help!
Add a reply
Sign up and join the conversation on Discord