Skip to content

Commit 56dde3a

Browse files
authored
feat(langchain): v1 scaffolding (#32166)
This PR adds scaffolding for langchain 1.0 entry package. Most contents have been removed. Currently remaining entrypoints for: * chat models * embedding models * memory -> trimming messages, filtering messages and counting tokens [we may remove this] * prompts -> we may remove some prompts * storage: primarily to support cache backed embeddings, may remove the kv store * tools -> report tool primitives Things to be added: * Selected agent implementations * Selected workflows * Common primitives: messages, Document * Primitives for type hinting: BaseChatModel, BaseEmbeddings * Selected retrievers * Selected text splitters Things to be removed: * Globals needs to be removed (needs an update in langchain core) Todos: * TBD indexing api (requires sqlalchemy which we don't want as a dependency) * Be explicit about public/private interfaces (e.g., likely rename chat_models.base.py to something more internal) * Remove dockerfiles * Update module doc-strings and README.md
1 parent bd3d649 commit 56dde3a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+8548
-0
lines changed

.github/scripts/check_diff.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"libs/core",
1717
"libs/text-splitters",
1818
"libs/langchain",
19+
"libs/langchain_v1",
1920
]
2021

2122
# when set to True, we are ignoring core dependents

libs/langchain_v1/.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.venv
2+
.github
3+
.git
4+
.mypy_cache
5+
.pytest_cache
6+
Dockerfile

libs/langchain_v1/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) LangChain, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

libs/langchain_v1/Makefile

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
.PHONY: all clean docs_build docs_clean docs_linkcheck api_docs_build api_docs_clean api_docs_linkcheck format lint test tests test_watch integration_tests docker_tests help extended_tests
2+
3+
# Default target executed when no arguments are given to make.
4+
all: help
5+
6+
######################
7+
# TESTING AND COVERAGE
8+
######################
9+
10+
# Define a variable for the test file path.
11+
TEST_FILE ?= tests/unit_tests/
12+
13+
.EXPORT_ALL_VARIABLES:
14+
UV_FROZEN = true
15+
16+
# Run unit tests and generate a coverage report.
17+
coverage:
18+
uv run --group test pytest --cov \
19+
--cov-config=.coveragerc \
20+
--cov-report xml \
21+
--cov-report term-missing:skip-covered \
22+
$(TEST_FILE)
23+
24+
test tests:
25+
uv run --group test pytest -n auto --disable-socket --allow-unix-socket $(TEST_FILE)
26+
27+
extended_tests:
28+
uv run --group test pytest --disable-socket --allow-unix-socket --only-extended tests/unit_tests
29+
30+
test_watch:
31+
uv run --group test ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket --disable-warnings tests/unit_tests
32+
33+
test_watch_extended:
34+
uv run --group test ptw --snapshot-update --now . -- -x --disable-socket --allow-unix-socket --only-extended tests/unit_tests
35+
36+
integration_tests:
37+
uv run --group test --group test_integration pytest tests/integration_tests
38+
39+
docker_tests:
40+
docker build -t my-langchain-image:test .
41+
docker run --rm my-langchain-image:test
42+
43+
check_imports: $(shell find langchain -name '*.py')
44+
uv run python ./scripts/check_imports.py $^
45+
46+
######################
47+
# LINTING AND FORMATTING
48+
######################
49+
50+
# Define a variable for Python and notebook files.
51+
PYTHON_FILES=.
52+
MYPY_CACHE=.mypy_cache
53+
lint format: PYTHON_FILES=.
54+
lint_diff format_diff: PYTHON_FILES=$(shell git diff --relative=libs/langchain --name-only --diff-filter=d master | grep -E '\.py$$|\.ipynb$$')
55+
lint_package: PYTHON_FILES=langchain
56+
lint_tests: PYTHON_FILES=tests
57+
lint_tests: MYPY_CACHE=.mypy_cache_test
58+
59+
lint lint_diff lint_package lint_tests:
60+
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check $(PYTHON_FILES)
61+
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES) --diff
62+
[ "$(PYTHON_FILES)" = "" ] || mkdir -p $(MYPY_CACHE) && uv run --all-groups mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)
63+
64+
format format_diff:
65+
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff format $(PYTHON_FILES)
66+
[ "$(PYTHON_FILES)" = "" ] || uv run --all-groups ruff check --fix $(PYTHON_FILES)
67+
68+
spell_check:
69+
uv run --all-groups codespell --toml pyproject.toml
70+
71+
spell_fix:
72+
uv run --all-groups codespell --toml pyproject.toml -w
73+
74+
######################
75+
# HELP
76+
######################
77+
78+
help:
79+
@echo '===================='
80+
@echo 'clean - run docs_clean and api_docs_clean'
81+
@echo 'docs_build - build the documentation'
82+
@echo 'docs_clean - clean the documentation build artifacts'
83+
@echo 'docs_linkcheck - run linkchecker on the documentation'
84+
@echo 'api_docs_build - build the API Reference documentation'
85+
@echo 'api_docs_clean - clean the API Reference documentation build artifacts'
86+
@echo 'api_docs_linkcheck - run linkchecker on the API Reference documentation'
87+
@echo '-- LINTING --'
88+
@echo 'format - run code formatters'
89+
@echo 'lint - run linters'
90+
@echo 'spell_check - run codespell on the project'
91+
@echo 'spell_fix - run codespell on the project and fix the errors'
92+
@echo '-- TESTS --'
93+
@echo 'coverage - run unit tests and generate coverage report'
94+
@echo 'test - run unit tests'
95+
@echo 'tests - run unit tests (alias for "make test")'
96+
@echo 'test TEST_FILE=<test_file> - run all tests in file'
97+
@echo 'extended_tests - run only extended unit tests'
98+
@echo 'test_watch - run unit tests in watch mode'
99+
@echo 'integration_tests - run integration tests'
100+
@echo 'docker_tests - run unit tests in docker'
101+
@echo '-- DOCUMENTATION tasks are from the top-level Makefile --'

