ContextualPrompt

Struct ContextualPrompt 

Source
pub struct ContextualPrompt<'a> { /* private fields */ }
Expand description

Context-aware prompt renderer (Phase 2)

A wrapper type that combines an Expertise with a RenderContext to enable context-aware prompt generation. Implements ToPrompt for seamless integration with the DTO pattern.

§Examples

§Direct Usage

use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};
use llm_toolkit_expertise::context::TaskHealth;

let expertise = Expertise::new("rust-reviewer", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Review Rust code".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
    .with_task_type("security-review")
    .with_task_health(TaskHealth::AtRisk)
    .to_prompt();

§DTO Integration

// With ToPrompt-based DTO pattern:
// #[derive(ToPrompt)]
// #[prompt(template = "Knowledge:\n{{expertise}}\n\nTask: {{task}}")]
// struct RequestDto<'a> {
//     expertise: ContextualPrompt<'a>,
//     task: String,
// }

Implementations§

Source§

impl<'a> ContextualPrompt<'a>

Source

pub fn from_expertise(expertise: &'a Expertise, context: RenderContext) -> Self

Create a contextual prompt from expertise and context

§Examples
use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};

let expertise = Expertise::new("test", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Test".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new());
Source

pub fn with_task_type(self, task_type: impl Into<String>) -> Self

Set the task type

§Examples
use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};

let expertise = Expertise::new("test", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Test".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
    .with_task_type("security-review");
Source

pub fn with_user_state(self, state: impl Into<String>) -> Self

Add a user state

§Examples
use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};

let expertise = Expertise::new("test", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Test".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
    .with_user_state("beginner");
Source

pub fn with_task_health(self, health: TaskHealth) -> Self

Set the task health

§Examples
use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};
use llm_toolkit_expertise::context::TaskHealth;

let expertise = Expertise::new("test", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Test".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
    .with_task_health(TaskHealth::AtRisk);
Source

pub fn to_prompt(&self) -> String

Render the prompt with context

This is called automatically when using ToPrompt trait.

§Examples
use llm_toolkit_expertise::{Expertise, WeightedFragment, KnowledgeFragment};
use llm_toolkit_expertise::render::{ContextualPrompt, RenderContext};

let expertise = Expertise::new("test", "1.0")
    .with_fragment(WeightedFragment::new(
        KnowledgeFragment::Text("Test content".to_string())
    ));

let prompt = ContextualPrompt::from_expertise(&expertise, RenderContext::new())
    .to_prompt();

assert!(prompt.contains("Test content"));

Trait Implementations§

Source§

impl<'a> Clone for ContextualPrompt<'a>

Source§

fn clone(&self) -> ContextualPrompt<'a>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for ContextualPrompt<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for ContextualPrompt<'a>

§

impl<'a> RefUnwindSafe for ContextualPrompt<'a>

§

impl<'a> Send for ContextualPrompt<'a>

§

impl<'a> Sync for ContextualPrompt<'a>

§

impl<'a> Unpin for ContextualPrompt<'a>

§

impl<'a> UnwindSafe for ContextualPrompt<'a>

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.