1pub trait ConfTrait {
2 fn system(&self) -> &str;
3 fn temperature(&self) -> f32;
4 fn fmt(&self, txt: String) -> String;
5}
6
7#[derive(Debug, Clone)]
8pub struct Conf {
9 pub system: String,
10 pub temperature: f32,
11}
12
13impl ConfTrait for Conf {
14 fn system(&self) -> &str {
15 &self.system
16 }
17 fn temperature(&self) -> f32 {
18 self.temperature
19 }
20 fn fmt(&self, txt: String) -> String {
21 txt
22 }
23}
24
25#[derive(Debug, Clone)]
26pub struct ConfNoThink {
27 pub system: String,
28 pub temperature: f32,
29}
30
31impl ConfNoThink {
32 pub fn new(system: impl AsRef<str>, temperature: f32) -> ConfNoThink {
33 let system = system.as_ref();
34 ConfNoThink {
35 system: if system.is_empty() {
36 "/no-think".into()
37 } else {
38 format!("{system} /no-think")
39 },
40 temperature,
41 }
42 }
43}
44
45impl ConfTrait for ConfNoThink {
46 fn system(&self) -> &str {
47 &self.system
48 }
49 fn temperature(&self) -> f32 {
50 self.temperature
51 }
52 fn fmt(&self, txt: String) -> String {
53 if let Some(p) = txt.find("</think>") {
54 return txt[p + 8..].trim_start().into();
55 }
56 txt
57 }
58}