Eurico149 commited on
Commit
9defe9f
·
1 Parent(s): 77b3d53

feat: text summarization tool for supervisor agent

Browse files
Files changed (3) hide show
  1. app.py +3 -1
  2. tools/TextSummarizerTool.py +26 -0
  3. tools/__init__.py +1 -0
app.py CHANGED
@@ -6,6 +6,7 @@ from langgraph.checkpoint.memory import InMemorySaver
6
  from dotenv import load_dotenv
7
  from agents import get_book_retriver_agent
8
  from tools import get_retrieve_book_context_rag_agent_tool
 
9
 
10
 
11
  class GradioAgent:
@@ -37,7 +38,8 @@ class GradioAgent:
37
  rag_agent = get_book_retriver_agent()
38
 
39
  tools = [
40
- get_retrieve_book_context_rag_agent_tool(rag_agent)
 
41
  ]
42
 
43
  prompt = ("You are a helpful and usefull coordinator agent, you have access to a collection of tools and"
 
6
  from dotenv import load_dotenv
7
  from agents import get_book_retriver_agent
8
  from tools import get_retrieve_book_context_rag_agent_tool
9
+ from tools import get_summarization_tool
10
 
11
 
12
  class GradioAgent:
 
38
  rag_agent = get_book_retriver_agent()
39
 
40
  tools = [
41
+ get_retrieve_book_context_rag_agent_tool(rag_agent),
42
+ get_summarization_tool()
43
  ]
44
 
45
  prompt = ("You are a helpful and usefull coordinator agent, you have access to a collection of tools and"
tools/TextSummarizerTool.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from langchain_huggingface import HuggingFacePipeline
2
+ from transformers import pipeline
3
+ from langchain.tools import tool
4
+
5
+
6
+ def get_summarization_tool():
7
+
8
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
9
+ hf_summarizer = HuggingFacePipeline(pipeline=summarizer)
10
+
11
+ @tool
12
+ def summarize_tool(text: str) -> str:
13
+ """ Summarize a given text only if the user explicitly asks for a summary or if summarization is clearly required.
14
+
15
+ Args:
16
+ text: text to be summarized
17
+ """
18
+ sumirized_text = hf_summarizer.invoke(
19
+ text,
20
+ max_length=350,
21
+ min_length=50,
22
+ do_sample=False
23
+ )
24
+ return sumirized_text
25
+
26
+ return summarize_tool
tools/__init__.py CHANGED
@@ -1,2 +1,3 @@
1
  from .RetriveBooksDataTool import get_retrieve_book_context_tool
2
  from .BookRetriverRagAgent import get_retrieve_book_context_rag_agent_tool
 
 
1
  from .RetriveBooksDataTool import get_retrieve_book_context_tool
2
  from .BookRetriverRagAgent import get_retrieve_book_context_rag_agent_tool
3
+ from .TextSummarizerTool import get_summarization_tool