The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
cli[patch]: integration template nits (#14691)
Bagatur10c10f2deadd
diff --git a/libs/cli/langchain_cli/integration_template/Makefile b/libs/cli/langchain_cli/integration_template/Makefileindex bed6f5bda5..2837e81a66 100644--- a/libs/cli/langchain_cli/integration_template/Makefile+++ b/libs/cli/langchain_cli/integration_template/Makefile@@ -5,16 +5,11 @@ all: help# Define a variable for the test file path.TEST_FILE ?= tests/unit_tests/+integration_test integration_tests: TEST_FILE = tests/integration_tests/-integration_tests: TEST_FILE = tests/integration_tests/--test integration_tests:- poetry run pytest $(TEST_FILE)--tests:+test tests integration_test integration_tests:poetry run pytest $(TEST_FILE)-####################### LINTING AND FORMATTING######################@@ -32,7 +27,7 @@ lint lint_diff lint_package lint_tests:poetry run ruff .poetry run ruff format $(PYTHON_FILES) --diffpoetry run ruff --select I $(PYTHON_FILES)- mkdir $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)+ mkdir -p $(MYPY_CACHE); poetry run mypy $(PYTHON_FILES) --cache-dir $(MYPY_CACHE)format format_diff:poetry run ruff format $(PYTHON_FILES)diff --git a/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py b/libs/cli/langchain_cli/integration_template/integration_template/chat_models.pyindex 3f60c9e6a7..df19152454 100644--- a/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py+++ b/libs/cli/langchain_cli/integration_template/integration_template/chat_models.py@@ -1,3 +1,4 @@+"""__ModuleName__ chat models."""from typing import Any, AsyncIterator, Iterator, List, Optionalfrom langchain_core.callbacks import (@@ -5,7 +6,7 @@ from langchain_core.callbacks import (CallbackManagerForLLMRun,)from langchain_core.language_models.chat_models import BaseChatModel-from langchain_core.messages import BaseMessage, BaseMessageChunk+from langchain_core.messages import BaseMessagefrom langchain_core.outputs import ChatGenerationChunk, ChatResult@@ -15,49 +16,51 @@ class Chat__ModuleName__(BaseChatModel):Example:.. code-block:: python- from __module_name__ import Chat__ModuleName__+ from langchain_core.messages import HumanMessage+ from __module_name__ import Chat__ModuleName__model = Chat__ModuleName__()- """+ model.invoke([HumanMessage(content="Come up with 10 names for a song about parrots.")])+ """ # noqa: E501@propertydef _llm_type(self) -> str:"""Return type of chat model."""return "chat-__package_name_short__"- def _stream(+ def _generate(self,messages: List[BaseMessage],stop: Optional[List[str]] = None,run_manager: Optional[CallbackManagerForLLMRun] = None,**kwargs: Any,- ) -> Iterator[ChatGenerationChunk]:+ ) -> ChatResult:raise NotImplementedError- async def _astream(+ # TODO: Implement if __model_name__ supports streaming. Otherwise delete method.+ def _stream(self,messages: List[BaseMessage],stop: Optional[List[str]] = None,- run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,+ run_manager: Optional[CallbackManagerForLLMRun] = None,**kwargs: Any,- ) -> AsyncIterator[ChatGenerationChunk]:- yield ChatGenerationChunk(- message=BaseMessageChunk(content="Yield chunks", type="ai"),- )- yield ChatGenerationChunk(- message=BaseMessageChunk(content=" like this!", type="ai"),- )+ ) -> Iterator[ChatGenerationChunk]:+ raise NotImplementedError- def _generate(+ # TODO: Implement if __model_name__ supports async streaming. Otherwise delete+ # method.+ async def _astream(self,messages: List[BaseMessage],stop: Optional[List[str]] = None,- run_manager: Optional[CallbackManagerForLLMRun] = None,+ run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,**kwargs: Any,- ) -> ChatResult:+ ) -> AsyncIterator[ChatGenerationChunk]:raise NotImplementedError+ # TODO: Implement if __model_name__ supports async generation. Otherwise delete+ # method.async def _agenerate(self,messages: List[BaseMessage],diff --git a/libs/cli/langchain_cli/integration_template/integration_template/llms.py b/libs/cli/langchain_cli/integration_template/integration_template/llms.pyindex bd8c2fc37f..562fc0f400 100644--- a/libs/cli/langchain_cli/integration_template/integration_template/llms.py+++ b/libs/cli/langchain_cli/integration_template/integration_template/llms.py@@ -1,5 +1,4 @@-import asyncio-from functools import partial+"""__ModuleName__ large language models."""from typing import (Any,AsyncIterator,@@ -25,6 +24,7 @@ class __ModuleName__LLM(BaseLLM):from __module_name__ import __ModuleName__LLMmodel = __ModuleName__LLM()+ model.invoke("Come up with 10 names for a song about parrots")"""@property@@ -41,6 +41,8 @@ class __ModuleName__LLM(BaseLLM):) -> LLMResult:raise NotImplementedError+ # TODO: Implement if __model_name__ supports async generation. Otherwise+ # delete method.async def _agenerate(self,prompts: List[str],@@ -48,11 +50,9 @@ class __ModuleName__LLM(BaseLLM):run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,**kwargs: Any,) -> LLMResult:- # Change implementation if integration natively supports async generation.- return await asyncio.get_running_loop().run_in_executor(- None, partial(self._generate, **kwargs), prompts, stop, run_manager- )+ raise NotImplementedError+ # TODO: Implement if __model_name__ supports streaming. Otherwise delete method.def _stream(self,prompt: str,@@ -62,6 +62,8 @@ class __ModuleName__LLM(BaseLLM):) -> Iterator[GenerationChunk]:raise NotImplementedError+ # TODO: Implement if __model_name__ supports async streaming. Otherwise delete+ # method.async def _astream(self,prompt: str,@@ -69,5 +71,4 @@ class __ModuleName__LLM(BaseLLM):run_manager: Optional[AsyncCallbackManagerForLLMRun] = None,**kwargs: Any,) -> AsyncIterator[GenerationChunk]:- yield GenerationChunk(text="Yield chunks")- yield GenerationChunk(text=" like this!")+ raise NotImplementedErrordiff --git a/libs/cli/langchain_cli/integration_template/integration_template/vectorstores.py b/libs/cli/langchain_cli/integration_template/integration_template/vectorstores.pyindex 10c22f22b2..3683d53c4a 100644--- a/libs/cli/langchain_cli/integration_template/integration_template/vectorstores.py+++ b/libs/cli/langchain_cli/integration_template/integration_template/vectorstores.py@@ -1,3 +1,4 @@+"""__ModuleName__ vector stores."""from __future__ import annotationsimport asyncio@@ -24,7 +25,7 @@ VST = TypeVar("VST", bound=VectorStore)class __ModuleName__VectorStore(VectorStore):- """Interface for vector store.+ """__ModuleName__ vector store.Example:.. code-block:: pythondiff --git a/libs/cli/langchain_cli/integration_template/pyproject.toml b/libs/cli/langchain_cli/integration_template/pyproject.tomlindex be76900001..08a778b2fc 100644--- a/libs/cli/langchain_cli/integration_template/pyproject.toml+++ b/libs/cli/langchain_cli/integration_template/pyproject.toml@@ -12,25 +12,21 @@ license = "MIT"[tool.poetry.dependencies]python = ">=3.8.1,<4.0"-langchain-core = ">=0.0.12"+langchain-core = "^0.1"[tool.poetry.group.test]optional = true[tool.poetry.group.test.dependencies]-pytest = "^7.3.0"-freezegun = "^1.2.2"-pytest-mock = "^3.10.0"-syrupy = "^4.0.2"-pytest-watcher = "^0.3.4"-pytest-asyncio = "^0.21.1"+pytest = "^7.4.3"+pytest-asyncio = "^0.23.2"langchain-core = {path = "../../core", develop = true}[tool.poetry.group.codespell]optional = true[tool.poetry.group.codespell.dependencies]-codespell = "^2.2.0"+codespell = "^2.2.6"[tool.poetry.group.test_integration]optional = true@@ -41,10 +37,10 @@ optional = trueoptional = true[tool.poetry.group.lint.dependencies]-ruff = "^0.1.5"+ruff = "^0.1.8"[tool.poetry.group.typing.dependencies]-mypy = "^0.991"+mypy = "^1.7.1"langchain-core = {path = "../../core", develop = true}[tool.poetry.group.dev]@@ -87,8 +83,6 @@ addopts = "--snapshot-warn-unused --strict-markers --strict-config --durations=5# Registering custom markers.# https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markersmarkers = [- "requires: mark tests as requiring a specific library",- "asyncio: mark tests as requiring asyncio","compile: mark placeholder test used to compile integration tests without running them",]asyncio_mode = "auto"diff --git a/libs/cli/langchain_cli/integration_template/scripts/lint_imports.sh b/libs/cli/langchain_cli/integration_template/scripts/lint_imports.shindex 695613c7ba..19ccec1480 100755--- a/libs/cli/langchain_cli/integration_template/scripts/lint_imports.sh+++ b/libs/cli/langchain_cli/integration_template/scripts/lint_imports.sh@@ -5,9 +5,10 @@ set -eu# Initialize a variable to keep track of errorserrors=0-# make sure not importing from langchain or langchain_experimental+# make sure not importing from langchain, langchain_experimental, or langchain_communitygit --no-pager grep '^from langchain\.' . && errors=$((errors+1))git --no-pager grep '^from langchain_experimental\.' . && errors=$((errors+1))+git --no-pager grep '^from langchain_community\.' . && errors=$((errors+1))# Decide on an exit status based on the errorsif [ "$errors" -gt 0 ]; then