Skip to content

Commit 0a331fe

Browse files
committed
fix cache req body
1 parent 28a5de8 commit 0a331fe

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Added a launcher function `launch` to make it easier to launch the app.
1717
- Semantic caching enabled by SemanticCaches.jl. You can change it by setting `cached=false` in the `launch()` function.
1818

19+
### Fixed
20+
- Fixed a bug when caching would error for certain types of HTTP body (eg, `IOBuffer`)
21+
22+
1923
## [0.3.0]
2024

2125
### Added

src/CacheLayer.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ const HASH_CACHE = HashCache()
3232
function cache_layer(handler)
3333
return function (req; kw...)
3434
VERBOSE = Base.get(ENV, "CACHES_VERBOSE", "true") == "true"
35-
if req.method == "POST" && !isempty(req.body)
35+
has_body = (req.body isa IOBuffer ||
36+
(req.body isa AbstractVector && !isempty(req.body)))
37+
if req.method == "POST" && has_body
3638
body = JSON3.read(copy(req.body))
3739
## chat/completions is for OpenAI, v1/messages is for Anthropic
3840
if occursin("v1/chat/completions", req.target) ||

0 commit comments

Comments
 (0)