Spaces:
Running
on
Zero
Running
on
Zero
Delete web_search.py
Browse files- web_search.py +0 -51
web_search.py
DELETED
@@ -1,51 +0,0 @@
|
|
1 |
-
from llama_cpp_agent import LlamaCppAgent, MessagesFormatterType
|
2 |
-
from llama_cpp_agent.chat_history.messages import Roles
|
3 |
-
from llama_cpp_agent.llm_output_settings import LlmStructuredOutputSettings
|
4 |
-
from llama_cpp_agent.providers import LlamaCppServerProvider
|
5 |
-
from llama_cpp_agent.providers.provider_base import LlmProvider
|
6 |
-
from web_search_interfaces import WebCrawler, WebSearchProvider
|
7 |
-
from default_web_crawlers import TrafilaturaWebCrawler
|
8 |
-
from default_web_search_providers import DDGWebSearchProvider
|
9 |
-
|
10 |
-
|
11 |
-
class WebSearchTool:
|
12 |
-
|
13 |
-
def __init__(self, llm_provider: LlmProvider, message_formatter_type: MessagesFormatterType, context_character_limit: int = 7500,
|
14 |
-
web_crawler: WebCrawler = None, web_search_provider: WebSearchProvider = None):
|
15 |
-
self.summarising_agent = LlamaCppAgent(llm_provider, debug_output=True,
|
16 |
-
system_prompt="You are a text summarization and information extraction specialist and you are able to summarize and filter out information relevant to a specific query.",
|
17 |
-
predefined_messages_formatter_type=message_formatter_type)
|
18 |
-
if web_crawler is None:
|
19 |
-
self.web_crawler = TrafilaturaWebCrawler()
|
20 |
-
else:
|
21 |
-
self.web_crawler = web_crawler
|
22 |
-
|
23 |
-
if web_search_provider is None:
|
24 |
-
self.web_search_provider = DDGWebSearchProvider()
|
25 |
-
else:
|
26 |
-
self.web_search_provider = web_search_provider
|
27 |
-
|
28 |
-
self.context_character_limit = context_character_limit
|
29 |
-
|
30 |
-
def search_web(self, search_query: str):
|
31 |
-
"""
|
32 |
-
Search the web for information.
|
33 |
-
Args:
|
34 |
-
search_query (str): Search query to search for.
|
35 |
-
"""
|
36 |
-
results = self.web_search_provider.search_web(search_query)
|
37 |
-
result_string = ''
|
38 |
-
for res in results:
|
39 |
-
web_info = self.web_crawler.get_website_content_from_url(res)
|
40 |
-
if web_info != "":
|
41 |
-
web_info = self.summarising_agent.get_chat_response(
|
42 |
-
f"Please summarize the following Website content and extract relevant information to this query:'{search_query}'.\n\n" + web_info,
|
43 |
-
add_response_to_chat_history=False, add_message_to_chat_history=False)
|
44 |
-
result_string += web_info
|
45 |
-
|
46 |
-
res = result_string.strip()
|
47 |
-
return "Please combine this summarizes results below, into one summary as markdown document:\nResults:\n\n" + res[:self.context_character_limit]
|
48 |
-
|
49 |
-
def get_tool(self):
|
50 |
-
return self.search_web
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|