libs/langchain_v1/README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# 🦜️🔗 LangChain
2+
3+
⚡ Building applications with LLMs through composability ⚡
4+
5+
[![Release Notes](https://img.shields.io/github/release/langchain-ai/langchain)](https://github.com/langchain-ai/langchain/releases)
6+
[![lint](https://github.com/langchain-ai/langchain/actions/workflows/lint.yml/badge.svg)](https://github.com/langchain-ai/langchain/actions/workflows/lint.yml)
7+
[![test](https://github.com/langchain-ai/langchain/actions/workflows/test.yml/badge.svg)](https://github.com/langchain-ai/langchain/actions/workflows/test.yml)
8+
[![Downloads](https://static.pepy.tech/badge/langchain/month)](https://pepy.tech/project/langchain)
9+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10+
[![Twitter](https://img.shields.io/twitter/url/https/twitter.com/langchainai.svg?style=social&label=Follow%20%40LangChainAI)](https://twitter.com/langchainai)
11+
[![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://github.com/langchain-ai/langchain)
12+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/langchain-ai/langchain)
13+
[![GitHub star chart](https://img.shields.io/github/stars/langchain-ai/langchain?style=social)](https://star-history.com/#langchain-ai/langchain)
14+
[![Dependency Status](https://img.shields.io/librariesio/github/langchain-ai/langchain)](https://libraries.io/github/langchain-ai/langchain)
15+
[![Open Issues](https://img.shields.io/github/issues-raw/langchain-ai/langchain)](https://github.com/langchain-ai/langchain/issues)
16+
17+
18+
Looking for the JS/TS version? Check out [LangChain.js](https://github.com/langchain-ai/langchainjs).
19+
20+
To help you ship LangChain apps to production faster, check out [LangSmith](https://smith.langchain.com).
21+
[LangSmith](https://smith.langchain.com) is a unified developer platform for building, testing, and monitoring LLM applications.
22+
Fill out [this form](https://www.langchain.com/contact-sales) to speak with our sales team.
23+
24+
## Quick Install
25+
26+
`pip install langchain`
27+
or
28+
`pip install langsmith && conda install langchain -c conda-forge`
29+
30+
## 🤔 What is this?
31+
32+
Large language models (LLMs) are emerging as a transformative technology, enabling developers to build applications that they previously could not. However, using these LLMs in isolation is often insufficient for creating a truly powerful app - the real power comes when you can combine them with other sources of computation or knowledge.
33+
34+
This library aims to assist in the development of those types of applications. Common examples of these applications include:
35+
36+
**❓ Question answering with RAG**
37+
38+
- [Documentation](https://python.langchain.com/docs/use_cases/question_answering/)
39+
- End-to-end Example: [Chat LangChain](https://chat.langchain.com) and [repo](https://github.com/langchain-ai/chat-langchain)
40+
41+
**🧱 Extracting structured output**
42+
43+
- [Documentation](https://python.langchain.com/docs/use_cases/extraction/)
44+
- End-to-end Example: [SQL Llama2 Template](https://github.com/langchain-ai/langchain-extract/)
45+
46+
**🤖 Chatbots**
47+
48+
- [Documentation](https://python.langchain.com/docs/use_cases/chatbots)
49+
- End-to-end Example: [Web LangChain (web researcher chatbot)](https://weblangchain.vercel.app) and [repo](https://github.com/langchain-ai/weblangchain)
50+
51+
## 📖 Documentation
52+
53+
Please see [here](https://python.langchain.com) for full documentation on:
54+
55+
- Getting started (installation, setting up the environment, simple examples)
56+
- How-To examples (demos, integrations, helper functions)
57+
- Reference (full API docs)
58+
- Resources (high-level explanation of core concepts)
59+
60+
## 🚀 What can this help with?
61+
62+
There are five main areas that LangChain is designed to help with.
63+
These are, in increasing order of complexity:
64+
65+
**📃 Models and Prompts:**
66+
67+
This includes prompt management, prompt optimization, a generic interface for all LLMs, and common utilities for working with chat models and LLMs.
68+
69+
**🔗 Chains:**
70+
71+
Chains go beyond a single LLM call and involve sequences of calls (whether to an LLM or a different utility). LangChain provides a standard interface for chains, lots of integrations with other tools, and end-to-end chains for common applications.
72+
73+
**📚 Retrieval Augmented Generation:**
74+
75+
Retrieval Augmented Generation involves specific types of chains that first interact with an external data source to fetch data for use in the generation step. Examples include summarization of long pieces of text and question/answering over specific data sources.
76+
77+
**🤖 Agents:**
78+
79+
Agents involve an LLM making decisions about which Actions to take, taking that Action, seeing an Observation, and repeating that until done. LangChain provides a standard interface for agents, a selection of agents to choose from, and examples of end-to-end agents.
80+
81+
**🧐 Evaluation:**
82+
83+
[BETA] Generative models are notoriously hard to evaluate with traditional metrics. One new way of evaluating them is using language models themselves to do the evaluation. LangChain provides some prompts/chains for assisting in this.
84+
85+
For more information on these concepts, please see our [full documentation](https://python.langchain.com).
86+
87+
## 💁 Contributing
88+
89+
As an open-source project in a rapidly developing field, we are extremely open to contributions, whether it be in the form of a new feature, improved infrastructure, or better documentation.
90+
91+
For detailed information on how to contribute, see the [Contributing Guide](https://python.langchain.com/docs/contributing/).
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-e ../partners/openai
2+
-e ../partners/anthropic
3+
-e ../partners/fireworks
4+
-e ../partners/mistralai
5+
-e ../partners/groq
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""Main entrypoint into package."""
2+
3+
from importlib import metadata
4+
from typing import Any
5+
6+
try:
7+
__version__ = metadata.version(__package__)
8+
except metadata.PackageNotFoundError:
9+
# Case where package metadata is not available.
10+
__version__ = ""
11+
del metadata # optional, avoids polluting the results of dir(__package__)
12+
13+
14+
def __getattr__(name: str) -> Any: # noqa: ANN401
15+
"""Get an attribute from the package."""
16+
if name == "verbose":
17+
from langchain.globals import _verbose
18+
19+
return _verbose
20+
if name == "debug":
21+
from langchain.globals import _debug
22+
23+
return _debug
24+
if name == "llm_cache":
25+
from langchain.globals import _llm_cache
26+
27+
return _llm_cache
28+
msg = f"Could not find: {name}"
29+
raise AttributeError(msg)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""**Chat Models** are a variation on language models.
2+
3+
While Chat Models use language models under the hood, the interface they expose
4+
is a bit different. Rather than expose a "text in, text out" API, they expose
5+
an interface where "chat messages" are the inputs and outputs.
6+
7+
**Class hierarchy:**
8+
9+
.. code-block::
10+
11+
BaseLanguageModel --> BaseChatModel --> <name> # Examples: ChatOpenAI, ChatGooglePalm
12+
13+
**Main helpers:**
14+
15+
.. code-block::
16+
17+
AIMessage, BaseMessage, HumanMessage
18+
""" # noqa: E501
19+
20+
from langchain.chat_models.base import init_chat_model
21+
22+
__all__ = [
23+
"init_chat_model",
24+
]

0 commit comments

Comments
 (0)