capability_example/
manual_flow_strategy.rs1crate::ix!();
3
4pub struct ManualFlowStrategy {
8 query_output_path: PathBuf,
9}
10
11impl From<PathBuf> for ManualFlowStrategy {
12
13 fn from(query_output_path: PathBuf) -> Self {
14 Self {
15 query_output_path
16 }
17 }
18}
19
20impl ManualFlowStrategy {
21
22 #[instrument(level = "trace", skip_all)]
24 async fn write_query_and_instruct_user(
25 &self,
26 query_str: &str,
27 instruction: &str,
28 ) -> Result<(), ManualGrowerFlowError> {
29 let mut file = File::create(&self.query_output_path).await?;
30 file.write_all(query_str.as_bytes()).await?;
31 save_string_to_clipboard(query_str)?;
32 info!("PLEASE RUN THIS QUERY MANUALLY:\n\n{}\n", query_str);
33 info!("{}", instruction);
34 Ok(())
35 }
36}
37
38#[async_trait]
39impl GrowerFlowStrategy for ManualFlowStrategy {
40
41 #[instrument(level = "trace", skip(self, partial, grower_inputs))]
42 async fn fill_justified_tree_configuration(
43 &self,
44 partial: &PartiallyGrownModel,
45 grower_inputs: &GrowerInputs,
46 ) -> Result<Option<JustifiedGrowerTreeConfiguration>, ManualGrowerFlowError> {
47 info!("Missing JustifiedGrowerTreeConfiguration. Generating query for user...");
48 let query_str =
49 GrowerModel::grower_tree_configuration_generation_query_string(grower_inputs);
50 let instruction = "Afterwards, add the result under `maybe_ungrown_justified_grower_tree_configuration` in the partial JSON and re-run.";
51
52 self.write_query_and_instruct_user(&query_str, instruction)
53 .await?;
54 Ok(None)
55 }
56
57 #[instrument(level = "trace", skip(self, partial, grower_inputs, tree_conf))]
58 async fn fill_justified_string_skeleton(
59 &self,
60 partial: &PartiallyGrownModel,
61 grower_inputs: &GrowerInputs,
62 tree_conf: &JustifiedGrowerTreeConfiguration,
63 ) -> Result<Option<JustifiedStringSkeleton>, ManualGrowerFlowError> {
64 info!("We have a JustifiedGrowerTreeConfiguration but no JustifiedStringSkeleton. Generating query...");
65 let query_str =
66 GrowerModel::string_skeleton_generation_query_string(grower_inputs, tree_conf);
67 let instruction = "Afterwards, place the result under `maybe_ungrown_justified_string_skeleton` and re-run.";
68
69 self.write_query_and_instruct_user(&query_str, instruction)
70 .await?;
71 Ok(None)
72 }
73
74 #[instrument(level = "trace", skip(self, partial, grower_inputs, tree_conf, stripped_skel))]
75 async fn fill_core_string_skeleton(
76 &self,
77 partial: &PartiallyGrownModel,
78 grower_inputs: &GrowerInputs,
79 tree_conf: &JustifiedGrowerTreeConfiguration,
80 stripped_skel: &StrippedStringSkeleton,
81 ) -> Result<Option<CoreStringSkeleton>, ManualGrowerFlowError> {
82 info!("We have a StrippedStringSkeleton but no CoreStringSkeleton. Generating query...");
83 let query_str = GrowerModel::core_string_skeleton_generation_query_string(
84 grower_inputs,
85 tree_conf,
86 stripped_skel,
87 );
88 let instruction = "Afterwards, place the result under `maybe_ungrown_core_string_skeleton` and re-run.";
89
90 self.write_query_and_instruct_user(&query_str, instruction)
91 .await?;
92 Ok(None)
93 }
94
95 #[instrument(level = "trace", skip(self, partial, grower_inputs, tree_conf, core_skel))]
96 async fn fill_annotated_leaf_holder_expansions(
97 &self,
98 partial: &PartiallyGrownModel,
99 grower_inputs: &GrowerInputs,
100 tree_conf: &JustifiedGrowerTreeConfiguration,
101 core_skel: &CoreStringSkeleton,
102 ) -> Result<Option<AnnotatedLeafHolderExpansions>, ManualGrowerFlowError> {
103 info!("We have a CoreStringSkeleton but no AnnotatedLeafHolderExpansions. Generating query...");
104 let query_str = GrowerModel::annotated_leaf_holder_expansions_generation_query_string(
105 grower_inputs,
106 tree_conf,
107 core_skel,
108 );
109 let instruction = "Afterwards, place the result under `maybe_ungrown_annotated_leaf_holder_expansions` and re-run.";
110
111 self.write_query_and_instruct_user(&query_str, instruction)
112 .await?;
113 Ok(None)
114 }
115}