From 9adf372d461ceee5d9fc3aef4429b262290636b4 Mon Sep 17 00:00:00 2001
From: Qetesh <4559341+Qetesh@users.noreply.github.com>
Date: Mon, 19 Aug 2024 22:00:35 +0800
Subject: add timeout, add err handler
---
config.sample.yml | 2 +-
main.py | 27 ++++++++++++++++++++-------
requirements.txt | 3 ++-
3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/config.sample.yml b/config.sample.yml
index d56863f..a9d4c39 100644
--- a/config.sample.yml
+++ b/config.sample.yml
@@ -10,7 +10,7 @@ llm:
agents:
summary:
title: "💡AI 摘要"
- prompt: "Please summarize the content of the article in 50 words in Chinese. Do not add any explanations or annotations to the result text. 请用 50 个字的中文总结文章的内容。"
+ prompt: "Please summarize the content of the article under 50 words in Chinese. Do not add any additional Character、markdown language to the result text. 请用不超过50个汉字概括文章内容。结果文本中不要添加任何额外的字符、Markdown语言。"
style_block: true
blacklist:
- https://xxxx.net
diff --git a/main.py b/main.py
index 9180760..22f213f 100644
--- a/main.py
+++ b/main.py
@@ -3,6 +3,7 @@ import time
import miniflux
from markdownify import markdownify as md
+import markdown
from openai import OpenAI
from yaml import load, Loader
@@ -17,31 +18,43 @@ def process_entry(entry):
[start_with_list.append('
\n{agent[1]['title']}:{response_content}
"
+ llm_result = (llm_result + '\n'
+ + agent[1]['title'] + ':'
+ + response_content.replace('\n', '').replace('\r', '')
+ + '\n
')
else:
- llm_result = llm_result + f"{agent[1]['title']}:{response_content}
"
+ llm_result = llm_result + f"{agent[1]['title']}:{markdown.markdown(response_content)}
"
if len(llm_result) > 0:
miniflux_client.update_entry(entry['id'], content= llm_result + entry['content'])
while True:
- # Fetch entries with status unread
entries = miniflux_client.get_entries(status=['unread'], limit=10000)
- print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()), 'Fetched new entries: ' + str(len(entries['entries']))) if len(entries['entries']) > 0 else print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()), 'No new entries')
+ start_time = time.time()
+ print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()), 'Fetched unread entries: ' + str(len(entries['entries']))) if len(entries['entries']) > 0 else print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()), 'No new entries')
+
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(process_entry, i) for i in entries['entries']]
+ for future in concurrent.futures.as_completed(futures):
+ try:
+ data = future.result()
+ except Exception as e:
+ print('generated an exception: %s' % e)
- if len(entries['entries']) > 0:
+ if len(entries['entries']) > 0 and time.time() - start_time >= 3:
print(time.strftime("%Y/%m/%d %H:%M:%S", time.localtime()), 'Done')
time.sleep(60)
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
index 4596549..7599e77 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,5 @@
miniflux
openai
markdownify
-PyYAML
\ No newline at end of file
+markdown
+PyYAML
--
cgit v1.2.3