Skip to content

Commit 2c5828f

Browse files
committed
feature: req-reply cache for get tool function params
1 parent 6e566a2 commit 2c5828f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

server/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ bytes = "1.9.0"
192192
pagefind = { version = "1.3.0" }
193193
tl = "0.7.8"
194194
url = "2.5.4"
195+
actix-request-reply-cache = "0.1.5"
195196

196197
[build-dependencies]
197198
dotenvy = "0.15.7"

server/src/lib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use crate::{
1515
};
1616
use actix_cors::Cors;
1717
use actix_identity::IdentityMiddleware;
18+
use actix_request_reply_cache::RedisCacheMiddlewareBuilder;
1819
use actix_session::{config::PersistentSession, storage::RedisSessionStore, SessionMiddleware};
1920
use actix_web::{
2021
cookie::{Key, SameSite},
@@ -1101,6 +1102,18 @@ pub fn main() -> std::io::Result<()> {
11011102
.service(
11021103
web::resource("/message/get_tool_function_params")
11031104
.route(web::post().to(handlers::message_handler::get_tool_function_params))
1105+
.wrap(RedisCacheMiddlewareBuilder::new(redis_url)
1106+
.cache_prefix("function_params:")
1107+
.ttl(60 * 60 * 24)
1108+
.cache_if(|ctx| {
1109+
if let Ok(req_body) = serde_json::from_slice::<serde_json::Value>(ctx.body) {
1110+
return req_body.get("audio_input").is_none() || req_body.get("audio_input").unwrap().is_null();
1111+
}
1112+
1113+
true
1114+
})
1115+
.build()
1116+
)
11041117
)
11051118
.service(
11061119
web::resource("/message/{message_id}")

0 commit comments

Comments
 (0)