cryogenic22 commited on
Commit
9f4320e
·
verified ·
1 Parent(s): b9a6c3b

Create modules/summarizer_module.py

Browse files
Files changed (1) hide show
  1. modules/summarizer_module.py +26 -0
modules/summarizer_module.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #modules/summarizer_module.py
2
+ from typing import Dict, List
3
+ from core.base_module import AIModule
4
+ from langchain import OpenAI
5
+
6
+ class SummarizerModule(AIModule):
7
+ def __init__(self, model_name: str = "gpt-3.5-turbo"):
8
+ self.model = OpenAI(model_name=model_name)
9
+
10
+ async def process(self, input_data: Dict) -> Dict:
11
+ text = input_data.get("text", "")
12
+ prompt = f"Please summarize the following text:\n\n{text}\n\nSummary:"
13
+ summary = self.model.predict(prompt)
14
+
15
+ return {
16
+ "summary": summary,
17
+ "original_length": len(text),
18
+ "summary_length": len(summary)
19
+ }
20
+
21
+ async def get_status(self) -> Dict:
22
+ return {"status": "operational"}
23
+
24
+ @property
25
+ def capabilities(self) -> List[str]:
26
+ return ["text-summarization", "length-reduction"]