MCPcopy Create free account
hub / github.com/Autoparallel/learner / init

Function init

crates/learnerd/src/commands/init.rs:25–89  ·  view source on GitHub ↗

Function for the [`Commands::Init`] in the CLI.

(interaction: &mut I, init_args: InitArgs)

Source from the content-addressed store, hash-verified

23
24/// Function for the [`Commands::Init`] in the CLI.
25pub async fn init<I: UserInteraction>(interaction: &mut I, init_args: InitArgs) -> Result<()> {
26 let InitArgs { db_path, storage_path, no_default_retrievers } = init_args;
27 // Throughout, assume we are using default config path (`~/.learner`)
28
29 // Set database storage location
30 let config = if let Some(db_path) = db_path {
31 Config::default().with_database_path(&db_path)
32 } else if !interaction.confirm(&format!(
33 "Would you like to use the default path {:?} for storing the Learner database?",
34 Database::default_path(),
35 ))? {
36 interaction.reply(ResponseContent::Info(
37 "Please pass in your intended database storage path using --db-path",
38 ))?;
39 return Ok(());
40 } else {
41 Config::default()
42 };
43
44 if config.database_path.exists()
45 && !interaction.confirm(
46 "Database already exists at this location, do you want to overwrite this database?",
47 )?
48 {
49 interaction.reply(ResponseContent::Info(
50 "Please choose a different location for this new Learner database using --db-path",
51 ))?;
52 return Ok(());
53 }
54
55 // Set document storage location
56 let config = if let Some(storage_path) = storage_path {
57 config.with_storage_path(&storage_path)
58 } else if !interaction.confirm(&format!(
59 "Would you like to use the default path {:?} for storing documents?",
60 Database::default_storage_path(),
61 ))? {
62 interaction.reply(ResponseContent::Info(
63 "Please pass in your intended database storage path using --storage-path",
64 ))?;
65 return Ok(());
66 } else {
67 config
68 };
69
70 // Create learner with this configuration and with the default retrievers (arXiv, DOI, IACR)
71 if !no_default_retrievers {
72 interaction
73 .reply(ResponseContent::Info("Using the default set of retrievers (arXiv, DOI, and DOI)."))?;
74 std::fs::create_dir_all(Config::default_path()?.join("retrievers"))?;
75 std::fs::write(config.retrievers_path.join("arxiv.toml"), learner::ARXIV_CONFIG)?;
76 std::fs::write(config.retrievers_path.join("doi.toml"), learner::DOI_CONFIG)?;
77 std::fs::write(config.retrievers_path.join("iacr.toml"), learner::IACR_CONFIG)?;
78 }
79 Learner::builder().with_config(config.clone()).build().await?;
80 std::fs::write(Config::default_path()?.join("config.toml"), toml::to_string(&config)?)?;
81 interaction.reply(ResponseContent::Success(&format!(
82 "Created Learner configuration with\nConfig path: {:?}\nDatabase path: {:?}\nDocument storage \

Callers 2

mainFunction · 0.85
initMethod · 0.85

Calls 6

with_database_pathMethod · 0.80
with_storage_pathMethod · 0.80
buildMethod · 0.80
confirmMethod · 0.45
replyMethod · 0.45
with_configMethod · 0.45

Tested by

no test coverage detected