Fix circular import by moving DuckDuckGoSearchTool to separate module
Browse files- app.py +6 -5
- tools/blog_tools.py +2 -2
- tools/search_tools.py +9 -0
app.py
CHANGED
@@ -1,10 +1,11 @@
|
|
1 |
-
from smolagents import CodeAgent,
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from tools.blog_tools import generate_blog_section, improve_writing_style, check_readability, generate_seo_metadata
|
|
|
8 |
from Gradio_UI import GradioUI
|
9 |
|
10 |
@tool
|
@@ -15,7 +16,7 @@ def generate_blog_outline(topic: str) -> str:
|
|
15 |
"""
|
16 |
try:
|
17 |
# Research the topic first
|
18 |
-
search_tool =
|
19 |
research = search_tool.forward(f"{topic} key aspects challenges solutions")
|
20 |
|
21 |
# Create an outline based on research and expertise
|
@@ -48,7 +49,7 @@ def suggest_blog_topics(main_theme: str) -> str:
|
|
48 |
"""
|
49 |
try:
|
50 |
# Research current trends
|
51 |
-
search_tool =
|
52 |
research = search_tool.forward(f"{main_theme} latest developments challenges")
|
53 |
|
54 |
# Generate topic suggestions based on research and expertise
|
@@ -90,10 +91,10 @@ def research_topic(query: str) -> str:
|
|
90 |
"""
|
91 |
try:
|
92 |
# Create a fresh instance for each search
|
93 |
-
search_tool =
|
94 |
|
95 |
# Add focus on tech and AI product development
|
96 |
-
enhanced_query = f"{query} AI product development"
|
97 |
results = search_tool.forward(enhanced_query)
|
98 |
|
99 |
# Format the results in your style
|
|
|
1 |
+
from smolagents import CodeAgent, HfApiModel, load_tool, tool
|
2 |
import datetime
|
3 |
import requests
|
4 |
import pytz
|
5 |
import yaml
|
6 |
from tools.final_answer import FinalAnswerTool
|
7 |
from tools.blog_tools import generate_blog_section, improve_writing_style, check_readability, generate_seo_metadata
|
8 |
+
from tools.search_tools import get_search_tool
|
9 |
from Gradio_UI import GradioUI
|
10 |
|
11 |
@tool
|
|
|
16 |
"""
|
17 |
try:
|
18 |
# Research the topic first
|
19 |
+
search_tool = get_search_tool(max_results=2)
|
20 |
research = search_tool.forward(f"{topic} key aspects challenges solutions")
|
21 |
|
22 |
# Create an outline based on research and expertise
|
|
|
49 |
"""
|
50 |
try:
|
51 |
# Research current trends
|
52 |
+
search_tool = get_search_tool(max_results=2)
|
53 |
research = search_tool.forward(f"{main_theme} latest developments challenges")
|
54 |
|
55 |
# Generate topic suggestions based on research and expertise
|
|
|
91 |
"""
|
92 |
try:
|
93 |
# Create a fresh instance for each search
|
94 |
+
search_tool = get_search_tool(max_results=3)
|
95 |
|
96 |
# Add focus on tech and AI product development
|
97 |
+
enhanced_query = f"{query} AI product development"
|
98 |
results = search_tool.forward(enhanced_query)
|
99 |
|
100 |
# Format the results in your style
|
tools/blog_tools.py
CHANGED
@@ -2,7 +2,7 @@ from smolagents import tool
|
|
2 |
from typing import List, Dict
|
3 |
import re
|
4 |
import yaml
|
5 |
-
from
|
6 |
|
7 |
# Load style guide
|
8 |
with open("style_guide.yaml", 'r') as f:
|
@@ -21,7 +21,7 @@ def generate_blog_section(topic: str, section_title: str) -> str:
|
|
21 |
section_title: The title of the section to generate
|
22 |
"""
|
23 |
# First, get some background information
|
24 |
-
search_tool =
|
25 |
try:
|
26 |
search_query = f"{topic} {section_title}"
|
27 |
research = search_tool.forward(search_query)
|
|
|
2 |
from typing import List, Dict
|
3 |
import re
|
4 |
import yaml
|
5 |
+
from .search_tools import get_search_tool
|
6 |
|
7 |
# Load style guide
|
8 |
with open("style_guide.yaml", 'r') as f:
|
|
|
21 |
section_title: The title of the section to generate
|
22 |
"""
|
23 |
# First, get some background information
|
24 |
+
search_tool = get_search_tool(max_results=2)
|
25 |
try:
|
26 |
search_query = f"{topic} {section_title}"
|
27 |
research = search_tool.forward(search_query)
|
tools/search_tools.py
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from smolagents import DuckDuckGoSearchTool
|
2 |
+
|
3 |
+
def get_search_tool(max_results=3):
|
4 |
+
"""Returns a configured DuckDuckGo search tool instance
|
5 |
+
|
6 |
+
Args:
|
7 |
+
max_results: Maximum number of results to return
|
8 |
+
"""
|
9 |
+
return DuckDuckGoSearchTool(max_results=max_results)
|