Skip to content

Commit

Permalink
Switch LLM model and re-try processing summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
mithandir committed Jun 18, 2024
1 parent cdc723b commit 57b685d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
14 changes: 12 additions & 2 deletions src/main/java/ch/climbd/newsfeed/controller/MlController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ch.climbd.newsfeed.controller;

import ch.climbd.newsfeed.data.NewsEntry;
import jakarta.annotation.PostConstruct;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ai.chat.client.ChatClient;
Expand All @@ -24,14 +25,23 @@ public class MlController {
this.mongo = mongoController;
}

@PostConstruct
public void fixQueueAfterRestart() {
var todaysNews = mongo.findAllPostedToday();
todaysNews.stream()
.filter(news -> news.getSummary() == null || news.getSummary().isBlank())
.filter(news -> news.getContent() != null && !news.getContent().isBlank() && news.getContent().length() > 1000)
.forEach(this::queueSummarize);
}

public void queueSummarize(NewsEntry news) {
LOG.info("Queued article for summarization: {}", news.getTitle());
queue.add(news);
}

@Scheduled(fixedDelay = 1, initialDelay = 5, timeUnit = TimeUnit.MINUTES)
@Scheduled(fixedDelay = 15, initialDelay = 30, timeUnit = TimeUnit.SECONDS)
public void summarize() {
NewsEntry news = null;
NewsEntry news;
try {
news = queue.poll();

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/ch/climbd/newsfeed/controller/MongoController.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ public List<NewsEntry> findAllFilterdBySite(String host) {
return template.find(query, NewsEntry.class);
}

public List<NewsEntry> findAllPostedToday() {
Query query = new Query();
query.addCriteria(Criteria.where("publishedAt").gte(ZonedDateTime.now().truncatedTo(ChronoUnit.DAYS).toInstant()));
query.with(Sort.by(Sort.Direction.DESC, "publishedAt"));
query.limit(100);
query.maxTimeMsec(1000);

return template.find(query, NewsEntry.class);
}

public void save(NewsEntry newsEntry) {
template.save(newsEntry);
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ spring:
ollama:
base-url: http://ollama:11434
chat.options:
model: qwen2:0.5b
model: qwen2:1.5b
temperature: 0.7
keep_alive: 60m
num-thread: 1
Expand Down

0 comments on commit 57b685d

Please sign in to comment.