File size: 855 Bytes
9f4320e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#modules/summarizer_module.py
from typing import Dict, List
from core.base_module import AIModule
from langchain import OpenAI

class SummarizerModule(AIModule):
    def __init__(self, model_name: str = "gpt-3.5-turbo"):
        self.model = OpenAI(model_name=model_name)
    
    async def process(self, input_data: Dict) -> Dict:
        text = input_data.get("text", "")
        prompt = f"Please summarize the following text:\n\n{text}\n\nSummary:"
        summary = self.model.predict(prompt)
        
        return {
            "summary": summary,
            "original_length": len(text),
            "summary_length": len(summary)
        }
    
    async def get_status(self) -> Dict:
        return {"status": "operational"}
    
    @property
    def capabilities(self) -> List[str]:
        return ["text-summarization", "length-reduction"]