-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat : convert from get to post endpoint * rename : project name * add request and response, convert endpoint to post * feat : implement RAG * remove unused file
- Loading branch information
1 parent
6adb623
commit 6d00a63
Showing
8 changed files
with
66 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 7 additions & 14 deletions
21
...hain4j-AllMiniLmL6V2-llm/src/main/java/com/learning/ai/config/AICustomerSupportAgent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
package com.learning.ai.config; | ||
|
||
import com.learning.ai.domain.response.AICustomerSupportResponse; | ||
import dev.langchain4j.service.SystemMessage; | ||
import dev.langchain4j.service.UserMessage; | ||
import dev.langchain4j.service.V; | ||
|
||
public interface AICustomerSupportAgent { | ||
|
||
@SystemMessage({ | ||
@UserMessage({ | ||
""" | ||
You're assisting with questions about services offered by Carina. | ||
Carina is a two-sided healthcare marketplace focusing on home care aides (caregivers) | ||
and their Medicaid in-home care clients (adults and children with developmental disabilities and low income elderly population). | ||
Carina's mission is to build online tools to bring good jobs to care workers, so care workers can provide the | ||
best possible care for those who need it. | ||
Tell me about {{question}}? as of {{current_date}} | ||
Use the information from the DOCUMENTS section to provide accurate answers but act as if you knew this information innately. | ||
If unsure, simply state that you don't know. | ||
DOCUMENTS: | ||
{documents} | ||
""" | ||
Use the following information to answer the question: | ||
{{information}} | ||
""" | ||
}) | ||
AICustomerSupportResponse chat(@V("documents") String documents); | ||
AICustomerSupportResponse chat(@V("question") String question, @V("information") String information); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 3 additions & 1 deletion
4
...niLmL6V2-llm/src/main/java/com/learning/ai/domain/response/AICustomerSupportResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
package com.learning.ai.domain.response; | ||
|
||
public record AICustomerSupportResponse(String response) {} | ||
import java.util.List; | ||
|
||
public record AICustomerSupportResponse(String name, int age, List<String> records, List<String> trophiesWon) {} |
38 changes: 38 additions & 0 deletions
38
...ain4j-AllMiniLmL6V2-llm/src/main/java/com/learning/ai/service/CustomerSupportService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.learning.ai.service; | ||
|
||
import com.learning.ai.config.AICustomerSupportAgent; | ||
import com.learning.ai.domain.response.AICustomerSupportResponse; | ||
import dev.langchain4j.data.embedding.Embedding; | ||
import dev.langchain4j.data.segment.TextSegment; | ||
import dev.langchain4j.model.embedding.EmbeddingModel; | ||
import dev.langchain4j.store.embedding.EmbeddingMatch; | ||
import dev.langchain4j.store.embedding.EmbeddingStore; | ||
import java.util.List; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
public class CustomerSupportService { | ||
|
||
private final EmbeddingModel embeddingModel; | ||
private final EmbeddingStore<TextSegment> embeddingStore; | ||
private final AICustomerSupportAgent aiCustomerSupportAgent; | ||
|
||
public CustomerSupportService( | ||
EmbeddingModel embeddingModel, | ||
EmbeddingStore<TextSegment> embeddingStore, | ||
AICustomerSupportAgent aiCustomerSupportAgent) { | ||
this.embeddingModel = embeddingModel; | ||
this.embeddingStore = embeddingStore; | ||
this.aiCustomerSupportAgent = aiCustomerSupportAgent; | ||
} | ||
|
||
public AICustomerSupportResponse chat(String question) { | ||
|
||
Embedding queryEmbedding = embeddingModel.embed(question).content(); | ||
List<EmbeddingMatch<TextSegment>> relevant = embeddingStore.findRelevant(queryEmbedding, 1); | ||
EmbeddingMatch<TextSegment> embeddingMatch = relevant.get(0); | ||
|
||
String embeddedText = embeddingMatch.embedded().text(); | ||
return aiCustomerSupportAgent.chat(question, embeddedText); | ||
} | ||
} |
Binary file not shown.
Binary file removed
BIN
-204 KB
rag-langchain4j-AllMiniLmL6V2-llm/src/main/resources/medicaid-wa-faqs.pdf
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters