Find answers from the community

Updated 3 days ago

Using An Extractor To Extract Sentiment From Nodes

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