pub struct QueuedLlmPolicy { /* private fields */ }Implementations§
Source§impl QueuedLlmPolicy
impl QueuedLlmPolicy
Sourcepub fn new(
id: impl Into<String>,
version: impl Into<String>,
model: LlmModelIdentity,
) -> QueuedLlmPolicy
pub fn new( id: impl Into<String>, version: impl Into<String>, model: LlmModelIdentity, ) -> QueuedLlmPolicy
Examples found in repository?
examples/uncertainty_resolution.rs (lines 191-199)
176fn llm_interface_branch() -> Result<(), Box<dyn std::error::Error>> {
177 let mut canwu = Canwu::demo(202)?;
178 let ticket_id = DecisionTicketId::new(2);
179 enqueue_ticket(
180 &mut canwu,
181 ticket_id,
182 10,
183 DecisionControllerBinding::new(
184 "law-llm-controller",
185 DecisionPolicyIdentity::new(DecisionPolicyKind::Llm, "strict-law-selector", "1"),
186 DecisionAuthority::Actor {
187 actor: Canwu::demo_ids().commander,
188 },
189 ),
190 )?;
191 let mut policy = QueuedLlmPolicy::new(
192 "strict-law-selector",
193 "1",
194 LlmModelIdentity {
195 provider: "not-connected".to_owned(),
196 model: "host-selected-model".to_owned(),
197 prompt_contract: "return one existing option_id and no new action".to_owned(),
198 },
199 );
200 let ticket = canwu.decision_ticket(ticket_id).expect("LLM ticket");
201 let request = policy.external_request(ticket);
202 println!("llm_request={}", serde_json::to_string(&request)?);
203
204 // A real host sends `request` to its model and parses a strict structured
205 // answer. This example supplies the same response object without making a
206 // network call.
207 policy.submit(
208 ticket_id,
209 ExternalDecisionResponse {
210 ticket_version: request.ticket_version,
211 option_id: "pass".to_owned(),
212 provider: "not-connected".to_owned(),
213 request_id: "example-response-1".to_owned(),
214 metadata: BTreeMap::new(),
215 },
216 )?;
217 let evaluation = canwu.drive_decision(
218 canwu.time(),
219 0,
220 DecisionRequestId::new(12),
221 None,
222 ticket_id,
223 &policy,
224 )?;
225 assert!(matches!(evaluation, DecisionEvaluation::Prepared(_)));
226 canwu.step_canonical()?.expect("LLM decision boundary");
227 Ok(())
228}Sourcepub fn submit(
&mut self,
ticket_id: DecisionTicketId,
response: ExternalDecisionResponse,
) -> Result<(), DecisionError>
pub fn submit( &mut self, ticket_id: DecisionTicketId, response: ExternalDecisionResponse, ) -> Result<(), DecisionError>
Examples found in repository?
examples/uncertainty_resolution.rs (lines 207-216)
176fn llm_interface_branch() -> Result<(), Box<dyn std::error::Error>> {
177 let mut canwu = Canwu::demo(202)?;
178 let ticket_id = DecisionTicketId::new(2);
179 enqueue_ticket(
180 &mut canwu,
181 ticket_id,
182 10,
183 DecisionControllerBinding::new(
184 "law-llm-controller",
185 DecisionPolicyIdentity::new(DecisionPolicyKind::Llm, "strict-law-selector", "1"),
186 DecisionAuthority::Actor {
187 actor: Canwu::demo_ids().commander,
188 },
189 ),
190 )?;
191 let mut policy = QueuedLlmPolicy::new(
192 "strict-law-selector",
193 "1",
194 LlmModelIdentity {
195 provider: "not-connected".to_owned(),
196 model: "host-selected-model".to_owned(),
197 prompt_contract: "return one existing option_id and no new action".to_owned(),
198 },
199 );
200 let ticket = canwu.decision_ticket(ticket_id).expect("LLM ticket");
201 let request = policy.external_request(ticket);
202 println!("llm_request={}", serde_json::to_string(&request)?);
203
204 // A real host sends `request` to its model and parses a strict structured
205 // answer. This example supplies the same response object without making a
206 // network call.
207 policy.submit(
208 ticket_id,
209 ExternalDecisionResponse {
210 ticket_version: request.ticket_version,
211 option_id: "pass".to_owned(),
212 provider: "not-connected".to_owned(),
213 request_id: "example-response-1".to_owned(),
214 metadata: BTreeMap::new(),
215 },
216 )?;
217 let evaluation = canwu.drive_decision(
218 canwu.time(),
219 0,
220 DecisionRequestId::new(12),
221 None,
222 ticket_id,
223 &policy,
224 )?;
225 assert!(matches!(evaluation, DecisionEvaluation::Prepared(_)));
226 canwu.step_canonical()?.expect("LLM decision boundary");
227 Ok(())
228}Trait Implementations§
Source§impl Clone for QueuedLlmPolicy
impl Clone for QueuedLlmPolicy
Source§fn clone(&self) -> QueuedLlmPolicy
fn clone(&self) -> QueuedLlmPolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for QueuedLlmPolicy
impl Debug for QueuedLlmPolicy
Source§impl DecisionPolicy for QueuedLlmPolicy
impl DecisionPolicy for QueuedLlmPolicy
fn identity(&self) -> &DecisionPolicyIdentity
fn decide( &self, ticket: &DecisionTicket, ) -> Result<PolicyDecision, DecisionError>
Source§impl ExternalPolicy for QueuedLlmPolicy
impl ExternalPolicy for QueuedLlmPolicy
fn submitted_response( &self, ticket: &DecisionTicket, ) -> Option<ExternalDecisionResponse>
fn external_request(&self, ticket: &DecisionTicket) -> ExternalDecisionRequest
Source§impl LlmPolicy for QueuedLlmPolicy
impl LlmPolicy for QueuedLlmPolicy
fn model_identity(&self) -> &LlmModelIdentity
Auto Trait Implementations§
impl Freeze for QueuedLlmPolicy
impl RefUnwindSafe for QueuedLlmPolicy
impl Send for QueuedLlmPolicy
impl Sync for QueuedLlmPolicy
impl Unpin for QueuedLlmPolicy
impl UnsafeUnpin for QueuedLlmPolicy
impl UnwindSafe for QueuedLlmPolicy
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