fix google search - using api

This commit is contained in:
Dobromir Popov
2024-01-08 17:53:18 +02:00
parent 7c0dd39227
commit 3d114d1a76
2 changed files with 118 additions and 23 deletions

View File

@ -190,9 +190,21 @@ async def bad_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> Non
#------------------------- webagent --------------------------#
import schedule
import time
from agents.webagent import run_web_agent
from agents.webagent import run_web_agent, save_data
async def run_web_agent_and_process_result(topic, folder):
print(f"Running web agent for topic: {topic}")
news_data = run_web_agent(topic, folder)
save_data(news_data, folder)
# summary = summarize_data(news_data)
# with open(os.path.join(folder, "summary_log.txt"), 'a') as log_file:
# log_file.write(f"{datetime.now()}: {summary}\n")
# Process the result immediately after obtaining it
user_message = f"New data received: {news_data}"
query_result = await query_llm(user_message)
# Process the query_result as needed
async def async_main():
# Assuming this is your asynchronous main function with its full details
@ -205,22 +217,17 @@ async def async_main():
def sync_main():
# Synchronous part for scheduling
topic = "tesla news"
interval = 1 # in minutes
interval = 8 # in minutes
folder = "agent-py-bot/scrape/raw"
schedule.every(interval).minutes.do(run_web_agent, topic=topic, folder=folder)
# schedule.every(interval).minutes.do(run_web_agent_and_process_result, topic=topic, folder=folder)
schedule.every(interval).hours.do(run_web_agent_and_process_result, topic=topic, folder=folder)
# Run once at the start
news_json = run_web_agent(topic=topic, folder=folder)
news_json = await run_web_agent_and_process_result(topic=topic, folder=folder)
while True:
schedule.run_pending()
time.sleep(1)
# Check if there's new data obtained from web agent
new_data, new_summary = run_web_agent(topic=topic, folder=folder)
# Use the new data to call the async function
user_message = f"New data received: {new_data}"
query_result = query_llm(user_message)
if __name__ == '__main__':
loop = asyncio.get_event_loop()