capability_example/
generate_core_string_skeleton.rs1crate::ix!();
3
4impl GrowerModel {
5
6 pub async fn generate_core_string_skeleton(
7 language_model_client: &GrowerLanguageModelClient,
8 grower_inputs: &GrowerInputs,
9 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
10 stripped_string_skeleton: &StrippedStringSkeleton,
11
12 ) -> Result<CoreStringSkeleton,GrowerCoreStringSkeletonGenerationError> {
13
14 let query_string = Self::core_string_skeleton_generation_query_string(grower_inputs,justified_grower_tree_configuration,stripped_string_skeleton);
15 info!("generating our CoreStringSkeleton with the query string:\n{query_string}");
16 type Target = CoreStringSkeleton;
17 type Error = GrowerCoreStringSkeletonGenerationError;
18 language_model_client.run_oneshot_query_with_repair::<Target,Error>(&query_string)
19 }
20
21 pub async fn handle_core_string_skeleton_generation_error(
22 e: GrowerCoreStringSkeletonGenerationError,
23 client: &GrowerLanguageModelClient,
24 grower_inputs: &GrowerInputs,
25 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
26 justified_string_skeleton: &JustifiedStringSkeleton,
27 stripped_string_skeleton: &StrippedStringSkeleton,
28
29 ) -> Result<CoreStringSkeleton,GrowerModelGenerationError> {
30
31 warn!("Here we can attempt retry. if we do, we must decide how many times");
32
33 let partially_grown_model: PartiallyGrownModel = PartiallyGrownModelBuilder::default()
34 .grower_inputs(grower_inputs.clone())
35 .maybe_ungrown_justified_grower_tree_configuration(Some(justified_grower_tree_configuration.clone()))
36 .maybe_ungrown_justified_string_skeleton(Some(justified_string_skeleton.clone()))
37 .maybe_ungrown_stripped_string_skeleton(Some(stripped_string_skeleton.clone()))
38 .build()
39 .unwrap();
40
41 partially_grown_model.save_to_file(grower_inputs.output_file_name()).await?;
42
43 Err(GrowerModelGenerationError::CoreStringSkeleton {
44 error: e,
45 fragment: partially_grown_model,
46 })
47 }
48
49 pub fn core_string_skeleton_generation_query_string(
50 grower_inputs: &GrowerInputs,
51 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
52 stripped_string_skeleton: &StrippedStringSkeleton,
53 ) -> String {
54
55 let target = grower_inputs.target();
56 let global_environment_display = grower_inputs.global_environment_display();
57 let sub_environment_display = grower_inputs.sub_environment_display();
58 let core_string_skeleton_template = RigorousJsonCommandBuilder::instructions::<CoreStringSkeleton>();
60
61 formatdoc!{
62 r#"
63 Hello! We are growing a skill tree for the following domain:
64 {target}
65
66 We have already calculated the overall model shape! It looks like this:
67
68 ```model-tree-shape
69 {stripped_string_skeleton}
70 ```
71
72 Now we would like to *create the model itself*.
73
74 To do this, we must generate a useful set of leaves for each LeafHolder node in our tree.
75
76 It is important to remember that we are growing this skill-tree within the context of a *real global environment*, specified like this:
77 {global_environment_display}
78
79 We note that this global environment is also equipped with the following sub-domains:
80 {sub_environment_display}
81
82 The overall shape of our model tree is already adapted to the shape of this target domain given the target skill.
83 However, it is important to understand this concept while we generate the leaves themselves.
84
85 For each LeafHolder node, we generate a number of model leaves determined by the parameter n_leaves>=10.
86 This means we need *at least* exactly this many leaves generated *per LeafHolder node*.
87
88 Ultimately, what we need from you now is *no more and no less than* the strict json structure specified here.
89
90 Here is how we want you to perform the expansion:
91 {core_string_skeleton_template}
92 "#
93 }
94 }
95}