capability_example/
generate_grower_tree_configuration.rs1crate::ix!();
3
4impl GrowerModel {
5
6 pub async fn generate_grower_tree_configuration(
7 language_model_client: &GrowerLanguageModelClient,
8 grower_inputs: &GrowerInputs
9
10 ) -> Result<JustifiedGrowerTreeConfiguration,GrowerTreeConfigurationGenerationError> {
11
12 let query_string = Self::grower_tree_configuration_generation_query_string(grower_inputs);
13
14 info!("generating our GrowerTreeConfiguration with the query string:\n{query_string}");
15
16 type Target = JustifiedGrowerTreeConfiguration;
17 type Error = GrowerTreeConfigurationGenerationError;
18 language_model_client.run_oneshot_query_with_repair::<Target,Error>(&query_string)
19 }
20
21 pub async fn handle_grower_tree_configuration_generation_error(
22 e: GrowerTreeConfigurationGenerationError,
23 client: &GrowerLanguageModelClient,
24 grower_inputs: &GrowerInputs
25
26 ) -> Result<JustifiedGrowerTreeConfiguration,GrowerModelGenerationError> {
27
28 warn!("Here we can attempt retry. if we do, we must decide how many times");
29
30 let partially_grown_model: PartiallyGrownModel = PartiallyGrownModelBuilder::default()
34 .grower_inputs(grower_inputs.clone())
35 .build()
36 .unwrap();
37
38 partially_grown_model.save_to_file(grower_inputs.output_file_name()).await?;
39
40 Err(GrowerModelGenerationError::Config {
41 error: e,
42 fragment: partially_grown_model,
43 })
44 }
45
46 pub fn grower_tree_configuration_generation_query_string(grower_inputs: &GrowerInputs) -> String {
47
48 let target = grower_inputs.target();
49 let global_environment_display = grower_inputs.global_environment_display();
50 let sub_environment_display = grower_inputs.sub_environment_display();
51 let neighbor_display = grower_inputs.neighbor_display();
52 let grower_tree_template = RigorousJsonCommandBuilder::instructions_with_justification::<GrowerTreeConfiguration>();
53
54 formatdoc!{r#"
55 We would like to grow a tree-structure representative of `{target}`.
56
57 Our goal is to produce an exact json representation of the configuration structure required to grow it.
58
59 We have provided a description of the global environment as well as provided the relevant sub-environment details.
60
61 We have specified the desired target concept: '{target}'.
62
63 Please select the optimal tree-grower configuration parameters (depth, breadth, density, balance, contextual influence, leaf granularity, etc).
64
65 We will use these parameters downstream to grow a tree-like data-structure charting and mapping `{target}`.
66
67 Justify clearly each parameter choice based on domain-specific considerations.
68
69 We take into account contextual connections with the provided neighbors (listed below).
70
71 We take into account the intended granularity and level-of-detail of the model.
72
73 ## Here is the global environment we are working in:
74 {global_environment_display}
75
76 ## Here are the sub-environments we need to consider:
77 {sub_environment_display}
78
79 ## Here is the name of our target:
80 {target}
81
82 ## Here is the list of neighbors we use for contextual reference:
83 {neighbor_display}
84
85 ## Here is how we want you to perform the expansion:
86
87 {grower_tree_template}
88
89 While you determine the optimal grow-parameters, please consider all sub-environments as well as the full set of information we have provided.
90
91 The list of neighbors is primarily useful for determining where to place emphasis. Each neighbor will ultimately have its own tree.
92
93 Therefore, we seek to *minimize* model overlap between neighbors while simultaneously *maximizing* the expressive potential within the target domain provided by each individual tree.
94
95 We may also use the list of neighbors to create useful synergies between targets.
96
97 For example, a `fishing` target, aware that it neighbors `ice-shelter-building` and `primitive-tool-making`, may select to grow a `spear-fishing` subtree within its model.
98
99 Conversely, a `fishing` target, aware that it neighbors `spear-fishing`, may choose to work around the `spear-fishing` domain so as to not introduce unnecessary domain overlap.
100
101 If you decide to make use of neighbor-aware tree-growing parameter transformations, please indicate your decision to do so (where applicable) within your justifications.
102
103 The nodes in the tree will model the domain itself and should not have names reflecting meta-information regarding the shape of the tree.
104
105 Importantly, the node names should not be meta-aware as to whether or not they are `leaf` or `aggregate`, for example, or which child number they represent etc.
106 "#
107 }
108 }
109}