From 9c04455e363d076cd7582fe9d476aa0fd6d86ea8 Mon Sep 17 00:00:00 2001 From: sigoden Date: Mon, 13 Mar 2023 10:09:01 +0800 Subject: feat: support role args (#69) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: support role args We can use role args to pass some additional arguments to the prompt. ``` - name: convert:json:yaml prompt: convert __ARG1__ below to __ARG2__ ``` `:json:yaml` is `role args`. It has two args: - arg1 `json`, it will replace __ARG1__ in prompt - arg2 `yaml`, it will replace __ARG2__ in prompt ``` 〉.role convert:json:yaml name: convert:json:yaml prompt: convert json below to yaml temperature: null 〉.role convert:yaml:json name: convert:yaml:json prompt: convert yaml below to json temperature: null ``` different role args, will generate different prompts. * small updates --- src/config/mod.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/config/mod.rs') diff --git a/src/config/mod.rs b/src/config/mod.rs index a37140c..569e434 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -120,7 +120,7 @@ impl Config { } pub fn find_role(&self, name: &str) -> Option { - self.roles.iter().find(|v| v.name == name).cloned() + self.roles.iter().find(|v| v.match_name(name)).cloned() } pub fn config_dir() -> Result { @@ -200,7 +200,8 @@ impl Config { pub fn change_role(&mut self, name: &str) -> Result { match self.find_role(name) { - Some(role) => { + Some(mut role) => { + role.complete_prompt_args(name); if let Some(conversation) = self.conversation.as_mut() { conversation.update_role(&role)?; } -- cgit v1.2.3