Skip to content

Commit

Permalink
feat: init domain dispatcher
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Aug 30, 2023
1 parent f1485bf commit 19080b0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/main/kotlin/cc/unitmesh/cf/domains/DomainDispatcher.kt
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
package cc.unitmesh.cf.domains

import cc.unitmesh.cf.core.Domain
import cc.unitmesh.cf.factory.process.DomainDetector
import cc.unitmesh.cf.factory.process.DomainDetectorPlaceholder
import cc.unitmesh.cf.infrastructure.cache.CachedEmbedding
import cc.unitmesh.cf.infrastructure.llms.embedding.Embedding
import org.springframework.stereotype.Component
import org.reflections.Reflections
import org.reflections.scanners.SubTypesScanner
import org.springframework.stereotype.Component

@Component
class DomainDispatcher(
private val cachedEmbedding: CachedEmbedding,
) {
val cachedDomains: MutableList<Class<out DomainDetector>> = mutableListOf()
fun dispatch(question: String): DomainDetector {
val question: Embedding = cachedEmbedding.createEmbedding(question)
return DomainDetectorPlaceholder()
}

fun lookupDomains(): List<Class<out DomainDetector>> {
val reflections = Reflections(DomainDispatcher::class.java.`package`.name, SubTypesScanner(false))
if (cachedDomains.isNotEmpty()) {
return cachedDomains
}

return reflections.getSubTypesOf(DomainDetector::class.java)
val domains = Reflections(DomainDispatcher::class.java.`package`.name).getSubTypesOf(DomainDetector::class.java)
.toList()

this.cachedDomains.addAll(domains)
return domains
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package cc.unitmesh.cf.domains

import cc.unitmesh.cf.infrastructure.cache.CachedEmbedding
import io.kotest.matchers.ints.shouldBeGreaterThan
import io.kotest.matchers.ints.shouldBeGreaterThanOrEqual
import io.mockk.MockKAnnotations
import io.mockk.impl.annotations.MockK
import io.mockk.junit5.MockKExtension
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith

Expand Down

0 comments on commit 19080b0

Please sign in to comment.