Skip to main content

CardGenerator

Struct CardGenerator 

Source
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>

Source

pub fn new( provider: &'a P, config: WikiConfig, max_concurrent: usize, language: String, ) -> Self

使用指定的 LLM Provider 创建 CardGenerator

max_concurrent 控制并行 LLM 调用的最大并发数(0 表示不限制)。 language 指定生成内容的语言。 config 提供产物路径定位(卡片文件读/写规则),供人工修改记录恢复。

Source

pub fn llm_call_count(&self) -> usize

返回已完成的 LLM 调用次数

Source

pub fn failed_modules(&self) -> Vec<String>

返回生成失败的模块名列表(演进计划 T3.2:失败隔离的可见性出口)

Source

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 不会输出,回填保证不丢)。

Source

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 同构,管道不再“生成后补记“):

  1. 旧卡片磁盘上的“人工修改待同步“节(recover_pending_manual_edits, 记录随生成回填到新卡片,保证不丢);
  2. 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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more