Skip to content

Commit

Permalink
fix: use updated apis
Browse files Browse the repository at this point in the history
  • Loading branch information
Angular2Guy committed Dec 17, 2024
1 parent f4c4cd3 commit b04d847
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import org.postgresql.util.PGobject;
import org.springframework.ai.document.Document;
import org.springframework.ai.embedding.EmbeddingModel;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.ai.vectorstore.SearchRequest;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.ai.vectorstore.filter.Filter;
import org.springframework.ai.vectorstore.filter.Filter.ExpressionType;
import org.springframework.ai.vectorstore.filter.Filter.Key;
import org.springframework.ai.vectorstore.filter.Filter.Value;
import org.springframework.ai.vectorstore.filter.FilterExpressionConverter;
import org.springframework.ai.vectorstore.pgvector.PgVectorStore;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
Expand All @@ -52,7 +52,7 @@ public DocumentVSRepositoryBean(JdbcTemplate jdbcTemplate, EmbeddingModel embedd
ObjectMapper objectMapper) {
this.jdbcTemplate = jdbcTemplate;
this.objectMapper = objectMapper;
this.vectorStore = new PgVectorStore(jdbcTemplate, embeddingClient);
this.vectorStore = PgVectorStore.builder().embeddingModel(embeddingClient).jdbcTemplate(jdbcTemplate).build();
this.filterExpressionConverter = ((PgVectorStore) this.vectorStore).filterExpressionConverter;
this.vectorTableName = PgVectorStore.DEFAULT_TABLE_NAME;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import ch.xxx.aidoclibchat.domain.model.entity.Subject;
import ch.xxx.aidoclibchat.domain.model.entity.SubjectRepository;
import ch.xxx.aidoclibchat.domain.model.entity.Work;

@Repository
public class SubjectRepositoryBean implements SubjectRepository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public String generateTest(String url, Optional<String> testUrlOpt) {
.collect(Collectors.joining(System.getProperty("line.separator")));
LOGGER.debug(new PromptTemplate(this.contextWindowSize >= 16 * 1024 ? this.ollamaPrompt1 : this.ollamaPrompt,
Map.of("classToTest", classToTest, "contextClasses", contextClasses, "testExample", testExample))
.createMessage().getContent());
.createMessage().getText());
LOGGER.info("Generation started with context window: {}", this.contextWindowSize);
var response = chatClient.prompt()
.user(u -> u.text(this.contextWindowSize >= 16 * 1024 ? this.ollamaPrompt1 : this.ollamaPrompt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public Long storeDocument(Document document) {
record TikaDocumentAndContent(org.springframework.ai.document.Document document, String content) {
}
var aiDocuments = tikaDocuments.stream()
.flatMap(myDocument1 -> this.splitStringToTokenLimit(myDocument1.getContent(), embeddingTokenLimit)
.flatMap(myDocument1 -> this.splitStringToTokenLimit(myDocument1.getText(), embeddingTokenLimit)
.stream().map(myStr -> new TikaDocumentAndContent(myDocument1, myStr)))
.map(myTikaRecord -> new org.springframework.ai.document.Document(myTikaRecord.content(),
myTikaRecord.document().getMetadata()))
Expand Down Expand Up @@ -226,10 +226,10 @@ public AiDocumentResult queryDocuments(SearchDto searchDto) {
this.getSystemMessage(mostSimilar.stream().toList(), this.documentTokenLimit, searchDto.getSearchString());
default -> this.getSystemMessage(documentChunks, this.documentTokenLimit, searchDto.getSearchString());
};
UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getContent())
UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getText())
: new UserMessage(searchDto.getSearchString());
LocalDateTime start = LocalDateTime.now();
var response = chatClient.prompt().system(s -> s.text(systemMessage.getContent()))
var response = chatClient.prompt().system(s -> s.text(systemMessage.getText()))
.user(u -> u.text(userMessage.getContent())).call().chatResponse();
LOGGER.info("AI response time: {}ms",
ZonedDateTime.of(LocalDateTime.now(), ZoneId.systemDefault()).toInstant().toEpochMilli()
Expand All @@ -251,7 +251,7 @@ public AiDocumentResult queryDocuments(SearchDto searchDto) {
private Message getSystemMessage(List<org.springframework.ai.document.Document> similarDocuments, int tokenLimit,
String prompt) {
String documentStr = this.cutStringToTokenLimit(
similarDocuments.stream().map(entry -> entry.getContent())
similarDocuments.stream().map(entry -> entry.getText())
.filter(Predicate.not(Objects::isNull))
.filter(Predicate.not(String::isBlank)).collect(Collectors.joining("\n")),
tokenLimit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class ImageService {
private DocumentVsRepository documentVsRepository;
@Value("${image.result-size:20}")
private Long resultSize;
private final String systemPrompt = "You are a helpful assistent searching image descriptions.";
//private final String systemPrompt = "You are a helpful assistent searching image descriptions.";

private record ResultData(String answer, ImageQueryDto imageQueryDto) {
}
Expand Down Expand Up @@ -97,7 +97,7 @@ public List<ImageDto> queryImage(String imageQuery) {
.stream().collect(Collectors.toMap(myDoc -> myDoc.getId(), myDoc -> myDoc));
return imageMap.entrySet().stream().map(myEntry -> createImageContainer(aiDocuments, myEntry))
.sorted((containerA, containerB) -> containerA.distance().compareTo(containerB.distance()))
.map(myContainer -> new ImageDto(myContainer.document().getContent(),
.map(myContainer -> new ImageDto(myContainer.document().getText(),
Base64.getEncoder().encodeToString(myContainer.image().getImageContent()),
myContainer.image().getImageType()))
.limit(this.resultSize).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ private Prompt createPrompt(SearchDto searchDto, EmbeddingContainer documentCont
joinTable.set(((String) myRowDoc.getMetadata().get(MetaData.TABLE_NAME)));
joinColumn.set(((String) myRowDoc.getMetadata().get(MetaData.DATANAME)));
tableColumnNames.columnNames().add(((String) myRowDoc.getMetadata().get(MetaData.DATANAME)));
columnValue.set(myRowDoc.getContent());
columnValue.set(myRowDoc.getText());
this.tableMetadataRepository
.findByTableNameIn(List.of(((String) myRowDoc.getMetadata().get(MetaData.TABLE_NAME))))
.stream()
Expand Down Expand Up @@ -190,7 +190,7 @@ private List<Message> createMessages(SearchDto searchDto, final Float minRowDist
tableRecords.stream().map(myRecord -> myRecord.schema()).collect(Collectors.joining(";")),
"prompt", searchDto.getSearchString(), "joinColumn", joinColumn.get(), "joinTable",
joinTable.get(), "columnValue", columnValue.get()));
UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getContent())
UserMessage userMessage = this.activeProfile.contains("ollama") ? new UserMessage(systemMessage.getText())
: new UserMessage(searchDto.getSearchString());
return List.of(systemMessage, userMessage);
}
Expand Down

0 comments on commit b04d847

Please sign in to comment.