refactor: rename `function_filter` to `function_matcher` (#535)

pull/537/head
sigoden 4 weeks ago committed by GitHub
parent ba3bcfd67c
commit 50b13d2de9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -167,14 +167,14 @@ impl Input {
let mut functions = None;
if self.config.read().function_calling && model.supports_function_calling() {
let config = self.config.read();
let function_filter = if let Some(session) = self.session(&config.session) {
session.function_filter()
let function_matcher = if let Some(session) = self.session(&config.session) {
session.function_matcher()
} else if let Some(role) = self.role() {
role.function_filter.as_deref()
role.function_matcher.as_deref()
} else {
None
};
functions = config.function.filtered_declarations(function_filter);
functions = config.function.select(function_matcher);
};
Ok(SendData {
messages,

@ -29,7 +29,7 @@ pub struct Role {
#[serde(skip_serializing_if = "Option::is_none")]
pub top_p: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub function_filter: Option<String>,
pub function_matcher: Option<String>,
}
impl Role {
@ -40,7 +40,7 @@ impl Role {
temperature: None,
model_id: None,
top_p: None,
function_filter: None,
function_matcher: None,
}
}
@ -74,13 +74,13 @@ async function timeout(ms) {
("%functions%", String::new(), Some(".*".into())),
]
.into_iter()
.map(|(name, prompt, function_filter)| Self {
.map(|(name, prompt, function_matcher)| Self {
name: name.into(),
prompt,
model_id: None,
temperature: None,
top_p: None,
function_filter,
function_matcher,
})
.collect()
}

@ -22,7 +22,7 @@ pub struct Session {
#[serde(skip_serializing_if = "Option::is_none")]
top_p: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
function_filter: Option<String>,
function_matcher: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
save_session: Option<bool>,
messages: Vec<Message>,
@ -50,7 +50,7 @@ impl Session {
model_id: config.model.id(),
temperature: config.temperature,
top_p: config.top_p,
function_filter: None,
function_matcher: None,
save_session: config.save_session,
messages: Default::default(),
compressed_messages: Default::default(),
@ -96,8 +96,8 @@ impl Session {
self.top_p
}
pub fn function_filter(&self) -> Option<&str> {
self.function_filter.as_deref()
pub fn function_matcher(&self) -> Option<&str> {
self.function_matcher.as_deref()
}
pub fn save_session(&self) -> Option<bool> {
@ -134,8 +134,8 @@ impl Session {
if let Some(top_p) = self.top_p() {
data["top_p"] = top_p.into();
}
if let Some(function_filter) = self.function_filter() {
data["function_filter"] = function_filter.into();
if let Some(function_matcher) = self.function_matcher() {
data["function_matcher"] = function_matcher.into();
}
if let Some(save_session) = self.save_session() {
data["save_session"] = save_session.into();
@ -170,8 +170,8 @@ impl Session {
items.push(("top_p", top_p.to_string()));
}
if let Some(function_filter) = self.function_filter() {
items.push(("function_filter", function_filter.into()));
if let Some(function_matcher) = self.function_matcher() {
items.push(("function_matcher", function_matcher.into()));
}
if let Some(save_session) = self.save_session() {
@ -247,14 +247,14 @@ impl Session {
}
}
pub fn set_functions(&mut self, function_filter: Option<&str>) {
self.function_filter = function_filter.map(|v| v.to_string());
pub fn set_function_matcher(&mut self, function_matcher: Option<&str>) {
self.function_matcher = function_matcher.map(|v| v.to_string());
}
pub fn set_role_properties(&mut self, role: &Role) {
self.set_temperature(role.temperature);
self.set_top_p(role.top_p);
self.set_functions(role.function_filter.as_deref());
self.set_function_matcher(role.function_matcher.as_deref());
}
pub fn set_save_session(&mut self, value: Option<bool>) {

@ -126,9 +126,9 @@ impl Function {
})
}
pub fn filtered_declarations(&self, filter: Option<&str>) -> Option<Vec<FunctionDeclaration>> {
let filter = filter?;
let regex = Regex::new(&format!("^({filter})$")).ok()?;
pub fn select(&self, matcher: Option<&str>) -> Option<Vec<FunctionDeclaration>> {
let matcher = matcher?;
let regex = Regex::new(&format!("^({matcher})$")).ok()?;
let output: Vec<FunctionDeclaration> = self
.declarations
.iter()

Loading…
Cancel
Save