pub struct CardGenerator<'a, P: LlmProvider> { /* private fields */ }Expand description
Knowledge Card 生成器
通过 LLM 为每个代码模块生成结构化的 Knowledge Card, 供 AI Agent 快速理解模块职责和关键实体。
Implementations§
Source§impl<'a, P: LlmProvider> CardGenerator<'a, P>
impl<'a, P: LlmProvider> CardGenerator<'a, P>
Sourcepub fn new(
provider: &'a P,
config: WikiConfig,
max_concurrent: usize,
language: String,
) -> Self
pub fn new( provider: &'a P, config: WikiConfig, max_concurrent: usize, language: String, ) -> Self
使用指定的 LLM Provider 创建 CardGenerator
max_concurrent 控制并行 LLM 调用的最大并发数(0 表示不限制)。 language 指定生成内容的语言。 config 提供产物路径定位(卡片文件读/写规则),供人工修改记录恢复。
Sourcepub fn llm_call_count(&self) -> usize
pub fn llm_call_count(&self) -> usize
返回已完成的 LLM 调用次数
Sourcepub fn failed_modules(&self) -> Vec<String>
pub fn failed_modules(&self) -> Vec<String>
返回生成失败的模块名列表(演进计划 T3.2:失败隔离的可见性出口)
Sourcepub async fn generate_card(
&self,
chunk: &Chunk,
pending_manual_edits: &[String],
) -> Result<KnowledgeCard>
pub async fn generate_card( &self, chunk: &Chunk, pending_manual_edits: &[String], ) -> Result<KnowledgeCard>
为单个模块生成 Knowledge Card
跳过空块。LLM 调用失败时返回错误。 通过 Semaphore 控制并发(acquire → complete → release)。 pending_manual_edits 为人工修改记录:注入 LLM 输入, 且解析后回填新卡片(该字段由管道维护,LLM 不会输出,回填保证不丢)。
Sourcepub async fn generate_all_cards(
&self,
chunks: &[Chunk],
extra_edits: &HashMap<String, Vec<String>>,
) -> Result<Vec<KnowledgeCard>>
pub async fn generate_all_cards( &self, chunks: &[Chunk], extra_edits: &HashMap<String, Vec<String>>, ) -> Result<Vec<KnowledgeCard>>
并行生成所有模块的 Knowledge Card
使用 join_all + Semaphore 实现可控并发。失败的卡片会被跳过(不中断整体流程)。
人工修改记录的两路来源在生成前合并为 LLM 输入(与单卡重生成 generate_module_card 同构,管道不再“生成后补记“):
- 旧卡片磁盘上的“人工修改待同步“节(recover_pending_manual_edits, 记录随生成回填到新卡片,保证不丢);
- extra_edits:本次运行新检测到的人工修改(模块名 → 记录文本), 由上层(lib.rs 从状态指纹比对结果)组装传入。
Auto Trait Implementations§
impl<'a, P> !Freeze for CardGenerator<'a, P>
impl<'a, P> RefUnwindSafe for CardGenerator<'a, P>where
P: RefUnwindSafe,
impl<'a, P> Send for CardGenerator<'a, P>
impl<'a, P> Sync for CardGenerator<'a, P>
impl<'a, P> Unpin for CardGenerator<'a, P>
impl<'a, P> UnsafeUnpin for CardGenerator<'a, P>
impl<'a, P> UnwindSafe for CardGenerator<'a, P>where
P: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more