Skip to content

Commit

Permalink
update prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
yinan-c committed Sep 7, 2023
1 parent da7f1ad commit 3c31743
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 429 deletions.
1 change: 1 addition & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[cfg]
base = "rss/"
language = "Chinese"
keyword_length = "5"
summary_length = "200"

Expand Down
28 changes: 18 additions & 10 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,25 @@ def truncate_entries(entries, max_entries):
entries = entries[:max_entries]
return entries

def gpt_summary(query,model):
chat = ChatCompletion.create(
model=model,
api_key=OPENAI_API_KEY,
messages=[
def gpt_summary(query,model,language):
if language == "zh":
messages = [
{"role": "user", "content": query},
{"role": "assistant", "content": f"请用中文总结这篇文章,先提取出{keyword_length}个关键词,在同一行内输出,然后换行,用中文在{summary_length}字内写一个简短总结,包含全部要点,按照以下格式输出'<br><br>总结:',<br>是HTML的换行符,输出时必须保留2个,并且必须在'总结:'二字之前"}
]
else:
messages = [
{"role": "user", "content": query},
{"role": f"assistant", "content": f"Please summarize this article in English, first extract {keyword_length} keywords, output them in the same line like 'keyword1, keyword2, keyword3 ...'. Then write a short summary in {summary_length} words, including all the key points, and output in the following format '<br><br>Summary:' , <br> is the line break of HTML, 2 must be retained when output, and it must be before the word 'Summary:', then translate keywords and summary into {language}, keeping the same HTML format"}
]
chat = ChatCompletion.create(
model=model,
api_key=OPENAI_API_KEY,
messages=messages,
)
return chat["choices"][0]["message"]["content"]

def output(sec):
def output(sec, language):
""" output
This function is used to output the summary of the RSS feed.
Expand Down Expand Up @@ -218,19 +225,19 @@ def output(sec):
else:
token_length = len(cleaned_article)
if token_length > 16000:
entry.summary = gpt_summary(cleaned_article[:16000],model="gpt-3.5-turbo-16k")
entry.summary = gpt_summary(cleaned_article[:16000],model="gpt-3.5-turbo-16k", language=language)
with open(log_file, 'a') as f:
f.write(f"Token length: {token_length}\n")
f.write(f"Truncate to 16k token length\n")
f.write(f"Summarized using GPT-3.5-turbo-16k\n")
else:
try:
entry.summary = gpt_summary(cleaned_article,model="gpt-3.5-turbo")
entry.summary = gpt_summary(cleaned_article,model="gpt-3.5-turbo", language=language)
with open(log_file, 'a') as f:
f.write(f"Token length: {token_length}\n")
f.write(f"Summarized using GPT-3.5-turbo\n")
except:
entry.summary = gpt_summary(cleaned_article,model="gpt-3.5-turbo-16k")
entry.summary = gpt_summary(cleaned_article,model="gpt-3.5-turbo-16k", language=language)
with open(log_file, 'a') as f:
f.write(f"Token length: {token_length}\n")
f.write(f"Summarized using GPT-3.5-turbo-16k\n")
Expand Down Expand Up @@ -264,6 +271,7 @@ def output(sec):
BASE =get_cfg('cfg', 'BASE')
keyword_length = int(get_cfg('cfg', 'keyword_length'))
summary_length = int(get_cfg('cfg', 'summary_length'))
language = get_cfg('cfg', 'language')

try:
os.mkdir(BASE)
Expand All @@ -275,7 +283,7 @@ def output(sec):
links = []
with open(os.path.join(BASE, 'index.html'), 'w') as f:
for x in secs[1:]:
output(x)
output(x, language=language)
feed = {"url": get_cfg(x, 'url').replace(',','<br>'), "name": get_cfg(x, 'name')}
feeds.append(feed)
links.append("- "+ get_cfg(x, 'url').replace(',',', ') + " -> https://yinan.me/RSS-GPT/rss/" + feed['name'] + ".xml\n")
Expand Down
67 changes: 5 additions & 62 deletions rss/appinn.log
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
------------------------------------------------------
Started: 2023-09-07 13:52:54.097926
Started: 2023-09-07 19:27:24.646318
Existing_entries: 0
Fetching from https://meta.appinn.net/tag/chrome.rss
Append: [请教 uBlock Origin 怎么屏蔽泛用于 淘宝所有店铺 用手机逛本店](https://meta.appinn.net/t/topic/47185)
Expand Down Expand Up @@ -33,6 +33,7 @@ Append: [推荐两个小工具吧](https://meta.appinn.net/t/topic/16176)
Append: [请教一个并不稀奇但却迟迟没有的chrome功能](https://meta.appinn.net/t/topic/45950)
Append: [有什么能让人用得顺手的浏览器浏览进程管理](https://meta.appinn.net/t/topic/39735)
Fetching from https://meta.appinn.net/tag/ios.rss
Append: [超高速背单词 APP 【嗯背单词】更新 1.2.2 版本,新增词根词缀,自由导入词书等功能](https://meta.appinn.net/t/topic/47211)
Append: [Sorted3 多端同步方案讨论帖](https://meta.appinn.net/t/topic/47180)
Append: [电子书阅读软件](https://meta.appinn.net/t/topic/39974)
Append: [MarkdownMind - 限时免费到30号](https://meta.appinn.net/t/topic/46314)
Expand Down Expand Up @@ -61,7 +62,6 @@ Append: [网络黄页——日记笔记类软件App](https://meta.appinn.net/t/t
Append: [日本航空的壁纸](https://meta.appinn.net/t/topic/45796)
Append: [音乐播放管理软件](https://meta.appinn.net/t/topic/40654)
Append: [每日状态(DayStatus)-ios软件【限时免费】](https://meta.appinn.net/t/topic/45594)
Append: [警示录-ios小组件-限时免费](https://meta.appinn.net/t/topic/45596)
Fetching from https://meta.appinn.net/tag/macos.rss
Append: [[自荐] 🎙️ MemoAI:颜值还行,支持 GPU 的离线语音转文字、字幕翻译工具,还有播客、YouTube 一键下载转录](https://meta.appinn.net/t/topic/47125)
Append: [【自荐】即时工具-独立开发的全能型工具箱客户端上线(送兑换码)](https://meta.appinn.net/t/topic/46304)
Expand All @@ -84,69 +84,12 @@ Append: [ThunderBird的UI大改、大版本更新之Supernova版](https://meta.a
Append: [Mac M 系列芯片 profile 工具](https://meta.appinn.net/t/topic/45941)
Append: [一堆PDF报告如何用chatgpt解读?](https://meta.appinn.net/t/topic/45356)
append_entries: 79
Finish: 2023-09-07 13:52:56.400753
------------------------------------------------------
Started: 2023-09-07 13:55:41.516316
Existing_entries: 79
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 13:55:43.726882
------------------------------------------------------
Started: 2023-09-07 13:57:35.689866
Existing_entries: 79
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 13:57:37.864959
------------------------------------------------------
Started: 2023-09-07 13:05:52.116335
Existing_entries: 79
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 13:05:55.445992
Finish: 2023-09-07 19:27:26.814955
------------------------------------------------------
Started: 2023-09-07 14:02:20.225995
Started: 2023-09-07 19:28:59.034622
Existing_entries: 79
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Append: [超高速背单词 APP 【嗯背单词】更新 1.2.2 版本,新增词根词缀,自由导入词书等功能](https://meta.appinn.net/t/topic/47211)
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 1
Finish: 2023-09-07 14:02:23.212825
------------------------------------------------------
Started: 2023-09-07 16:06:25.988460
Existing_entries: 80
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 16:06:29.794111
------------------------------------------------------
Started: 2023-09-07 19:00:48.654325
Existing_entries: 80
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 19:00:50.712677
------------------------------------------------------
Started: 2023-09-07 19:02:26.675132
Existing_entries: 80
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 19:02:28.686217
------------------------------------------------------
Started: 2023-09-07 18:06:54.806097
Existing_entries: 80
Fetching from https://meta.appinn.net/tag/chrome.rss
Fetching from https://meta.appinn.net/tag/ios.rss
Fetching from https://meta.appinn.net/tag/macos.rss
append_entries: 0
Finish: 2023-09-07 18:06:59.098086
Finish: 2023-09-07 19:29:01.139735
Loading

0 comments on commit 3c31743

Please sign in to comment.