-
Notifications
You must be signed in to change notification settings - Fork 15.9k
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
Core refac #13627
Merged
Merged
Core refac #13627
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ce866eb
wip
baskaryan c3f6ca9
more
baskaryan 0b204f5
imports
baskaryan 3c45439
core tests
baskaryan 8ed35ea
more
baskaryan 8435e1b
wip
baskaryan 3503457
fmt
baskaryan a4098b6
test
baskaryan 7697ca9
undo
baskaryan 0fb7e3f
fix
baskaryan 6f5d94c
more
baskaryan de5b6d9
Merge branch 'master' into bagatur/core_refac
baskaryan d4f1e2f
bump 0.0.2
baskaryan 499e277
cr
baskaryan 8761d94
merge
baskaryan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
from langchain_core.callbacks.base import ( | ||
AsyncCallbackHandler, | ||
BaseCallbackHandler, | ||
BaseCallbackManager, | ||
CallbackManagerMixin, | ||
Callbacks, | ||
ChainManagerMixin, | ||
LLMManagerMixin, | ||
RetrieverManagerMixin, | ||
RunManagerMixin, | ||
ToolManagerMixin, | ||
) | ||
from langchain_core.callbacks.manager import ( | ||
AsyncCallbackManager, | ||
AsyncCallbackManagerForChainGroup, | ||
AsyncCallbackManagerForChainRun, | ||
AsyncCallbackManagerForLLMRun, | ||
AsyncCallbackManagerForRetrieverRun, | ||
AsyncCallbackManagerForToolRun, | ||
AsyncParentRunManager, | ||
AsyncRunManager, | ||
BaseRunManager, | ||
CallbackManager, | ||
CallbackManagerForChainGroup, | ||
CallbackManagerForChainRun, | ||
CallbackManagerForLLMRun, | ||
CallbackManagerForRetrieverRun, | ||
CallbackManagerForToolRun, | ||
ParentRunManager, | ||
RunManager, | ||
env_var_is_set, | ||
register_configure_hook, | ||
) | ||
from langchain_core.callbacks.stdout import StdOutCallbackHandler | ||
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler | ||
|
||
__all__ = [ | ||
"RetrieverManagerMixin", | ||
"LLMManagerMixin", | ||
"ChainManagerMixin", | ||
"ToolManagerMixin", | ||
"Callbacks", | ||
"CallbackManagerMixin", | ||
"RunManagerMixin", | ||
"BaseCallbackHandler", | ||
"AsyncCallbackHandler", | ||
"BaseCallbackManager", | ||
"BaseRunManager", | ||
"RunManager", | ||
"ParentRunManager", | ||
"AsyncRunManager", | ||
"AsyncParentRunManager", | ||
"CallbackManagerForLLMRun", | ||
"AsyncCallbackManagerForLLMRun", | ||
"CallbackManagerForChainRun", | ||
"AsyncCallbackManagerForChainRun", | ||
"CallbackManagerForToolRun", | ||
"AsyncCallbackManagerForToolRun", | ||
"CallbackManagerForRetrieverRun", | ||
"AsyncCallbackManagerForRetrieverRun", | ||
"CallbackManager", | ||
"CallbackManagerForChainGroup", | ||
"AsyncCallbackManager", | ||
"AsyncCallbackManagerForChainGroup", | ||
"StdOutCallbackHandler", | ||
"StreamingStdOutCallbackHandler", | ||
"env_var_is_set", | ||
"register_configure_hook", | ||
] |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,10 @@ | |
from langsmith.run_helpers import get_run_tree_context | ||
from tenacity import RetryCallState | ||
|
||
from langchain_core.agents import ( | ||
AgentAction, | ||
AgentFinish, | ||
) | ||
from langchain_core.callbacks.base import ( | ||
BaseCallbackHandler, | ||
BaseCallbackManager, | ||
|
@@ -41,23 +45,16 @@ | |
ToolManagerMixin, | ||
) | ||
from langchain_core.callbacks.stdout import StdOutCallbackHandler | ||
from langchain_core.callbacks.tracers import run_collector | ||
from langchain_core.callbacks.tracers.langchain import ( | ||
from langchain_core.documents import Document | ||
from langchain_core.messages import BaseMessage, get_buffer_string | ||
from langchain_core.outputs import ChatGenerationChunk, GenerationChunk, LLMResult | ||
from langchain_core.tracers import run_collector | ||
from langchain_core.tracers.langchain import ( | ||
LangChainTracer, | ||
) | ||
from langchain_core.callbacks.tracers.langchain_v1 import ( | ||
LangChainTracerV1, | ||
TracerSessionV1, | ||
) | ||
from langchain_core.callbacks.tracers.stdout import ConsoleCallbackHandler | ||
from langchain_core.schema import ( | ||
AgentAction, | ||
AgentFinish, | ||
Document, | ||
LLMResult, | ||
) | ||
from langchain_core.schema.messages import BaseMessage, get_buffer_string | ||
from langchain_core.schema.output import ChatGenerationChunk, GenerationChunk | ||
from langchain_core.tracers.langchain_v1 import LangChainTracerV1 | ||
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. leave some of the old tracer stuff in langchain? |
||
from langchain_core.tracers.schemas import TracerSessionV1 | ||
from langchain_core.tracers.stdout import ConsoleCallbackHandler | ||
|
||
if TYPE_CHECKING: | ||
from langsmith import Client as LangSmithClient | ||
|
This file contains 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
This file contains 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
This file contains 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
2 changes: 1 addition & 1 deletion
2
libs/core/langchain_core/schema/chat.py → libs/core/langchain_core/chat_sessions.py
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Literal | ||
|
||
from langchain_core.load.serializable import Serializable | ||
from langchain_core.pydantic_v1 import Field | ||
|
||
|
||
class Document(Serializable): | ||
"""Class for storing a piece of text and associated metadata.""" | ||
|
||
page_content: str | ||
"""String text.""" | ||
metadata: dict = Field(default_factory=dict) | ||
"""Arbitrary metadata about the page content (e.g., source, relationships to other | ||
documents, etc.). | ||
""" | ||
type: Literal["Document"] = "Document" | ||
|
||
@classmethod | ||
def is_lc_serializable(cls) -> bool: | ||
"""Return whether this class is serializable.""" | ||
return True |
File renamed without changes.
8 changes: 6 additions & 2 deletions
8
...core/prompts/example_selector/__init__.py → ...gchain_core/example_selectors/__init__.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
"""Logic for selecting examples to include in prompts.""" | ||
from langchain_core.prompts.example_selector.length_based import ( | ||
from langchain_core.example_selectors.base import BaseExampleSelector | ||
from langchain_core.example_selectors.length_based import ( | ||
LengthBasedExampleSelector, | ||
) | ||
from langchain_core.prompts.example_selector.semantic_similarity import ( | ||
from langchain_core.example_selectors.semantic_similarity import ( | ||
MaxMarginalRelevanceExampleSelector, | ||
SemanticSimilarityExampleSelector, | ||
sorted_values, | ||
) | ||
|
||
__all__ = [ | ||
"BaseExampleSelector", | ||
"LengthBasedExampleSelector", | ||
"MaxMarginalRelevanceExampleSelector", | ||
"SemanticSimilarityExampleSelector", | ||
"sorted_values", | ||
] |
File renamed without changes.
This file contains 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
This file contains 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
efriis marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from typing import Any, Optional | ||
|
||
|
||
class LangChainException(Exception): | ||
"""General LangChain exception.""" | ||
|
||
|
||
class TracerException(LangChainException): | ||
"""Base class for exceptions in tracers module.""" | ||
|
||
|
||
class OutputParserException(ValueError, LangChainException): | ||
"""Exception that output parsers should raise to signify a parsing error. | ||
|
||
This exists to differentiate parsing errors from other code or execution errors | ||
that also may arise inside the output parser. OutputParserExceptions will be | ||
available to catch and handle in ways to fix the parsing error, while other | ||
errors will be raised. | ||
|
||
Args: | ||
error: The error that's being re-raised or an error message. | ||
observation: String explanation of error which can be passed to a | ||
model to try and remediate the issue. | ||
llm_output: String model output which is error-ing. | ||
send_to_llm: Whether to send the observation and llm_output back to an Agent | ||
after an OutputParserException has been raised. This gives the underlying | ||
model driving the agent the context that the previous output was improperly | ||
structured, in the hopes that it will update the output to the correct | ||
format. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
error: Any, | ||
observation: Optional[str] = None, | ||
llm_output: Optional[str] = None, | ||
send_to_llm: bool = False, | ||
): | ||
super(OutputParserException, self).__init__(error) | ||
if send_to_llm: | ||
if observation is None or llm_output is None: | ||
raise ValueError( | ||
"Arguments 'observation' & 'llm_output'" | ||
" are required if 'send_to_llm' is True" | ||
) | ||
self.observation = observation | ||
self.llm_output = llm_output | ||
self.send_to_llm = send_to_llm |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from langchain_core.language_models.base import BaseLanguageModel, LanguageModelInput | ||
from langchain_core.language_models.chat_models import BaseChatModel, SimpleChatModel | ||
from langchain_core.language_models.llms import LLM, BaseLLM | ||
|
||
__all__ = [ | ||
"BaseLanguageModel", | ||
"BaseChatModel", | ||
"SimpleChatModel", | ||
"BaseLLM", | ||
"LLM", | ||
"LanguageModelInput", | ||
] |
This file contains 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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
any reason for the relative instead of absolute?
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.
was copying above, guessing linter complains about importing from private module?