1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//! Port definitions for the token optimization engine.
//!
//! The [`SummarizationPort`] trait provides LLM-based text summarization
//! used as a fallback in tier-3 compaction. Implement this trait to connect
//! your own LLM backend.
//!
//! When the `pisovereign` feature is enabled, `InferencePortSummarizer`
//! adapts PiSovereign's `InferencePort` to this trait automatically.
//!
//! # Example (standalone)
//!
//! ```rust,ignore
//! use ai_tokenopt::ports::SummarizationPort;
//! use ai_tokenopt::TokenOptError;
//!
//! struct MyLlm;
//!
//! #[async_trait::async_trait]
//! impl SummarizationPort for MyLlm {
//! async fn summarize(
//! &self,
//! system_prompt: &str,
//! text: &str,
//! ) -> Result<String, TokenOptError> {
//! // Call your LLM backend here
//! todo!()
//! }
//! }
//! ```
use async_trait;
use crateTokenOptError;
/// Minimal trait for LLM-based text summarization.
///
/// The token optimizer uses this as a tier-3 compaction fallback when
/// heuristic (extractive) summarization is insufficient. Implementing
/// this trait allows the optimizer to request LLM-generated summaries
/// of pruned conversation history.
///
/// If no `SummarizationPort` is provided, the optimizer uses tier-2
/// extractive summarization only — no LLM calls are made.
/// Port for querying model metadata (context window size, etc.).
///
/// The adapter implementation (e.g. calling Ollama `/api/show`) lives
/// outside of `ai_tokenopt`. Provide an implementation when constructing
/// the `TokenOptimizer` or `Pipeline`.
/// Adapter wrapping PiSovereign's `InferencePort` as a [`SummarizationPort`].
///
/// Created automatically by the
/// [`TokenOptimizedInferencePort`](crate::decorator::TokenOptimizedInferencePort)
/// decorator. Not needed for standalone usage.
;