Skip to content

Commit dc689c5

Browse files
committed
Try qwen model
1 parent e3c7022 commit dc689c5

File tree

8 files changed

+56
-3
lines changed

8 files changed

+56
-3
lines changed

config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,7 @@ def coze_enabled():
8181
local_llm_score_threshold = 10
8282
logger.info(f'Use openai model {openai_model}')
8383

84+
disable_translation = os.getenv('DISABLE_TRANSLATION') == '1'
85+
8486
output_dir = os.path.join(os.path.dirname(__file__), 'output/')
8587
image_dir = os.path.join(output_dir, 'image/')

db/summary.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Model(Enum):
2121
LLAMA = 'Llama'
2222
STEP = 'Step'
2323
GEMMA = 'Gemma'
24+
QWEN = 'Qwen'
2425
OPENAI = 'OpenAI'
2526

2627
def can_truncate(self):
@@ -30,7 +31,7 @@ def local_llm(self):
3031
return self in (Model.LLAMA, Model.TRANSFORMER)
3132

3233
def is_finally(self) -> bool: # already best, no need to try other models
33-
return self in (Model.EMBED, Model.OPENAI, Model.GEMMA, Model.LLAMA, Model.STEP)
34+
return self in (Model.EMBED, Model.OPENAI, Model.GEMMA, Model.LLAMA, Model.STEP, Model.QWEN)
3435

3536
def need_escape(self):
3637
return self in (Model.OPENAI,)

hacker_news/llm/openai.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ def model_family() -> Model:
3232
return Model.GEMMA
3333
if 'step' in config.openai_model:
3434
return Model.STEP
35+
if 'qwen' in config.openai_model:
36+
return Model.QWEN
3537
return Model.OPENAI
3638

3739

@@ -110,6 +112,9 @@ def call_openai_family(content: str, sys_prompt: str) -> str:
110112
return '' # Let fallback code kicks in
111113
else:
112114
answer = message['content'].strip()
115+
if '</think>' in answer:
116+
# A reasoning model
117+
answer = answer.split('</think>', 1)[-1].strip()
113118
# Gemma sometimes returns "**Summary:**\n\nXXX\n\n**Key points:**\n\nXXX", extract the summary part
114119
for line in answer.split('\n'):
115120
if not line.strip():

hacker_news/news.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def summarize_by_openai(self, content):
147147
return ''
148148

149149
def translate_summary(self, summary: str):
150-
if not summary:
150+
if not summary or config.disable_translation:
151151
return
152152
try:
153153
if db.translation.exists(summary, 'zh'):

publish.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,33 @@ def gen_page(news_list, path, lang='en'):
7676
directory = os.path.dirname(static_page)
7777
os.makedirs(directory, exist_ok=True)
7878
start = time.time()
79+
daily_links = get_daily_links()
7980
rendered = template.render(news_list=news_list, last_updated=datetime.utcnow(), lang=lang,
81+
daily_links=daily_links,
8082
path=urljoin(config.site + '/', path.rstrip('index.html')))
8183
with open(static_page, "w") as fp:
8284
fp.write(rendered)
8385
cost = (time.time() - start) * 1000
8486
logger.info(f'Written {len(rendered)} bytes to {static_page}, cost(ms): {cost:.2f}')
8587

8688

89+
def get_daily_links():
90+
daily_dir = os.path.join(config.output_dir, 'daily')
91+
if not os.path.exists(daily_dir):
92+
return []
93+
links = []
94+
for name in os.listdir(daily_dir):
95+
if os.path.isdir(os.path.join(daily_dir, name)):
96+
try:
97+
datetime.strptime(name, '%Y-%m-%d')
98+
links.append(name)
99+
except ValueError:
100+
continue # Ignore directories that are not in 'YYYY-MM-DD' format
101+
links.sort(reverse=True)
102+
return links
103+
104+
105+
87106
def gen_feed(news_list):
88107
start = time.time()
89108
feed = AtomFeed('Hacker News Summary',

static/js/hn.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,18 @@ $(function () {
150150
setupSortHandlers();
151151
setupFilterHandlers();
152152

153+
// Reset daily links dropdown on open
154+
$('.daily-dropdown').on('show.bs.dropdown', function () {
155+
$('#daily-links-menu .extra-link').hide();
156+
$('#more-daily-links').parent().show();
157+
});
158+
159+
$('#more-daily-links').click(function (e) {
160+
$('#daily-links-menu .extra-link').show();
161+
$(this).parent().hide();
162+
return false;
163+
});
164+
153165
const urlParams = new URLSearchParams(window.location.hash.substring(1));
154166

155167
// Filter first

templates/base.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@
7272
<div class="collapse navbar-collapse" id="hn-menu">
7373
<ul class="nav navbar-nav nav-pills">
7474
{% block nav_links %} {% endblock %}
75+
<li class="daily-dropdown">
76+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Archive<span class="caret"></span></a>
77+
<ul class="dropdown-menu" id="daily-links-menu">
78+
{% for link in daily_links %}
79+
<li {% if loop.index > 10 %}class="extra-link" style="display: none;"{% endif %}>
80+
<a href="{{ config.site }}/daily/{{ link }}">{{ link }}</a>
81+
</li>
82+
{% endfor %}
83+
{% if daily_links|length > 10 %}
84+
<li class="divider"></li>
85+
<li><a href="#" id="more-daily-links">More...</a></li>
86+
{% endif %}
87+
</ul>
88+
</li>
7589
<li class="sort-dropdown">
7690
<a class="dropdown-toggle" data-toggle="dropdown" aria-expanded="true" href="#">
7791
Sort

templates/hackernews.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{% endblock %}
1515

1616
{% block nav_brand %}
17-
<a class="navbar-brand" href="#">Hacker News Summary</a>
17+
<a class="navbar-brand" href="{{ config.site }}/">Hacker News Summary</a>
1818
{% endblock %}
1919

2020
{% block nav_links %}

0 commit comments

Comments
 (0)