capability_example/
generate_annotated_leaf_holder_expansions.rs1crate::ix!();
3
4impl GrowerModel {
5
6 pub async fn generate_annotated_leaf_holder_expansions(
7 language_model_client: &GrowerLanguageModelClient,
8 grower_inputs: &GrowerInputs,
9 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
10 stripped_string_skeleton: &StrippedStringSkeleton,
11 core_string_skeleton: &CoreStringSkeleton,
12
13 ) -> Result<AnnotatedLeafHolderExpansions,GrowerAnnotatedLeafHolderExpansionsGenerationError> {
14
15 let query_string = Self::annotated_leaf_holder_expansions_generation_query_string(
16 grower_inputs,
17 justified_grower_tree_configuration,
18 core_string_skeleton,
19 );
20
21 info!("generating our AnnotatedLeafHolderExpansions with the query string:\n{query_string}");
22
23 type Target = AnnotatedLeafHolderExpansions;
24 type Error = GrowerAnnotatedLeafHolderExpansionsGenerationError;
25
26 language_model_client.run_oneshot_query_with_repair::<Target,Error>(&query_string)
27 }
28
29 pub async fn handle_annotated_leaf_holder_expansion_generation_error(
30 e: GrowerAnnotatedLeafHolderExpansionsGenerationError,
31 language_model_client: &GrowerLanguageModelClient,
32 grower_inputs: &GrowerInputs,
33 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
34 justified_string_skeleton: &JustifiedStringSkeleton,
35 stripped_string_skeleton: &StrippedStringSkeleton,
36 core_string_skeleton: &CoreStringSkeleton,
37
38 ) -> Result<AnnotatedLeafHolderExpansions,GrowerModelGenerationError> {
39
40 warn!("Here we can attempt retry. if we do, we must decide how many times");
41
42 let partially_grown_model: PartiallyGrownModel = PartiallyGrownModelBuilder::default()
43 .grower_inputs(grower_inputs.clone())
44 .maybe_ungrown_justified_grower_tree_configuration(Some(justified_grower_tree_configuration.clone()))
45 .maybe_ungrown_justified_string_skeleton(Some(justified_string_skeleton.clone()))
46 .maybe_ungrown_stripped_string_skeleton(Some(stripped_string_skeleton.clone()))
47 .maybe_ungrown_core_string_skeleton(Some(core_string_skeleton.clone()))
48 .build()
49 .unwrap();
50
51 partially_grown_model.save_to_file(grower_inputs.output_file_name()).await?;
52
53 Err(GrowerModelGenerationError::AnnotatedLeafHolderExpansions {
54 error: e,
55 fragment: partially_grown_model,
56 })
57 }
58
59 pub fn annotated_leaf_holder_expansions_generation_query_string(
60 grower_inputs: &GrowerInputs,
61 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
62 core_string_skeleton: &CoreStringSkeleton,
63 ) -> String {
64
65 let target = grower_inputs.target();
66 let global_environment_display = grower_inputs.global_environment_display();
67 let sub_environment_display = grower_inputs.sub_environment_display();
68 let annotated_leaf_holder_expansions_template = RigorousJsonCommandBuilder::instructions::<AnnotatedLeafHolderExpansions>();
70
71 formatdoc!{
72 r#"
73 ## We are growing a skill tree for the following domain:
74 {target}
75
76 ## We have already calculated the overall model shape. It looks like this:
77 {core_string_skeleton:#?}
78
79 We annotate each leaf to provide context and to weave it skillfully into the model tree DNA.
80
81 We generate a data structure encapsulating the LeafHolder expansions along with their variant annotations.
82
83 We generate these annotations knowing that the tree structure is being grown in the following environment:
84 {global_environment_display}
85
86 ## This environment is endowed with the following sub-domains:
87 {sub_environment_display}
88
89 Knowledge of the environment and sub-domains is already baked into the shape of the tree.
90
91 The tree is rooted in the domain starting point.
92
93 The environment is shared by the model annotator whose role you adopt.
94
95 ## Here is how we want you to perform the expansion:
96 {annotated_leaf_holder_expansions_template}
97 "#
98 }
99 }
100}