Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 12 additions & 38 deletions crates/nvisy-engine/src/analyzer/audio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,60 +16,34 @@
//! [`AnalyzerParams`]: nvisy_schema::plan::AnalyzerParams

use elide::detection::Analyzer;
use elide_core::Error;
use elide_core::modality::audio::Audio;
use elide_core::{Error, ErrorKind};
#[cfg(feature = "test-utils")]
use elide_stt::{MockBackend as MockSttBackend, SttEnricher};
use nvisy_core::ner::NerConfig;
use nvisy_schema::plan::{AnalyzerParams, SttBackendParams, SttEnricherParams};
use nvisy_schema::plan::AnalyzerParams;

use super::common::{attach_dedup, attach_pattern};
use super::ner::attach_ner_lineup;
use super::PatternGuardrails;
use super::enricher::attach_stt;
use super::layer::attach_dedup;
use super::recognizer::{attach_ner_lineup, attach_pattern};

/// Compile `spec` into an audio-modality [`Analyzer`].
pub(super) fn compile(spec: &AnalyzerParams, ner: &NerConfig) -> Result<Analyzer<Audio>, Error> {
pub(super) fn compile(
spec: &AnalyzerParams,
ner: &NerConfig,
guardrails: &PatternGuardrails,
) -> Result<Analyzer<Audio>, Error> {
let mut analyzer = Analyzer::<Audio>::new();

if let Some(stt) = &spec.enrichers.stt {
analyzer = attach_stt(analyzer, stt)?;
}

if let Some(pattern) = &spec.recognizers.pattern {
analyzer = attach_pattern(analyzer, pattern)?;
analyzer = attach_pattern(analyzer, pattern, guardrails)?;
}
if spec.recognizers.ner {
analyzer = attach_ner_lineup(analyzer, ner)?;
}

Ok(attach_dedup(analyzer, &spec.deduplication))
}

/// Attach an [`SttEnricher`] for the audio modality. The
/// deployment's `Bento` backend returns a clean "not wired yet"
/// error until `elide-bento` ships a `BentoStt` client;
/// unknown variants surface as Validation.
///
/// [`SttEnricher`]: elide_stt::SttEnricher
fn attach_stt(
analyzer: Analyzer<Audio>,
spec: &SttEnricherParams,
) -> Result<Analyzer<Audio>, Error> {
#[cfg(not(feature = "test-utils"))]
let _ = analyzer;
match &spec.backend {
SttBackendParams::Bento { .. } => Err(Error::new(
ErrorKind::Validation,
"analyzer compile: BentoML STT backend needs an elide-bento `BentoStt` \
client; not wired into the compile surface yet",
)),
#[cfg(feature = "test-utils")]
SttBackendParams::Mock => Ok(analyzer.with_enricher(SttEnricher::new(MockSttBackend))),
// `SttBackendParams` is `#[non_exhaustive]`. Unknown
// variants surface as Validation.
_ => Err(Error::new(
ErrorKind::Validation,
"analyzer compile: STT enricher uses a backend kind this engine binary \
doesn't understand; upgrade the engine or downgrade the config",
)),
}
}
112 changes: 0 additions & 112 deletions crates/nvisy-engine/src/analyzer/common.rs

This file was deleted.

29 changes: 29 additions & 0 deletions crates/nvisy-engine/src/analyzer/enricher/language.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//! Attach the lingua language-detection [`Enricher<Text>`].
//!
//! Text-modality only — writes the detected language into the
//! per-request recognizer context, so pattern/NER/LLM downstream
//! see what it wrote.
//!
//! [`Enricher<Text>`]: elide_core::recognition::Enricher

use elide::detection::Analyzer;
use elide::enrichment::lingua::LinguaEnricher;
use elide_core::modality::text::Text;
use nvisy_schema::plan::LanguageEnricherParams;

/// Attach the lingua language-detection enricher built from `spec`.
///
/// An empty `candidates` list yields the unrestricted detector
/// (every language lingua was compiled with); a non-empty list
/// scopes detection to that pool.
pub(in crate::analyzer) fn attach(
analyzer: Analyzer<Text>,
spec: &LanguageEnricherParams,
) -> Analyzer<Text> {
let enricher = if spec.candidates.is_empty() {
LinguaEnricher::unrestricted()
} else {
LinguaEnricher::with_candidates(spec.candidates.iter().cloned())
};
analyzer.with_enricher(enricher)
}
19 changes: 19 additions & 0 deletions crates/nvisy-engine/src/analyzer/enricher/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Per-enricher compile helpers: `language`, `ocr`, `stt`.
//!
//! Symmetric with [`super::recognizer`]. Enrichers run before
//! recognition and stamp side-channel data (language hint,
//! OCR'd text layout, audio transcript segments) onto the
//! per-request context so downstream recognizers pick it up
//! transparently.
//!
//! Every enricher is at-most-one per analyzer; the caller-facing
//! spec is the corresponding slot on
//! [`nvisy_schema::plan::EnricherParams`].

mod language;
mod ocr;
mod stt;

pub(super) use self::language::attach as attach_language;
pub(super) use self::ocr::attach as attach_ocr;
pub(super) use self::stt::attach as attach_stt;
Loading