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 189-197)
174fn llm_interface_branch() -> Result<(), Box<dyn std::error::Error>> {
175 let mut canwu = Canwu::demo(202)?;
176 let ticket_id = DecisionTicketId::new(2);
177 enqueue_ticket(
178 &mut canwu,
179 ticket_id,
180 10,
181 DecisionControllerBinding::new(
182 "law-llm-controller",
183 DecisionPolicyIdentity::new(DecisionPolicyKind::Llm, "strict-law-selector", "1"),
184 DecisionAuthority::Actor {
185 actor: Canwu::demo_ids().commander,
186 },
187 ),
188 )?;
189 let mut policy = QueuedLlmPolicy::new(
190 "strict-law-selector",
191 "1",
192 LlmModelIdentity {
193 provider: "not-connected".to_owned(),
194 model: "host-selected-model".to_owned(),
195 prompt_contract: "return one existing option_id and no new action".to_owned(),
196 },
197 );
198 let ticket = canwu.decision_ticket(ticket_id).expect("LLM ticket");
199 let request = policy.external_request(ticket);
200 println!("llm_request={}", serde_json::to_string(&request)?);
201
202 // A real host sends `request` to its model and parses a strict structured
203 // answer. This example supplies the same response object without making a
204 // network call.
205 policy.submit(
206 ticket_id,
207 ExternalDecisionResponse {
208 ticket_version: request.ticket_version,
209 option_id: "pass".to_owned(),
210 provider: "not-connected".to_owned(),
211 request_id: "example-response-1".to_owned(),
212 metadata: BTreeMap::new(),
213 },
214 )?;
215 let evaluation = canwu.drive_decision(
216 canwu.time(),
217 0,
218 DecisionRequestId::new(12),
219 None,
220 ticket_id,
221 &policy,
222 )?;
223 assert!(matches!(evaluation, DecisionEvaluation::Prepared(_)));
224 canwu.step_canonical()?.expect("LLM decision boundary");
225 Ok(())
226}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 205-214)
174fn llm_interface_branch() -> Result<(), Box<dyn std::error::Error>> {
175 let mut canwu = Canwu::demo(202)?;
176 let ticket_id = DecisionTicketId::new(2);
177 enqueue_ticket(
178 &mut canwu,
179 ticket_id,
180 10,
181 DecisionControllerBinding::new(
182 "law-llm-controller",
183 DecisionPolicyIdentity::new(DecisionPolicyKind::Llm, "strict-law-selector", "1"),
184 DecisionAuthority::Actor {
185 actor: Canwu::demo_ids().commander,
186 },
187 ),
188 )?;
189 let mut policy = QueuedLlmPolicy::new(
190 "strict-law-selector",
191 "1",
192 LlmModelIdentity {
193 provider: "not-connected".to_owned(),
194 model: "host-selected-model".to_owned(),
195 prompt_contract: "return one existing option_id and no new action".to_owned(),
196 },
197 );
198 let ticket = canwu.decision_ticket(ticket_id).expect("LLM ticket");
199 let request = policy.external_request(ticket);
200 println!("llm_request={}", serde_json::to_string(&request)?);
201
202 // A real host sends `request` to its model and parses a strict structured
203 // answer. This example supplies the same response object without making a
204 // network call.
205 policy.submit(
206 ticket_id,
207 ExternalDecisionResponse {
208 ticket_version: request.ticket_version,
209 option_id: "pass".to_owned(),
210 provider: "not-connected".to_owned(),
211 request_id: "example-response-1".to_owned(),
212 metadata: BTreeMap::new(),
213 },
214 )?;
215 let evaluation = canwu.drive_decision(
216 canwu.time(),
217 0,
218 DecisionRequestId::new(12),
219 None,
220 ticket_id,
221 &policy,
222 )?;
223 assert!(matches!(evaluation, DecisionEvaluation::Prepared(_)));
224 canwu.step_canonical()?.expect("LLM decision boundary");
225 Ok(())
226}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