feat: Added variable interpolation for conversation starters in agents
This commit is contained in:
+14
-6
@@ -285,7 +285,7 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn banner(&self) -> String {
|
pub fn banner(&self) -> String {
|
||||||
self.config.banner()
|
self.config.banner(&self.conversation_starters())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn name(&self) -> &str {
|
pub fn name(&self) -> &str {
|
||||||
@@ -300,16 +300,25 @@ impl Agent {
|
|||||||
self.rag.clone()
|
self.rag.clone()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn conversation_starters(&self) -> &[String] {
|
pub fn conversation_starters(&self) -> Vec<String> {
|
||||||
&self.config.conversation_starters
|
self.config
|
||||||
|
.conversation_starters
|
||||||
|
.iter()
|
||||||
|
.map(|starter| self.interpolate_text(starter))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn interpolated_instructions(&self) -> String {
|
pub fn interpolated_instructions(&self) -> String {
|
||||||
let mut output = self
|
let output = self
|
||||||
.session_dynamic_instructions
|
.session_dynamic_instructions
|
||||||
.clone()
|
.clone()
|
||||||
.or_else(|| self.shared_dynamic_instructions.clone())
|
.or_else(|| self.shared_dynamic_instructions.clone())
|
||||||
.unwrap_or_else(|| self.config.instructions.clone());
|
.unwrap_or_else(|| self.config.instructions.clone());
|
||||||
|
self.interpolate_text(&output)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn interpolate_text(&self, text: &str) -> String {
|
||||||
|
let mut output = text.to_string();
|
||||||
for (k, v) in self.variables() {
|
for (k, v) in self.variables() {
|
||||||
output = output.replace(&format!("{{{{{k}}}}}"), v)
|
output = output.replace(&format!("{{{{{k}}}}}"), v)
|
||||||
}
|
}
|
||||||
@@ -555,12 +564,11 @@ impl AgentConfig {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn banner(&self) -> String {
|
fn banner(&self, conversation_starters: &[String]) -> String {
|
||||||
let AgentConfig {
|
let AgentConfig {
|
||||||
name,
|
name,
|
||||||
description,
|
description,
|
||||||
version,
|
version,
|
||||||
conversation_starters,
|
|
||||||
..
|
..
|
||||||
} = self;
|
} = self;
|
||||||
let starters = if conversation_starters.is_empty() {
|
let starters = if conversation_starters.is_empty() {
|
||||||
|
|||||||
Reference in New Issue
Block a user