-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
2 changed files
with
9 additions
and
7 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
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 | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
src/test/kotlin/cc/unitmesh/cf/domains/DomainDispatcherTest.kt
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