Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot find self defined plugin when executing code #423

Open
irmowan opened this issue Oct 7, 2024 · 1 comment
Open

Cannot find self defined plugin when executing code #423

irmowan opened this issue Oct 7, 2024 · 1 comment

Comments

@irmowan
Copy link

irmowan commented Oct 7, 2024

I write a plugin under my project/plugins folder:

from taskweaver.plugin import Plugin, register_plugin
from typing import List
try:
    from snownlp import SnowNLP
except ImportError:
    raise ImportError("Please install snownlp with `pip install snownlp`")


@register_plugin
class SentimentAnalysis(Plugin):
    def _init(self) -> None:
        pass

    def sentiment_to_score(self, sentiment: float) -> int:
        """Map (0,1) to 1-5
        """
        return int(sentiment  * 5) + 1

    def __call__(self, inputs: List[str]):
        results = []
        for review in inputs:
            s = SnowNLP(review)
            rating = self.sentiment_to_score(s.sentiments)
            results.append(rating)
        return results    

Here is the yaml file:

name: sentiment_analysis
enabled: true
required: false
description: >-
  sentiment_analysis processes a list of text inputs and assigns a sentiment score from 1 to 5, based on the polarity of the text.
examples:
  sentiment_scores = sentiment_analysis(["Very good product", "Bad quality", "A little noisy"])

parameters:
  - name: inputs
    type: list
    required: true
    description: >-
      A list of sentences to be analyzed for sentiment polarity.

returns:
  - name: sentiment_scores
    type: list
    description: >-
      A list of sentiment scores (from 1 to 5, integer) for each input string, based on the analysis.

However, the taskweaver cannot find this plugin:
image

This is the folder structure.
image

@liqul
Copy link
Contributor

liqul commented Oct 9, 2024

The symptom suggests that TaskWeaver can find your plugin (because the code had been generated correctly), but calling it led to an error. Please first check the FAQ here to see if the problem can be fixed. There is also a way of debugging the plugin in the FAQ.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants