Skip to content

Commit

Permalink
Fix Request Body
Browse files Browse the repository at this point in the history
Fix cache req body
  • Loading branch information
svilupp authored Jul 11, 2024
2 parents 28a5de8 + 0a331fe commit f0702da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
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

2 comments on commit f0702da

@svilupp
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Added

  • 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)

Commits

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/110842

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.0 -m "<description of version>" f0702daec5ff8886ab491213d125d37583f47baf
git push origin v0.4.0

Also, note the warning: This looks like a new registration that registers version 0.4.0.
Ideally, you should register an initial release with 0.0.1, 0.1.0 or 1.0.0 version numbers
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.