feat: provide `--prompt` for adding a prompt from cli (#62)

pull/63/head
sigoden 1 year ago committed by GitHub
parent 52de7ec33a
commit d48cd64162
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,9 @@ use clap::Parser;
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Cli {
/// Add a GPT prompt
#[clap(short, long)]
pub prompt: Option<String>,
/// Turn off highlight
#[clap(short = 'H', long)]
pub no_highlight: bool,

@ -193,7 +193,7 @@ impl Config {
Ok(())
}
pub fn create_temp_role(&mut self, prompt: &str) -> Result<()> {
pub fn add_prompt(&mut self, prompt: &str) -> Result<()> {
let role = Role::new(prompt, self.temperature);
if let Some(conversation) = self.conversation.as_mut() {
conversation.update_role(&role)?;

@ -48,6 +48,9 @@ fn main() -> Result<()> {
if cli.no_highlight {
config.lock().highlight = false;
}
if let Some(prompt) = &cli.prompt {
config.lock().add_prompt(prompt)?;
}
let no_stream = cli.no_stream;
let client = ChatGptClient::init(config.clone())?;
if atty::isnt(atty::Stream::Stdin) {

@ -75,7 +75,7 @@ impl ReplCmdHandler {
print_now!("\n");
}
ReplCmd::Prompt(prompt) => {
self.config.lock().create_temp_role(&prompt)?;
self.config.lock().add_prompt(&prompt)?;
print_now!("\n");
}
ReplCmd::ViewInfo => {

Loading…
Cancel
Save