summary and sentiment analysis

This commit is contained in:
Dobromir Popov
2024-01-08 19:18:37 +02:00
parent 17d7316ef9
commit d7b19fbb14
3 changed files with 40 additions and 13 deletions

View File

@ -200,23 +200,25 @@ from agents.webagent import run_web_agent, save_data
async def run_web_agent_and_process_result(topic, folder):
news_data = run_web_agent(topic, folder)
# summary = summarize_data(news_data)
print(f"[{datetime.now()}] Doing summarisation and sentiment analysis with an AI model.")
# 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"Summarize these news and make sentiment analysis on each news and one overall: {news_data}"
print(f"[{datetime.now()}] Doing sentiment analysis with AI model.")
start = time.time()
query_result = await query_llm(user_message, "openhermes")
print(f"[{datetime.now()}] AI call returned in {time.time() - start} seconds.")
news_data["summary"] = query_result
user_message = "do sentiment analysis on theese news and report overall sentiment for the day from 1 to 100. Here's the current news articles: {news_data}"
start = time.time()
query_result = await query_llm(user_message, "openhermes")
print(f"[{datetime.now()}] AI call returned in {time.time() - start} seconds.")
news_data["sentimen"] = query_result
save_data(news_data, folder)
with open(os.path.join(folder, "summary_log.txt"), 'a') as log_file:
log_file.write(f"{datetime.now()}: {query_result}\n")
log_file.write(f"\n\n\n{datetime.now()}: {query_result}\n")
# Process the query_result as needed
@ -227,7 +229,7 @@ async def async_main():
while True:
await run_web_agent_and_process_result(topic=topic, folder=folder)
await asyncio.sleep(interval * 60) # Convert hours to seconds
await asyncio.sleep(interval * 3600) # Convert hours to seconds
if __name__ == '__main__':
asyncio.run(async_main())