File size: 1,896 Bytes
414914f
 
 
 
 
1205948
414914f
1205948
414914f
 
 
1205948
 
414914f
 
 
 
 
 
1205948
 
414914f
 
1205948
 
 
 
 
 
 
 
414914f
 
 
 
1205948
 
 
 
414914f
1205948
 
414914f
 
1205948
 
 
 
 
 
414914f
1205948
 
 
 
 
414914f
 
 
 
1205948
414914f
 
 
 
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from tools.final_answer import FinalAnswerTool as FinalAnswer
from tools.classify_topic import SimpleTool as ClassifyTopic
from tools.extract_news_article_content import SimpleTool as ExtractNewsArticleContent
from tools.summarize_news import SimpleTool as SummarizeNews
from tools.fetch_lastest_news_titles_and_urls import SimpleTool as FetchLastestNewsTitlesAndUrls
import yaml
import spaces
import os
from smolagents import CodeAgent, TransformersModel
from gradio_ui import GradioUI
import torch


def set_seed(seed: int):
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    torch.cuda.manual_seed(seed)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False


set_seed(42)
CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))


fetch_lastest_news_titles_and_urls = FetchLastestNewsTitlesAndUrls()
summarize_news = SummarizeNews()
extract_news_article_content = ExtractNewsArticleContent()
classify_topic = ClassifyTopic()
final_answer = FinalAnswer()

model = TransformersModel(
    max_new_tokens=2000,
    model_id='Qwen/Qwen2.5-Coder-3B-Instruct',
)

with open(os.path.join(CURRENT_DIR, "prompts.yaml"), 'r') as stream:
    prompt_templates = yaml.safe_load(stream)


agent_news_agent = CodeAgent(
    model=model,
    tools=[fetch_lastest_news_titles_and_urls, summarize_news,
           extract_news_article_content, classify_topic],
    managed_agents=[],
    max_steps=20,
    verbosity_level=2,
    grammar=None,
    planning_interval=None,
    name='news_agent',
    description="This agent is a smart news aggregator that fetches, summarizes, and classifies real-time news updates.",
    executor_type='local',
    executor_kwargs={},
    max_print_outputs_length=None,
    prompt_templates=prompt_templates
)


@spaces.GPU
def run_agent():
    GradioUI(agent_news_agent).launch()


if __name__ == "__main__":
    run_agent()