use crate::acg::capability::{BackendCapabilities, CapabilityRegistry};
use crate::acg::plugin::{
HintPlanApplier, PluginInput, PluginOutput, ProviderPlugin, translate_with_hint_plan,
};
use crate::acg::prompt_ir::PromptIR;
use crate::acg::translation::anthropic::AnthropicHintTranslator;
use crate::acg::translation::{HintPlan, HintTranslation, HintTranslator};
pub struct AnthropicCachePlugin {
translator: AnthropicHintTranslator,
capabilities: BackendCapabilities,
}
impl AnthropicCachePlugin {
pub fn new(registry: &CapabilityRegistry) -> Self {
Self {
translator: AnthropicHintTranslator::new(registry),
capabilities: registry
.get_backend("anthropic")
.cloned()
.unwrap_or_else(|| BackendCapabilities::none("anthropic")),
}
}
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn build_hint_translation(
&self,
input: &PluginInput<'_>,
) -> crate::acg::error::Result<HintTranslation> {
self.translator.translate(input)
}
}
impl ProviderPlugin for AnthropicCachePlugin {
fn plugin_id(&self) -> &str {
"anthropic"
}
fn plugin_name(&self) -> &str {
"Anthropic Cache Plugin"
}
fn translate(&self, input: &PluginInput<'_>) -> crate::acg::error::Result<PluginOutput> {
translate_with_hint_plan(&self.translator, self, input)
}
fn capabilities(&self) -> BackendCapabilities {
self.capabilities.clone()
}
}
impl HintPlanApplier for AnthropicCachePlugin {
fn apply_hint_plan(
&self,
request: &nemo_flow::api::llm::LlmRequest,
prompt_ir: &PromptIR,
hint_plan: &HintPlan,
) -> crate::acg::error::Result<nemo_flow::api::llm::LlmRequest> {
crate::acg::request_surfaces::apply_request_surface(
self.plugin_id(),
request,
prompt_ir,
hint_plan,
)
}
}
#[cfg(test)]
#[path = "../../tests/unit/acg/anthropic_plugin_tests.rs"]
mod tests;