-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
985a9d7
commit adb9bc4
Showing
14 changed files
with
206 additions
and
2 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
18 changes: 18 additions & 0 deletions
18
src/main/java/com/kustacks/kuring/admin/adapter/out/event/AdminAiEventAdapter.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,18 @@ | ||
package com.kustacks.kuring.admin.adapter.out.event; | ||
|
||
import com.kustacks.kuring.admin.application.port.out.AiEventPort; | ||
import com.kustacks.kuring.ai.adapter.in.event.dto.DataEmbeddingEvent; | ||
import com.kustacks.kuring.common.domain.Events; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.io.Resource; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class AdminAiEventAdapter implements AiEventPort { | ||
|
||
@Override | ||
public void sendDataEmbeddingEvent(String originName, String extension, String contentType, Resource resource) { | ||
Events.raise(new DataEmbeddingEvent(originName, extension, contentType, resource)); | ||
} | ||
} |
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/kustacks/kuring/admin/application/port/out/AiEventPort.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,8 @@ | ||
package com.kustacks.kuring.admin.application.port.out; | ||
|
||
import org.springframework.core.io.Resource; | ||
|
||
public interface AiEventPort { | ||
|
||
void sendDataEmbeddingEvent(String originName, String extension, String contentType, Resource resource); | ||
} |
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
28 changes: 28 additions & 0 deletions
28
src/main/java/com/kustacks/kuring/ai/adapter/in/event/DataEmbeddingEventListener.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,28 @@ | ||
package com.kustacks.kuring.ai.adapter.in.event; | ||
|
||
import com.kustacks.kuring.ai.adapter.in.event.dto.DataEmbeddingEvent; | ||
import com.kustacks.kuring.ai.application.port.in.RAGCommandUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.event.EventListener; | ||
import org.springframework.scheduling.annotation.Async; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DataEmbeddingEventListener { | ||
|
||
private final RAGCommandUseCase ragCommandUseCase; | ||
|
||
@Async | ||
@EventListener | ||
public void dataEmbeddingEvent( | ||
DataEmbeddingEvent event | ||
) { | ||
ragCommandUseCase.dataEmbedding( | ||
event.fileName(), | ||
event.extension(), | ||
event.contentType(), | ||
event.resource() | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/kustacks/kuring/ai/adapter/in/event/dto/DataEmbeddingEvent.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,11 @@ | ||
package com.kustacks.kuring.ai.adapter.in.event.dto; | ||
|
||
import org.springframework.core.io.Resource; | ||
|
||
public record DataEmbeddingEvent( | ||
String fileName, | ||
String extension, | ||
String contentType, | ||
Resource resource | ||
) { | ||
} |
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
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
8 changes: 8 additions & 0 deletions
8
src/main/java/com/kustacks/kuring/ai/application/port/in/RAGCommandUseCase.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,8 @@ | ||
package com.kustacks.kuring.ai.application.port.in; | ||
|
||
import org.springframework.core.io.Resource; | ||
|
||
public interface RAGCommandUseCase { | ||
|
||
void dataEmbedding(String originName, String extension, String contentType, Resource resource); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/kustacks/kuring/ai/application/service/RAGCommandService.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,35 @@ | ||
package com.kustacks.kuring.ai.application.service; | ||
|
||
import com.kustacks.kuring.ai.application.port.in.RAGCommandUseCase; | ||
import com.kustacks.kuring.ai.application.port.out.CommandVectorStorePort; | ||
import com.kustacks.kuring.common.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.core.io.Resource; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@UseCase | ||
@RequiredArgsConstructor | ||
public class RAGCommandService implements RAGCommandUseCase { | ||
|
||
private final CommandVectorStorePort commandVectorStorePort; | ||
private static final String EXTENSION_PDF = "pdf"; | ||
private static final String EXTENSION_TXT = "txt"; | ||
|
||
@Override | ||
public void dataEmbedding(String originName, String extension, String contentType, Resource resource) { | ||
try { | ||
if (extension.equals(EXTENSION_PDF)) { | ||
// TODO: pdf embedding | ||
} else if (extension.equals(EXTENSION_TXT)) { | ||
commandVectorStorePort.embeddingSingleTextFile(originName, resource); | ||
} else { | ||
log.warn("not supported file type : {}", extension); | ||
} | ||
} catch (IOException e) { | ||
log.warn("file embedding fail : {}", originName); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/kustacks/kuring/alert/application/port/in/dto/DataEmbeddingCommand.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,8 @@ | ||
package com.kustacks.kuring.alert.application.port.in.dto; | ||
|
||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record DataEmbeddingCommand( | ||
MultipartFile file | ||
) { | ||
} |
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