-
Notifications
You must be signed in to change notification settings - Fork 18.9k
refactor(langchain): refactor optional imports logic in langchain_v1
#32813
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
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for GitHub. |
CodSpeed WallTime Performance ReportMerging #32813 will not alter performanceComparing
|
CodSpeed Instrumentation Performance ReportMerging #32813 will not alter performanceComparing Summary
|
langchain_v1
@@ -28,6 +28,47 @@ | |||
from pydantic import BaseModel | |||
|
|||
|
|||
_SUPPORTED_PROVIDERS = { | |||
"openai": ("langchain_openai", "ChatOpenAI"), |
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.
I think we don't want to load things on __init__
-- we want to have as fast of an import of langchain / langchain.chat_models as possible. Users would ideally only pay an import cost for the things they use
Refactor OK, but let's make it lazy and memoize appropriately?
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.
Ruff rule PLC0415 recommends to do the imports at the module loading.
I think the langchain_*
modules are quite fast to import, aren't they ?
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.
it's been a significant problem which is why we've swapped to lazy imports in many places. I think we saw import time grow to ~0.5 seconds, which is way too slow
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.
So we want as little of the code loaded up front, so that end of the day only the parts of the code that the user needs are loaded
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.
Ok. I can switch to a cached lazy load then.
Note that the big load time may come from one package alone. It would be interesting to identify it.
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.
done.
53357e0
to
0a6572c
Compare
0a6572c
to
21a3b8f
Compare
Uh oh!
There was an error while loading. Please reload this page.