alith_client/components/grammar/
custom.rs1use super::{Grammar, GrammarError, GrammarSetterTrait};
2
3#[derive(Clone, PartialEq, Debug, Default)]
4pub struct CustomGrammar {
5 pub stop_word_done: Option<String>,
6 pub stop_word_no_result: Option<String>,
7 pub custom_grammar: Option<String>,
8}
9
10impl CustomGrammar {
11 pub fn wrap(self) -> Grammar {
12 Grammar::Custom(self)
13 }
14
15 #[inline]
16 pub fn custom_grammar(mut self, custom_grammar: String) -> Self {
17 self.custom_grammar = Some(custom_grammar);
18 self
19 }
20
21 #[inline]
22 pub fn grammar_string(&self) -> String {
23 self.custom_grammar.clone().expect("custom_grammar not set")
24 }
25
26 #[inline]
27 pub fn validate_clean(&self, content: &str) -> Result<String, GrammarError> {
28 Ok(content.to_owned())
29 }
30
31 #[inline]
32 pub fn grammar_parse(&self, content: &str) -> Result<String, GrammarError> {
33 Ok(content.to_owned())
34 }
35}
36
37impl GrammarSetterTrait for CustomGrammar {
38 fn stop_word_done_mut(&mut self) -> &mut Option<String> {
39 &mut self.stop_word_done
40 }
41
42 fn stop_word_no_result_mut(&mut self) -> &mut Option<String> {
43 &mut self.stop_word_no_result
44 }
45}