mirror of
https://github.com/tcsenpai/agenticSeek.git
synced 2025-06-06 11:05:26 +00:00
Fix : web search
This commit is contained in:
parent
ed02a4dad0
commit
479bc2769b
Binary file not shown.
Before Width: | Height: | Size: 92 KiB |
Binary file not shown.
Before Width: | Height: | Size: 254 KiB |
Binary file not shown.
Before Width: | Height: | Size: 107 KiB |
@ -18,7 +18,7 @@ class CasualAgent(Agent):
|
||||
"file_finder": FileFinder(),
|
||||
"bash": BashInterpreter()
|
||||
}
|
||||
self.role = "talking, advices and philosophical"
|
||||
self.role = "talking, advices, events and philosophical"
|
||||
|
||||
def process(self, prompt, speech_module) -> str:
|
||||
complete = False
|
||||
@ -32,8 +32,10 @@ class CasualAgent(Agent):
|
||||
exec_success, _ = self.execute_modules(answer)
|
||||
answer = self.remove_blocks(answer)
|
||||
self.last_answer = answer
|
||||
if exec_success:
|
||||
complete = True
|
||||
complete = True
|
||||
for tool in self.tools.values():
|
||||
if tool.found_executable_blocks():
|
||||
complete = False # AI read results and continue the conversation
|
||||
return answer, reasoning
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -81,6 +81,9 @@ class PlannerAgent(Agent):
|
||||
speech_module.speak(f"I will {task_name}. I assigned the {task['agent']} agent to the task.")
|
||||
try:
|
||||
self.agents[task['agent'].lower()].process(agent_prompt, None)
|
||||
pretty_print(f"-- Agent answer ---\n\n", color="output")
|
||||
self.agents[task['agent'].lower()].show_answer()
|
||||
pretty_print(f"\n\n", color="output")
|
||||
except Exception as e:
|
||||
pretty_print(f"Error: {e}", color="failure")
|
||||
speech_module.speak(f"I encountered an error: {e}")
|
||||
|
@ -39,6 +39,7 @@ class Tools():
|
||||
self.messages = []
|
||||
self.config = configparser.ConfigParser()
|
||||
self.current_dir = self.create_work_dir()
|
||||
self.excutable_blocks_found = False
|
||||
|
||||
def check_config_dir_validity(self):
|
||||
"""
|
||||
@ -129,6 +130,14 @@ class Tools():
|
||||
print(f"Saving code block to: {save_path}")
|
||||
with open(os.path.join(directory, save_path_file), 'w') as f:
|
||||
f.write(block)
|
||||
|
||||
def found_executable_blocks(self):
|
||||
"""
|
||||
Check if executable blocks were found.
|
||||
"""
|
||||
tmp = self.excutable_blocks_found
|
||||
self.excutable_blocks_found = False
|
||||
return tmp
|
||||
|
||||
def load_exec_block(self, llm_text: str) -> tuple[list[str], str | None]:
|
||||
"""
|
||||
@ -178,6 +187,7 @@ class Tools():
|
||||
if ':' in content.split('\n')[0]:
|
||||
save_path = content.split('\n')[0].split(':')[1]
|
||||
content = content[content.find('\n')+1:]
|
||||
self.excutable_blocks_found = True
|
||||
code_blocks.append(content)
|
||||
start_index = end_pos + len(end_tag)
|
||||
return code_blocks, save_path
|
||||
|
@ -6,9 +6,13 @@ import dotenv
|
||||
dotenv.load_dotenv()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
from utility import animate_thinking, pretty_print
|
||||
from tools import Tools
|
||||
else:
|
||||
from sources.tools.tools import Tools
|
||||
from sources.utility import animate_thinking, pretty_print
|
||||
|
||||
class webSearch(Tools):
|
||||
def __init__(self, api_key: str = None):
|
||||
@ -24,6 +28,7 @@ class webSearch(Tools):
|
||||
return "Error: No SerpApi key provided."
|
||||
for block in blocks:
|
||||
query = block.strip()
|
||||
pretty_print(f"Searching for: {query}", color="status")
|
||||
if not query:
|
||||
return "Error: No search query provided."
|
||||
|
||||
@ -32,19 +37,21 @@ class webSearch(Tools):
|
||||
params = {
|
||||
"q": query,
|
||||
"api_key": self.api_key,
|
||||
"num": 1,
|
||||
"num": 100,
|
||||
"output": "json"
|
||||
}
|
||||
response = requests.get(url, params=params)
|
||||
response.raise_for_status()
|
||||
|
||||
data = response.json()
|
||||
results = []
|
||||
if "organic_results" in data and len(data["organic_results"]) > 0:
|
||||
first_result = data["organic_results"][0]
|
||||
title = first_result.get("title", "No title")
|
||||
snippet = first_result.get("snippet", "No snippet available")
|
||||
link = first_result.get("link", "No link available")
|
||||
return f"Title: {title}\nSnippet: {snippet}\nLink: {link}"
|
||||
for result in data["organic_results"][:50]:
|
||||
title = result.get("title", "No title")
|
||||
snippet = result.get("snippet", "No snippet available")
|
||||
link = result.get("link", "No link available")
|
||||
results.append(f"Title: {title}\nSnippet: {snippet}\nLink: {link}")
|
||||
return "\n\n".join(results)
|
||||
else:
|
||||
return "No results found for the query."
|
||||
except requests.RequestException as e:
|
||||
@ -65,6 +72,6 @@ class webSearch(Tools):
|
||||
if __name__ == "__main__":
|
||||
search_tool = webSearch(api_key=os.getenv("SERPAPI_KEY"))
|
||||
query = "when did covid start"
|
||||
result = search_tool.execute(query, safety=True)
|
||||
result = search_tool.execute([query], safety=True)
|
||||
feedback = search_tool.interpreter_feedback(result)
|
||||
print(feedback)
|
Loading…
x
Reference in New Issue
Block a user