-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
langchain[minor], community[minor], core[minor]: Async Cache support and AsyncRedisCache #15817
Changes from all commits
18150e4
83dff04
58256da
3244533
cbba991
c113166
d125f76
589c813
3da8707
088f6a1
6bfb3bc
168cf10
5c5a857
a7b4af4
68bf6db
91d4ed7
6c52107
51fecab
bde6216
8bcec4d
96f8067
8afbc75
9cd1d7c
66f4e49
7e8f604
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# docker-compose to make it easier to spin up integration tests. | ||
# Services should use NON standard ports to avoid collision with | ||
version: "3" | ||
name: langchain-tests | ||
|
||
services: | ||
redis: | ||
image: redis/redis-stack-server:latest | ||
# We use non standard ports since | ||
# these instances are used for testing | ||
# and users may already have existing | ||
# redis instances set up locally | ||
# for other projects | ||
ports: | ||
- "6020:6379" | ||
volumes: | ||
- ./redis-volume:/data |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
from typing import Any, Optional, Sequence | ||
|
||
from langchain_core.outputs import Generation | ||
from langchain_core.runnables import run_in_executor | ||
|
||
RETURN_VAL_TYPE = Sequence[Generation] | ||
|
||
|
@@ -22,3 +23,17 @@ def update(self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE) -> N | |
@abstractmethod | ||
def clear(self, **kwargs: Any) -> None: | ||
"""Clear cache that can take additional keyword arguments.""" | ||
|
||
async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative would be to add these methods to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dzmitry-kankalovich We generally prefer keeping async version of methods in the same class as the sync versions, and have them provide a default async implementation that uses Would you mind merging into existing abstractions? Ideally a single PR that just modifies the core interface first, and then separately we can do a PR for any implementations There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As for the smaller PRs - yes, I can move slower and split up into several PRs, if you are happy with current direction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally better to split PRs by package to minimize potential dependency conflicts since the packages may have different release schedules |
||
"""Look up based on prompt and llm_string.""" | ||
return await run_in_executor(None, self.lookup, prompt, llm_string) | ||
|
||
async def aupdate( | ||
self, prompt: str, llm_string: str, return_val: RETURN_VAL_TYPE | ||
) -> None: | ||
"""Update cache based on prompt and llm_string.""" | ||
return await run_in_executor(None, self.update, prompt, llm_string, return_val) | ||
|
||
async def aclear(self, **kwargs: Any) -> None: | ||
"""Clear cache that can take additional keyword arguments.""" | ||
return await run_in_executor(None, self.clear, **kwargs) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: shouldn't import this in langchain, imports here are only for backwards compatibility There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see. Noted! Maybe makes sense to drop a comment in that file next time you are working with it - future contributors will know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dzmitry-kankalovich I added a docker compose file under /docker we might move it at some point, but thinking about making it easier for developers to spin up services that integration tests depend on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah that would be super useful!