Skip to content

Commit

Permalink
feat: first answers based on the documents
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Nov 12, 2023
1 parent 079a2af commit 3ee4540
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
*/
package ch.xxx.aidoclibchat.usecase.service;

import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -84,7 +87,11 @@ public AiResult queryDocuments(String query) {
(similarDocuments.size() <= 0 ? 2000 : Math.floorDiv(2000, similarDocuments.size())));
UserMessage userMessage = new UserMessage(query);
Prompt prompt = new Prompt(List.of(systemMessage, userMessage));
LocalDateTime start = LocalDateTime.now();
AiResponse response = aiClient.generate(prompt);
LOGGER.info("AI response time: {}ms",
ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).toInstant().toEpochMilli()
- ZonedDateTime.of(start, ZoneId.systemDefault()).toInstant().toEpochMilli());
var documents = response.getGenerations().stream().map(myGen -> myGen.getInfo().get(ID))
.filter(myId -> (myId instanceof Long)).map(myId -> this.documentRepository.findById((Long) myId))
.filter(Optional::isPresent).map(Optional::get).toList();
Expand Down

0 comments on commit 3ee4540

Please sign in to comment.