DEV Community

Smile Tech
Smile Tech

Posted on

GenLayer AI Tutorial: Python Sentiment Analysis

πŸš€ Build an AI Sentiment Analyzer on GenLayer

GenLayer allows smart contracts to use LLMs through decentralized consensus. Here is how to build a Sentiment Analyzer.

🐍 The Contract


python
# { "Depends": "py-genlayer:test" }
from genlayer import *

@gl.contract
class SentimentAnalyzer:
    last_analysis: str
    def __init__(self):
        self.last_analysis = "Empty"

    @gl.public.write
    def analyze(self, text: str) -> str:
        self.last_analysis = gl.call_llm(f"Sentiment of: {text}")
        return self.last_analysis
Enter fullscreen mode Exit fullscreen mode

Top comments (0)