feat(server): (Do Not Merge) POC - implement hooks for server#110
Draft
lukeroantreeONS wants to merge 1 commit intomainfrom
Draft
feat(server): (Do Not Merge) POC - implement hooks for server#110lukeroantreeONS wants to merge 1 commit intomainfrom
lukeroantreeONS wants to merge 1 commit intomainfrom
Conversation
…owapi ratelimiter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Quick proof-of-concept for extending the VectorStore's idea of 'hooks' to the server.
✨ Summary
Do Not Merge - proof of concept only.
I had some time on a train journey, so put together this proposal for extending the idea of user-defined hooks to the server, and showed in a demo that this can allow them to add customisations like rate-limiting themselves.
As part of this, I split the server module's
start_api()method intosetup_api()(which returns a FastAPI application) andstart_api()which runs it with Uvicorn.These changes show the main idea behind the proposal, but in order to get the slowapi ratelimiter working I had to tweak the endpoint definitions slightly (making the request parameter explicit instead of implicit, removing the response Pydantic object type hinting as ratelimiter hijacks the response object). Some of these changes (removal of the type hinting / validation) can be avoided by configuring the ratelimiter more carefully - I didn't want to devote time to that while it's still just a proposal.
As this includes breaking, and un-discussed, this draft PR is only to show the idea to facilitate discussion, not to be merged.
📜 Changes Introduced
✅ Checklist
terraform fmt&terraform validate)🔍 How to Test
build the package with
uv buildinstall
slowapi(uv pip install slowapi)copy the fake soc dataset in to the
testbed/directoryrun the example script (
cd testbed; uv run --script ./server_hooks_slowapi_ratelimiter_poc.py)open the swagger page, go to the search endpoint 'Try It Out', execute 3 times (checking the output after each). Expect 2 normal outputs and a rate limit error on the third (if 3 performed in under a minute).