diff options
| author | sigoden <sigoden@gmail.com> | 2024-02-23 13:15:18 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-02-23 13:15:18 +0800 |
| commit | 763841212826142ce248ef3d94524424c6316b0b (patch) | |
| tree | 6805fb523b3fa149744d8534928941a023e0d149 /src/config/role.rs | |
| parent | 6c0204e6965bf13c3d883ea5fa65d52415acd530 (diff) | |
| download | aichat-763841212826142ce248ef3d94524424c6316b0b.tar.gz | |
feat: support `-e/--execute` to execute shell command (#318)
Diffstat (limited to 'src/config/role.rs')
| -rw-r--r-- | src/config/role.rs | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/src/config/role.rs b/src/config/role.rs index bd7216c..ff60b55 100644 --- a/src/config/role.rs +++ b/src/config/role.rs @@ -1,4 +1,7 @@ -use crate::client::{Message, MessageContent, MessageRole}; +use crate::{ + client::{Message, MessageContent, MessageRole}, + utils::{detect_os, detect_shell}, +}; use anyhow::{Context, Result}; use serde::{Deserialize, Serialize}; @@ -18,6 +21,39 @@ pub struct Role { } impl Role { + pub fn for_execute() -> Self { + let os = detect_os(); + let shell = detect_shell(); + let shell = match shell.rsplit_once('/') { + Some((_, v)) => v, + None => &shell, + }; + Self { + name: "__builtin__".into(), + prompt: format!( + r#"Provide only {shell} commands for {os} without any description. +If there is a lack of details, provide most logical solution. +Ensure the output is a valid shell command. +If multiple steps required try to combine them together using &&. +Provide only plain text without Markdown formatting. +Do not provide markdown formatting such as ```"# + ), + temperature: None, + } + } + + pub fn for_describe() -> Self { + Self { + name: "__builtin__".into(), + prompt: r#"Provide a terse, single sentence description of the given shell command. +Describe each argument and option of the command. +Provide short responses in about 80 words. +APPLY MARKDOWN formatting when possible."# + .into(), + temperature: None, + } + } + pub fn info(&self) -> Result<String> { let output = serde_yaml::to_string(&self) .with_context(|| format!("Unable to show info about role {}", &self.name))?; |
