Download crates/forge_services/src/tool_services/followup.rs from SaylorTwift/forgecode: direct link, hf CLI and curl.
- Browser
- Download file 1.51 kB
-
https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_services/src/tool_services/followup.rs
- Command line
-
hf download hf://SaylorTwift/forgecode/crates/forge_services/src/tool_services/followup.rs
-
curl -L -o followup.rs https://huggingface.co/SaylorTwift/forgecode/resolve/main/crates/forge_services/src/tool_services/followup.rs
1.51 kB
| use std::sync::Arc; | |
| use forge_app::{FollowUpService, UserInfra}; | |
| /// Use this tool when you encounter ambiguities, need clarification, or require | |
| /// more details to proceed effectively. Use this tool judiciously to maintain a | |
| /// balance between gathering necessary information and avoiding excessive | |
| /// back-and-forth. | |
| pub struct ForgeFollowup<F> { | |
| infra: Arc<F>, | |
| } | |
| impl<F> ForgeFollowup<F> { | |
| pub fn new(infra: Arc<F>) -> Self { | |
| Self { infra } | |
| } | |
| } | |
| impl<F: UserInfra> FollowUpService for ForgeFollowup<F> { | |
| async fn follow_up( | |
| &self, | |
| question: String, | |
| options: Vec<String>, | |
| multiple: Option<bool>, | |
| ) -> anyhow::Result<Option<String>> { | |
| let inquire = &self.infra; | |
| let result = match (options.is_empty(), multiple.unwrap_or_default()) { | |
| (true, _) => inquire.prompt_question(&question).await?, | |
| (false, true) => inquire | |
| .select_many(&question, options) | |
| .await? | |
| .map(|selected| { | |
| format!( | |
| "User selected {} option(s): {}", | |
| selected.len(), | |
| selected.join(", ") | |
| ) | |
| }), | |
| (false, false) => inquire | |
| .select_one(&question, options) | |
| .await? | |
| .map(|selected| format!("User selected: {selected}")), | |
| }; | |
| Ok(result) | |
| } | |
| } | |