Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cache req body #17

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added a launcher function `launch` to make it easier to launch the app.
- Semantic caching enabled by SemanticCaches.jl. You can change it by setting `cached=false` in the `launch()` function.

### Fixed
- Fixed a bug when caching would error for certain types of HTTP body (eg, `IOBuffer`)


## [0.3.0]

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/CacheLayer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const HASH_CACHE = HashCache()
function cache_layer(handler)
return function (req; kw...)
VERBOSE = Base.get(ENV, "CACHES_VERBOSE", "true") == "true"
if req.method == "POST" && !isempty(req.body)
has_body = (req.body isa IOBuffer ||
(req.body isa AbstractVector && !isempty(req.body)))
if req.method == "POST" && has_body
body = JSON3.read(copy(req.body))
## chat/completions is for OpenAI, v1/messages is for Anthropic
if occursin("v1/chat/completions", req.target) ||
Expand Down
Loading