Mehedi2 commited on
Commit
2c13064
·
verified ·
1 Parent(s): 2eda349

Update tools/summarizer.py

Browse files
Files changed (1) hide show
  1. tools/summarizer.py +13 -15
tools/summarizer.py CHANGED
@@ -1,21 +1,19 @@
1
  from smolagents import tool
2
- from transformers import pipeline
3
-
4
- # load once globally (uses a small summarization model from Hugging Face)
5
- summarizer_pipeline = pipeline("summarization", model="facebook/bart-large-cnn")
6
 
7
  @tool
8
  def summarizer(text: str, max_length: int = 100, min_length: int = 30) -> str:
9
- """Summarize a long piece of text into a shorter version.
10
  Args:
11
- text: The text that needs to be summarized.
12
- max_length: Maximum length of the summary.
13
- min_length: Minimum length of the summary.
14
  """
15
- try:
16
- summary = summarizer_pipeline(
17
- text, max_length=max_length, min_length=min_length, do_sample=False
18
- )
19
- return summary[0]["summary_text"]
20
- except Exception as e:
21
- return f"Error during summarization: {str(e)}"
 
 
 
1
  from smolagents import tool
 
 
 
 
2
 
3
  @tool
4
  def summarizer(text: str, max_length: int = 100, min_length: int = 30) -> str:
5
+ """Summarize a long piece of text into a shorter version using the agent's own LLM.
6
  Args:
7
+ text: The text to be summarized.
8
+ max_length: Maximum length of the summary (approximate).
9
+ min_length: Minimum length of the summary (approximate).
10
  """
11
+ # Here we don’t call transformers — just ask the model to summarize
12
+ prompt = (
13
+ f"Summarize the following text into a clear and concise version:\n\n"
14
+ f"{text}\n\n"
15
+ f"Constraints: summary should be between {min_length} and {max_length} words."
16
+ )
17
+ # The agent will handle this prompt automatically
18
+ return prompt
19
+