Skip to content

Commit ed58eeb

Browse files
authored
community[major], core[patch], langchain[patch], experimental[patch]: Create langchain-community (langchain-ai#14463)
Moved the following modules to new package langchain-community in a backwards compatible fashion: ``` mv langchain/langchain/adapters community/langchain_community mv langchain/langchain/callbacks community/langchain_community/callbacks mv langchain/langchain/chat_loaders community/langchain_community mv langchain/langchain/chat_models community/langchain_community mv langchain/langchain/document_loaders community/langchain_community mv langchain/langchain/docstore community/langchain_community mv langchain/langchain/document_transformers community/langchain_community mv langchain/langchain/embeddings community/langchain_community mv langchain/langchain/graphs community/langchain_community mv langchain/langchain/llms community/langchain_community mv langchain/langchain/memory/chat_message_histories community/langchain_community mv langchain/langchain/retrievers community/langchain_community mv langchain/langchain/storage community/langchain_community mv langchain/langchain/tools community/langchain_community mv langchain/langchain/utilities community/langchain_community mv langchain/langchain/vectorstores community/langchain_community mv langchain/langchain/agents/agent_toolkits community/langchain_community mv langchain/langchain/cache.py community/langchain_community mv langchain/langchain/adapters community/langchain_community mv langchain/langchain/callbacks community/langchain_community/callbacks mv langchain/langchain/chat_loaders community/langchain_community mv langchain/langchain/chat_models community/langchain_community mv langchain/langchain/document_loaders community/langchain_community mv langchain/langchain/docstore community/langchain_community mv langchain/langchain/document_transformers community/langchain_community mv langchain/langchain/embeddings community/langchain_community mv langchain/langchain/graphs community/langchain_community mv langchain/langchain/llms community/langchain_community mv langchain/langchain/memory/chat_message_histories community/langchain_community mv langchain/langchain/retrievers community/langchain_community mv langchain/langchain/storage community/langchain_community mv langchain/langchain/tools community/langchain_community mv langchain/langchain/utilities community/langchain_community mv langchain/langchain/vectorstores community/langchain_community mv langchain/langchain/agents/agent_toolkits community/langchain_community mv langchain/langchain/cache.py community/langchain_community ``` Moved the following to core ``` mv langchain/langchain/utils/json_schema.py core/langchain_core/utils mv langchain/langchain/utils/html.py core/langchain_core/utils mv langchain/langchain/utils/strings.py core/langchain_core/utils cat langchain/langchain/utils/env.py >> core/langchain_core/utils/env.py rm langchain/langchain/utils/env.py ``` See .scripts/community_split/script_integrations.sh for all changes
1 parent c0f4b95 commit ed58eeb

File tree

2,616 files changed

+187004
-152317
lines changed

Some content is hidden

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

2,616 files changed

+187004
-152317
lines changed

.github/CONTRIBUTING.md

+47-11
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ Install Poetry: **[documentation on how to install it](https://python-poetry.org
7070
❗Note: If you use `Conda` or `Pyenv` as your environment/package manager, after installing Poetry,
7171
tell Poetry to use the virtualenv python environment (`poetry config virtualenvs.prefer-active-python true`)
7272

73-
### Core vs. Experimental
73+
### Different packages
7474

75-
This repository contains three separate projects:
76-
- `langchain`: core langchain code, abstractions, and use cases.
77-
- `langchain_core`: contain interfaces for key abstractions as well as logic for combining them in chains (LCEL).
78-
- `langchain_experimental`: see the [Experimental README](https://github.com/langchain-ai/langchain/tree/master/libs/experimental/README.md) for more information.
75+
This repository contains multiple packages:
76+
- `langchain-core`: Base interfaces for key abstractions as well as logic for combining them in chains (LangChain Expression Language).
77+
- `langchain-community`: Third-party integrations of various components.
78+
- `langchain`: Chains, agents, and retrieval logic that makes up the cognitive architecture of your applications.
79+
- `langchain-experimental`: Components and chains that are experimental, either in the sense that the techniques are novel and still being tested, or they require giving the LLM more access than would be possible in most production systems.
7980

8081
Each of these has its own development environment. Docs are run from the top-level makefile, but development
8182
is split across separate test & release flows.
8283

83-
For this quickstart, start with langchain core:
84+
For this quickstart, start with langchain:
8485

8586
```bash
8687
cd libs/langchain
@@ -330,15 +331,50 @@ what you wanted by clicking the `View deployment` or `Visit Preview` buttons on
330331
This will take you to a preview of the documentation changes.
331332
This preview is created by [Vercel](https://vercel.com/docs/getting-started-with-vercel).
332333

333-
## 🏭 Release Process
334+
## 📕 Releases & Versioning
334335

335336
As of now, LangChain has an ad hoc release process: releases are cut with high frequency by
336-
a developer and published to [PyPI](https://pypi.org/project/langchain/).
337+
a maintainer and published to [PyPI](https://pypi.org/).
338+
The different packages are versioned slightly differently.
337339

338-
LangChain follows the [semver](https://semver.org/) versioning standard. However, as pre-1.0 software,
339-
even patch releases may contain [non-backwards-compatible changes](https://semver.org/#spec-item-4).
340+
### `langchain-core`
340341

341-
### 🌟 Recognition
342+
`langchain-core` is currently on version `0.1.x`.
343+
344+
As `langchain-core` contains the base abstractions and runtime for the whole LangChain ecosystem, we will communicate any breaking changes with advance notice and version bumps. The exception for this is anything in `langchain_core.beta`. The reason for `langchain_core.beta` is that given the rate of change of the field, being able to move quickly is still a priority, and this module is our attempt to do so.
345+
346+
Minor version increases will occur for:
347+
348+
- Breaking changes for any public interfaces NOT in `langchain_core.beta`
349+
350+
Patch version increases will occur for:
351+
352+
- Bug fixes
353+
- New features
354+
- Any changes to private interfaces
355+
- Any changes to `langchain_core.beta`
356+
357+
### `langchain`
358+
359+
`langchain` is currently on version `0.0.x`
360+
361+
All changes will be accompanied by a patch version increase. Any changes to public interfaces are nearly always done in a backwards compatible way and will be communicated ahead of time when they are not backwards compatible.
362+
363+
We are targeting January 2024 for a release of `langchain` v0.1, at which point `langchain` will adopt the same versioning policy as `langchain-core`.
364+
365+
### `langchain-community`
366+
367+
`langchain-community` is currently on version `0.0.x`
368+
369+
All changes will be accompanied by a patch version increase.
370+
371+
### `langchain-experimental`
372+
373+
`langchain-experimental` is currently on version `0.0.x`
374+
375+
All changes will be accompanied by a patch version increase.
376+
377+
## 🌟 Recognition
342378

343379
If your contribution has made its way into a release, we will want to give you credit on Twitter (only if you want though)!
344380
If you have a Twitter account you would like us to mention, please let us know in the PR or through another means.

.github/scripts/check_diff.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"libs/core",
66
"libs/langchain",
77
"libs/experimental",
8+
"libs/community",
89
}
910

1011
if __name__ == "__main__":

.github/workflows/_all_ci.yml

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on:
1818
- libs/langchain
1919
- libs/core
2020
- libs/experimental
21+
- libs/community
2122

2223

2324
# If another push to the same PR or branch happens while this workflow is still running,

.github/workflows/_lint.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ jobs:
8585
with:
8686
path: |
8787
${{ env.WORKDIR }}/.mypy_cache
88-
key: mypy-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', env.WORKDIR)) }}
88+
key: mypy-lint-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', env.WORKDIR)) }}
89+
8990

9091
- name: Analysing the code with our lint
9192
working-directory: ${{ inputs.working-directory }}
@@ -105,13 +106,13 @@ jobs:
105106
run: |
106107
poetry install --with test
107108
108-
- name: Get .mypy_cache to speed up mypy
109+
- name: Get .mypy_cache_test to speed up mypy
109110
uses: actions/cache@v3
110111
env:
111112
SEGMENT_DOWNLOAD_TIMEOUT_MIN: "2"
112113
with:
113114
path: |
114-
${{ env.WORKDIR }}/.mypy_cache
115+
${{ env.WORKDIR }}/.mypy_cache_test
115116
key: mypy-test-${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}-${{ inputs.working-directory }}-${{ hashFiles(format('{0}/poetry.lock', env.WORKDIR)) }}
116117

117118
- name: Analysing the code with our lint

.github/workflows/_release.yml

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,25 @@ on:
77
required: true
88
type: string
99
description: "From which folder this pipeline executes"
10+
workflow_dispatch:
11+
inputs:
12+
working-directory:
13+
required: true
14+
type: choice
15+
default: 'libs/langchain'
16+
options:
17+
- libs/langchain
18+
- libs/core
19+
- libs/experimental
20+
- libs/community
1021

1122
env:
1223
PYTHON_VERSION: "3.10"
1324
POETRY_VERSION: "1.6.1"
1425

1526
jobs:
1627
build:
17-
if: github.ref == 'refs/heads/master'
28+
# if: github.ref == 'refs/heads/master'
1829
runs-on: ubuntu-latest
1930

2031
outputs:

.github/workflows/_test_release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ env:
1414

1515
jobs:
1616
build:
17-
if: github.ref == 'refs/heads/master'
17+
# if: github.ref == 'refs/heads/master'
1818
runs-on: ubuntu-latest
1919

2020
outputs:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
name: libs/core Release
3+
4+
on:
5+
workflow_dispatch: # Allows to trigger the workflow manually in GitHub UI
6+
7+
jobs:
8+
release:
9+
uses:
10+
./.github/workflows/_release.yml
11+
with:
12+
working-directory: libs/core
13+
secrets: inherit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""Main entrypoint into package."""
2+
from importlib import metadata
3+
4+
try:
5+
__version__ = metadata.version(__package__)
6+
except metadata.PackageNotFoundError:
7+
# Case where package metadata is not available.
8+
__version__ = ""
9+
del metadata # optional, avoids polluting the results of dir(__package__)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
"""Agent toolkits contain integrations with various resources and services.
2+
3+
LangChain has a large ecosystem of integrations with various external resources
4+
like local and remote file systems, APIs and databases.
5+
6+
These integrations allow developers to create versatile applications that combine the
7+
power of LLMs with the ability to access, interact with and manipulate external
8+
resources.
9+
10+
When developing an application, developers should inspect the capabilities and
11+
permissions of the tools that underlie the given agent toolkit, and determine
12+
whether permissions of the given toolkit are appropriate for the application.
13+
14+
See [Security](https://python.langchain.com/docs/security) for more information.
15+
"""
16+
from langchain_community.agent_toolkits.ainetwork.toolkit import AINetworkToolkit
17+
from langchain_community.agent_toolkits.amadeus.toolkit import AmadeusToolkit
18+
from langchain_community.agent_toolkits.azure_cognitive_services import (
19+
AzureCognitiveServicesToolkit,
20+
)
21+
from langchain_community.agent_toolkits.conversational_retrieval.openai_functions import ( # noqa: E501
22+
create_conversational_retrieval_agent,
23+
)
24+
from langchain_community.agent_toolkits.file_management.toolkit import (
25+
FileManagementToolkit,
26+
)
27+
from langchain_community.agent_toolkits.gmail.toolkit import GmailToolkit
28+
from langchain_community.agent_toolkits.jira.toolkit import JiraToolkit
29+
from langchain_community.agent_toolkits.json.base import create_json_agent
30+
from langchain_community.agent_toolkits.json.toolkit import JsonToolkit
31+
from langchain_community.agent_toolkits.multion.toolkit import MultionToolkit
32+
from langchain_community.agent_toolkits.nasa.toolkit import NasaToolkit
33+
from langchain_community.agent_toolkits.nla.toolkit import NLAToolkit
34+
from langchain_community.agent_toolkits.office365.toolkit import O365Toolkit
35+
from langchain_community.agent_toolkits.openapi.base import create_openapi_agent
36+
from langchain_community.agent_toolkits.openapi.toolkit import OpenAPIToolkit
37+
from langchain_community.agent_toolkits.playwright.toolkit import (
38+
PlayWrightBrowserToolkit,
39+
)
40+
from langchain_community.agent_toolkits.powerbi.base import create_pbi_agent
41+
from langchain_community.agent_toolkits.powerbi.chat_base import create_pbi_chat_agent
42+
from langchain_community.agent_toolkits.powerbi.toolkit import PowerBIToolkit
43+
from langchain_community.agent_toolkits.slack.toolkit import SlackToolkit
44+
from langchain_community.agent_toolkits.spark_sql.base import create_spark_sql_agent
45+
from langchain_community.agent_toolkits.spark_sql.toolkit import SparkSQLToolkit
46+
from langchain_community.agent_toolkits.sql.base import create_sql_agent
47+
from langchain_community.agent_toolkits.sql.toolkit import SQLDatabaseToolkit
48+
from langchain_community.agent_toolkits.steam.toolkit import SteamToolkit
49+
from langchain_community.agent_toolkits.zapier.toolkit import ZapierToolkit
50+
51+
52+
__all__ = [
53+
"AINetworkToolkit",
54+
"AmadeusToolkit",
55+
"AzureCognitiveServicesToolkit",
56+
"FileManagementToolkit",
57+
"GmailToolkit",
58+
"JiraToolkit",
59+
"JsonToolkit",
60+
"MultionToolkit",
61+
"NasaToolkit",
62+
"NLAToolkit",
63+
"O365Toolkit",
64+
"OpenAPIToolkit",
65+
"PlayWrightBrowserToolkit",
66+
"PowerBIToolkit",
67+
"SlackToolkit",
68+
"SteamToolkit",
69+
"SQLDatabaseToolkit",
70+
"SparkSQLToolkit",
71+
"ZapierToolkit",
72+
"create_json_agent",
73+
"create_openapi_agent",
74+
"create_pbi_agent",
75+
"create_pbi_chat_agent",
76+
"create_spark_sql_agent",
77+
"create_sql_agent",
78+
"create_conversational_retrieval_agent",
79+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from __future__ import annotations
2+
3+
from typing import Any, List, Optional, TYPE_CHECKING
4+
5+
from langchain_core.language_models import BaseLanguageModel
6+
from langchain_core.memory import BaseMemory
7+
from langchain_core.messages import SystemMessage
8+
from langchain_core.prompts.chat import MessagesPlaceholder
9+
from langchain_core.tools import BaseTool
10+
11+
if TYPE_CHECKING:
12+
from langchain.agents.agent import AgentExecutor
13+
14+
15+
def _get_default_system_message() -> SystemMessage:
16+
return SystemMessage(
17+
content=(
18+
"Do your best to answer the questions. "
19+
"Feel free to use any tools available to look up "
20+
"relevant information, only if necessary"
21+
)
22+
)
23+
24+
def create_conversational_retrieval_agent(
25+
llm: BaseLanguageModel,
26+
tools: List[BaseTool],
27+
remember_intermediate_steps: bool = True,
28+
memory_key: str = "chat_history",
29+
system_message: Optional[SystemMessage] = None,
30+
verbose: bool = False,
31+
max_token_limit: int = 2000,
32+
**kwargs: Any,
33+
) -> AgentExecutor:
34+
"""A convenience method for creating a conversational retrieval agent.
35+
36+
Args:
37+
llm: The language model to use, should be ChatOpenAI
38+
tools: A list of tools the agent has access to
39+
remember_intermediate_steps: Whether the agent should remember intermediate
40+
steps or not. Intermediate steps refer to prior action/observation
41+
pairs from previous questions. The benefit of remembering these is if
42+
there is relevant information in there, the agent can use it to answer
43+
follow up questions. The downside is it will take up more tokens.
44+
memory_key: The name of the memory key in the prompt.
45+
system_message: The system message to use. By default, a basic one will
46+
be used.
47+
verbose: Whether or not the final AgentExecutor should be verbose or not,
48+
defaults to False.
49+
max_token_limit: The max number of tokens to keep around in memory.
50+
Defaults to 2000.
51+
52+
Returns:
53+
An agent executor initialized appropriately
54+
"""
55+
from langchain.agents.agent import AgentExecutor
56+
from langchain.agents.openai_functions_agent.agent_token_buffer_memory import (
57+
AgentTokenBufferMemory,
58+
)
59+
from langchain.agents.openai_functions_agent.base import OpenAIFunctionsAgent
60+
from langchain.memory.token_buffer import ConversationTokenBufferMemory
61+
62+
if remember_intermediate_steps:
63+
memory: BaseMemory = AgentTokenBufferMemory(
64+
memory_key=memory_key, llm=llm, max_token_limit=max_token_limit
65+
)
66+
else:
67+
memory = ConversationTokenBufferMemory(
68+
memory_key=memory_key,
69+
return_messages=True,
70+
output_key="output",
71+
llm=llm,
72+
max_token_limit=max_token_limit,
73+
)
74+
75+
_system_message = system_message or _get_default_system_message()
76+
prompt = OpenAIFunctionsAgent.create_prompt(
77+
system_message=_system_message,
78+
extra_prompt_messages=[MessagesPlaceholder(variable_name=memory_key)],
79+
)
80+
agent = OpenAIFunctionsAgent(llm=llm, tools=tools, prompt=prompt)
81+
return AgentExecutor(
82+
agent=agent,
83+
tools=tools,
84+
memory=memory,
85+
verbose=verbose,
86+
return_intermediate_steps=remember_intermediate_steps,
87+
**kwargs,
88+
)

0 commit comments

Comments
 (0)