Skip to content

Commit

Permalink
feature: added CailaCatchAllActivator to save cailaAnalyzeResult with…
Browse files Browse the repository at this point in the history
… catchAll activation
  • Loading branch information
Veronika Akhapkina authored and CptBronzebeard committed Mar 6, 2024
1 parent addea3a commit 4926deb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.justai.jaicf.activator.caila

import com.justai.jaicf.activator.ActivatorFactory
import com.justai.jaicf.activator.caila.dto.CailaAnalyzeResponseData
import com.justai.jaicf.activator.catchall.CatchAllActivationRule
import com.justai.jaicf.activator.catchall.CatchAllActivator
import com.justai.jaicf.activator.catchall.CatchAllActivatorContext
import com.justai.jaicf.api.BotRequest
import com.justai.jaicf.api.hasQuery
import com.justai.jaicf.context.BotContext
import com.justai.jaicf.helpers.context.tempProperty

import com.justai.jaicf.model.scenario.ScenarioModel

class CailaCatchAllActivator(model: ScenarioModel) : CatchAllActivator(model) {

override val name = "cailaCatchAllActivator"

override fun canHandle(request: BotRequest) = request.hasQuery()

override fun provideRuleMatcher(botContext: BotContext, request: BotRequest) =
ruleMatcher<CatchAllActivationRule> {
botContext.cailaAnalyzeResult?.let { result ->
CailaCatchAllActivatorContext(result)
} ?: CatchAllActivatorContext()
}

companion object : ActivatorFactory {
override fun create(model: ScenarioModel) = CailaCatchAllActivator(model)
}
}

var BotContext.cailaAnalyzeResult by tempProperty<CailaAnalyzeResponseData?>(removeOnNull = true) { null }
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.justai.jaicf.activator.caila

import com.justai.jaicf.activator.caila.dto.CailaAnalyzeResponseData
import com.justai.jaicf.activator.catchall.CatchAllActivatorContext
import com.justai.jaicf.context.ActivatorContext

class CailaCatchAllActivatorContext(
val result: CailaAnalyzeResponseData,
) : CatchAllActivatorContext()

val ActivatorContext.cailaCatchAll
get() = this as? CailaCatchAllActivatorContext
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ open class CailaIntentActivator(

override fun provideRuleMatcher(botContext: BotContext, request: BotRequest): ActivationRuleMatcher {
val results = client.analyze(request.input) ?: return ActivationRuleMatcher { null }
botContext.cailaAnalyzeResult = results

val intents = extractIntents(results).sortedByDescending { it.confidence }
val intentMatcher = ruleMatcher<IntentActivationRule> { intents.firstOrNull(it.matches) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import com.justai.jaicf.model.scenario.ScenarioModel
*
* @see CatchAllActivatorContext
*/
class CatchAllActivator(model: ScenarioModel) : BaseActivator(model) {
open class CatchAllActivator(model: ScenarioModel) : BaseActivator(model) {

override val name = "catchAllActivator"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import com.justai.jaicf.context.StrictActivatorContext
/**
* Appears in the context of action block if [CatchAllActivator] handled the user's request.
*/
class CatchAllActivatorContext: StrictActivatorContext()
open class CatchAllActivatorContext : StrictActivatorContext()

val ActivatorContext.catchAll
get() = this as? CatchAllActivatorContext

0 comments on commit 4926deb

Please sign in to comment.