capability_example/
generate_string_skeleton.rs1crate::ix!();
3
4impl GrowerModel {
5
6 pub async fn generate_string_skeleton(
7 language_model_client: &GrowerLanguageModelClient,
8 grower_inputs: &GrowerInputs,
9 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration
10
11 ) -> Result<JustifiedStringSkeleton,GrowerStringSkeletonGenerationError> {
12
13 let query_string = Self::string_skeleton_generation_query_string(grower_inputs,justified_grower_tree_configuration);
14 info!("generating our StringSkeleton with the query string:\n{query_string}");
15 type Target = JustifiedStringSkeleton;
16 type Error = GrowerStringSkeletonGenerationError;
17 language_model_client.run_oneshot_query_with_repair::<Target,Error>(&query_string)
18 }
19
20 pub async fn handle_string_skeleton_generation_error(
21 e: GrowerStringSkeletonGenerationError,
22 client: &GrowerLanguageModelClient,
23 grower_inputs: &GrowerInputs,
24 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration,
25
26 ) -> Result<JustifiedStringSkeleton,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()
31 .grower_inputs(grower_inputs.clone())
32 .maybe_ungrown_justified_grower_tree_configuration(Some(justified_grower_tree_configuration.clone()))
33 .build()
34 .unwrap();
35
36 partially_grown_model.save_to_file(grower_inputs.output_file_name()).await?;
37
38 Err(GrowerModelGenerationError::StringSkeleton {
39 error: e,
40 fragment: partially_grown_model,
41 })
42 }
43
44 pub fn string_skeleton_generation_query_string(
45 grower_inputs: &GrowerInputs,
46 justified_grower_tree_configuration: &JustifiedGrowerTreeConfiguration
47 ) -> String {
48
49 let target = grower_inputs.target();
50 let global_environment_display = grower_inputs.global_environment_display();
51 let sub_environment_display = grower_inputs.sub_environment_display();
52 let neighboring_crate_display = grower_inputs.neighbor_display();
53 let string_skeleton_template = RigorousJsonCommandBuilder::instructions_with_justification::<StringSkeleton>();
54 let stamped_grower_tree_configuration_instructions = justified_grower_tree_configuration.stamp();
55
56 formatdoc!{
57 r#"
58 We are growing a tree-like representation of the domain of `{target}`.
59
60 We have a set of tree-grower parameters, characterized as follows:
61
62 {stamped_grower_tree_configuration_instructions}
63
64 We are growing this tree in the following global environment:
65 {global_environment_display}
66 This environment is comprised of the following sub-environments:
67 {sub_environment_display}
68
69 Our target tree `{target}` is growing in the context of the following neighbors:
70 {neighboring_crate_display}
71
72 There is a separately configured tree possible for each neighbor.
73
74 During the `StringSkeleton` growing procedure, please use the exact `GrowerTreeConfiguration` parameters mentioned above.
75
76 These parameters guide the overall shape of the growing tree. They help us identify domain nodes which belong to it.
77
78 They help us decide which domain paths are most useful for us to explore while mapping the concrete domain representation itself.
79
80 We would like you to perform the tree-growth procedure for us by using these exact parameters.
81
82 While you grow the tree, remember to consider the influence (if any) of each provided sub-environment.
83
84 Please also simultaneously leverage your knowledge of the global environment to guide tree-growth.
85
86 The list of neighboring concepts is primarily useful for determining where to place emphasis during the growing process.
87
88 Since each neighbor may ultimately grow its own tree, we seek to minimize model overlap between neighbors.
89
90 We also seek to simultaneously maximize the expressive potential of the local tree-model we are here growing.
91
92 This expressive potential is provided by the shape and nature of the tree within the target domain.
93
94 The grower parameters determine how it is to be grown.
95
96 Remember: it is crucially important each node has a good name. The node names MUST NOT be generic.
97 WE DO NOT ACCEPT generic node names like "LeafHolderA", or "AggregateNode_Alpha_Sub2".
98 Instead, please choose node names with practical and significant meaning to the model domain.
99
100 Now, we will generate the actual tree for `{target}`.
101
102 Here is how we want you to perform the expansion:
103
104 {string_skeleton_template}
105
106 Thank you!
107 "#
108 }
109 }
110}