...
This commit is contained in:
parent
dd1f961d57
commit
68a7a05961
@ -19,6 +19,7 @@ import dev.langchain4j.model.openai.OpenAiEmbeddingModel
|
|||||||
import dev.langchain4j.service.AiServices
|
import dev.langchain4j.service.AiServices
|
||||||
import dev.langchain4j.service.SystemMessage
|
import dev.langchain4j.service.SystemMessage
|
||||||
import dev.langchain4j.store.embedding.EmbeddingSearchRequest
|
import dev.langchain4j.store.embedding.EmbeddingSearchRequest
|
||||||
|
import dev.langchain4j.store.embedding.EmbeddingSearchResult
|
||||||
import dev.langchain4j.store.embedding.filter.MetadataFilterBuilder
|
import dev.langchain4j.store.embedding.filter.MetadataFilterBuilder
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.async
|
import kotlinx.coroutines.async
|
||||||
@ -298,20 +299,23 @@ object RagService {
|
|||||||
|
|
||||||
val question = "$stockName 실적 및 향후 전망"
|
val question = "$stockName 실적 및 향후 전망"
|
||||||
val questionEmbedding = embeddingModel.embed(question).content()
|
val questionEmbedding = embeddingModel.embed(question).content()
|
||||||
|
var finalSearchResult : EmbeddingSearchResult<TextSegment>? = null
|
||||||
|
try {
|
||||||
|
finalSearchResult = embeddingStore.search(
|
||||||
|
EmbeddingSearchRequest.builder()
|
||||||
|
.queryEmbedding(questionEmbedding)
|
||||||
|
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||||
|
.maxResults(10) // 최신 뉴스 3개 적정
|
||||||
|
.minScore(0.2)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {}
|
||||||
|
|
||||||
val finalSearchResult = embeddingStore.search(
|
|
||||||
EmbeddingSearchRequest.builder()
|
|
||||||
.queryEmbedding(questionEmbedding)
|
|
||||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
|
||||||
.maxResults(10) // 최신 뉴스 3개 적정
|
|
||||||
.minScore(0.2)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
|
|
||||||
// 3. 검색된 내용을 하나의 문자열로 합쳐서 전달
|
// 3. 검색된 내용을 하나의 문자열로 합쳐서 전달
|
||||||
tradingDecision.newsContext = finalSearchResult.matches().distinct() // 중복 제거
|
tradingDecision.newsContext = finalSearchResult?.matches()?.distinct() // 중복 제거
|
||||||
.take(4) // 10개에서 4개로 축소
|
?.take(4) // 10개에서 4개로 축소
|
||||||
.joinToString("\n\n") {
|
?.joinToString("\n\n") {
|
||||||
it.embedded().text()
|
it.embedded().text()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -336,20 +340,25 @@ object RagService {
|
|||||||
val questionEmbedding = embeddingModel.embed(question).content()
|
val questionEmbedding = embeddingModel.embed(question).content()
|
||||||
|
|
||||||
// 1. 벡터 DB에서 해당 종목의 뉴스 검색
|
// 1. 벡터 DB에서 해당 종목의 뉴스 검색
|
||||||
val searchResult = embeddingStore.search(
|
var searchResult : EmbeddingSearchResult<TextSegment>? = null
|
||||||
EmbeddingSearchRequest.builder()
|
try {
|
||||||
.queryEmbedding(questionEmbedding)
|
searchResult = embeddingStore.search(
|
||||||
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
EmbeddingSearchRequest.builder()
|
||||||
.maxResults(10)
|
.queryEmbedding(questionEmbedding)
|
||||||
.minScore(0.2)
|
.filter(MetadataFilterBuilder.metadataKey("stockCode").isEqualTo(stockCode))
|
||||||
.build()
|
.maxResults(10)
|
||||||
)
|
.minScore(0.2)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
// 2. 검색된 뉴스 중 1시간 이내(Very Recent) 데이터가 있는지 확인
|
// 2. 검색된 뉴스 중 1시간 이내(Very Recent) 데이터가 있는지 확인
|
||||||
val hasHotNews = searchResult.matches().any { match ->
|
val hasHotNews = searchResult?.matches()?.any { match ->
|
||||||
val pubDate = match.embedded().metadata().getString("date")
|
val pubDate = match.embedded().metadata().getString("date")
|
||||||
isVeryRecentNews(pubDate, maxHours = 1)
|
isVeryRecentNews(pubDate, maxHours = 1)
|
||||||
}
|
} ?: false
|
||||||
|
|
||||||
// 3. 최신 뉴스가 없다면 네이버 API 및 Playwright 스크래핑 가동
|
// 3. 최신 뉴스가 없다면 네이버 API 및 Playwright 스크래핑 가동
|
||||||
if (!hasHotNews) {
|
if (!hasHotNews) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user