chore(cli): remove ruff exclusion of templates (#32864)

This commit is contained in:
Christophe Bornet
2025-09-09 20:56:47 +02:00
committed by GitHub
parent 256a0b5f2f
commit 352ff363ca
19 changed files with 1317 additions and 1302 deletions

View File

@@ -63,7 +63,9 @@
"import os\n", "import os\n",
"\n", "\n",
"if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n", "if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n",
" os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" " os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
" )"
] ]
}, },
{ {

View File

@@ -58,7 +58,9 @@
"import getpass\n", "import getpass\n",
"import os\n", "import os\n",
"\n", "\n",
"os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" "os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
")"
] ]
}, },
{ {

View File

@@ -56,7 +56,9 @@
"import os\n", "import os\n",
"\n", "\n",
"if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n", "if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n",
" os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" " os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
" )"
] ]
}, },
{ {
@@ -173,9 +175,7 @@
"source": [ "source": [
"from langchain_core.prompts import PromptTemplate\n", "from langchain_core.prompts import PromptTemplate\n",
"\n", "\n",
"prompt = PromptTemplate(\n", "prompt = PromptTemplate(\"How to say {input} in {output_language}:\\n\")\n",
" \"How to say {input} in {output_language}:\\n\"\n",
")\n",
"\n", "\n",
"chain = prompt | llm\n", "chain = prompt | llm\n",
"chain.invoke(\n", "chain.invoke(\n",

View File

@@ -62,7 +62,9 @@
"import os\n", "import os\n",
"\n", "\n",
"if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n", "if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n",
" os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" " os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
" )"
] ]
}, },
{ {

View File

@@ -52,7 +52,9 @@
"import os\n", "import os\n",
"\n", "\n",
"if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n", "if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n",
" os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" " os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
" )"
] ]
}, },
{ {

View File

@@ -120,9 +120,7 @@
"from langchain_community.tools import __ModuleName__\n", "from langchain_community.tools import __ModuleName__\n",
"\n", "\n",
"\n", "\n",
"tool = __ModuleName__(\n", "tool = __ModuleName__(...)"
" ...\n",
")"
] ]
}, },
{ {

View File

@@ -68,7 +68,9 @@
"import os\n", "import os\n",
"\n", "\n",
"if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n", "if not os.getenv(\"__MODULE_NAME___API_KEY\"):\n",
" os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\"Enter your __ModuleName__ API key: \")" " os.environ[\"__MODULE_NAME___API_KEY\"] = getpass.getpass(\n",
" \"Enter your __ModuleName__ API key: \"\n",
" )"
] ]
}, },
{ {
@@ -140,24 +142,15 @@
"source": [ "source": [
"from langchain_core.documents import Document\n", "from langchain_core.documents import Document\n",
"\n", "\n",
"document_1 = Document(\n", "document_1 = Document(page_content=\"foo\", metadata={\"source\": \"https://example.com\"})\n",
" page_content=\"foo\",\n",
" metadata={\"source\": \"https://example.com\"}\n",
")\n",
"\n", "\n",
"document_2 = Document(\n", "document_2 = Document(page_content=\"bar\", metadata={\"source\": \"https://example.com\"})\n",
" page_content=\"bar\",\n",
" metadata={\"source\": \"https://example.com\"}\n",
")\n",
"\n", "\n",
"document_3 = Document(\n", "document_3 = Document(page_content=\"baz\", metadata={\"source\": \"https://example.com\"})\n",
" page_content=\"baz\",\n",
" metadata={\"source\": \"https://example.com\"}\n",
")\n",
"\n", "\n",
"documents = [document_1, document_2, document_3]\n", "documents = [document_1, document_2, document_3]\n",
"\n", "\n",
"vector_store.add_documents(documents=documents,ids=[\"1\",\"2\",\"3\"])" "vector_store.add_documents(documents=documents, ids=[\"1\", \"2\", \"3\"])"
] ]
}, },
{ {
@@ -178,11 +171,10 @@
"outputs": [], "outputs": [],
"source": [ "source": [
"updated_document = Document(\n", "updated_document = Document(\n",
" page_content=\"qux\",\n", " page_content=\"qux\", metadata={\"source\": \"https://another-example.com\"}\n",
" metadata={\"source\": \"https://another-example.com\"}\n",
")\n", ")\n",
"\n", "\n",
"vector_store.update_documents(document_id=\"1\",document=updated_document)" "vector_store.update_documents(document_id=\"1\", document=updated_document)"
] ]
}, },
{ {
@@ -228,7 +220,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"results = vector_store.similarity_search(query=\"thud\",k=1,filter={\"source\":\"https://another-example.com\"})\n", "results = vector_store.similarity_search(\n",
" query=\"thud\", k=1, filter={\"source\": \"https://another-example.com\"}\n",
")\n",
"for doc in results:\n", "for doc in results:\n",
" print(f\"* {doc.page_content} [{doc.metadata}]\")" " print(f\"* {doc.page_content} [{doc.metadata}]\")"
] ]
@@ -250,7 +244,9 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"results = vector_store.similarity_search_with_score(query=\"thud\",k=1,filter={\"source\":\"https://example.com\"})\n", "results = vector_store.similarity_search_with_score(\n",
" query=\"thud\", k=1, filter={\"source\": \"https://example.com\"}\n",
")\n",
"for doc, score in results:\n", "for doc, score in results:\n",
" print(f\"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]\")" " print(f\"* [SIM={score:3f}] {doc.page_content} [{doc.metadata}]\")"
] ]
@@ -274,10 +270,7 @@
"metadata": {}, "metadata": {},
"outputs": [], "outputs": [],
"source": [ "source": [
"retriever = vector_store.as_retriever(\n", "retriever = vector_store.as_retriever(search_type=\"mmr\", search_kwargs={\"k\": 1})\n",
" search_type=\"mmr\",\n",
" search_kwargs={\"k\": 1}\n",
")\n",
"retriever.invoke(\"thud\")" "retriever.invoke(\"thud\")"
] ]
}, },

View File

@@ -21,11 +21,13 @@ class Chat__ModuleName__(BaseChatModel):
# https://github.com/langchain-ai/langchain/blob/7ff05357bac6eaedf5058a2af88f23a1817d40fe/libs/partners/openai/langchain_openai/chat_models/base.py#L1120 # https://github.com/langchain-ai/langchain/blob/7ff05357bac6eaedf5058a2af88f23a1817d40fe/libs/partners/openai/langchain_openai/chat_models/base.py#L1120
"""__ModuleName__ chat model integration. """__ModuleName__ chat model integration.
The default implementation echoes the first `parrot_buffer_length` characters of the input. The default implementation echoes the first `parrot_buffer_length` characters of
the input.
# TODO: Replace with relevant packages, env vars. # TODO: Replace with relevant packages, env vars.
Setup: Setup:
Install ``__package_name__`` and set environment variable ``__MODULE_NAME___API_KEY``. Install ``__package_name__`` and set environment variable
``__MODULE_NAME___API_KEY``.
.. code-block:: bash .. code-block:: bash
@@ -48,7 +50,8 @@ class Chat__ModuleName__(BaseChatModel):
max_retries: int max_retries: int
Max number of retries. Max number of retries.
api_key: Optional[str] api_key: Optional[str]
__ModuleName__ API key. If not passed in will be read from env var __MODULE_NAME___API_KEY. __ModuleName__ API key. If not passed in will be read from env var
__MODULE_NAME___API_KEY.
See full list of supported init args and their descriptions in the params section. See full list of supported init args and their descriptions in the params section.

View File

@@ -14,7 +14,8 @@ class __ModuleName__Loader(BaseLoader):
# TODO: Replace with relevant packages, env vars. # TODO: Replace with relevant packages, env vars.
Setup: Setup:
Install ``__package_name__`` and set environment variable ``__MODULE_NAME___API_KEY``. Install ``__package_name__`` and set environment variable
``__MODULE_NAME___API_KEY``.
.. code-block:: bash .. code-block:: bash
@@ -62,7 +63,7 @@ class __ModuleName__Loader(BaseLoader):
TODO: Example output TODO: Example output
""" # noqa: E501 """
# TODO: This method must be implemented to load documents. # TODO: This method must be implemented to load documents.
# Do not implement load(), a default implementation is already available. # Do not implement load(), a default implementation is already available.

View File

@@ -12,7 +12,8 @@ class __ModuleName__Toolkit(BaseToolkit):
# TODO: Replace with relevant packages, env vars, etc. # TODO: Replace with relevant packages, env vars, etc.
Setup: Setup:
Install ``__package_name__`` and set environment variable ``__MODULE_NAME___API_KEY``. Install ``__package_name__`` and set environment variable
``__MODULE_NAME___API_KEY``.
.. code-block:: bash .. code-block:: bash
@@ -65,7 +66,7 @@ class __ModuleName__Toolkit(BaseToolkit):
# TODO: Example output. # TODO: Example output.
""" # noqa: E501 """
# TODO: This method must be implemented to list tools. # TODO: This method must be implemented to list tools.
def get_tools(self) -> List[BaseTool]: def get_tools(self) -> List[BaseTool]:

View File

@@ -27,7 +27,8 @@ class __ModuleName__Tool(BaseTool): # type: ignore[override]
Setup: Setup:
# TODO: Replace with relevant packages, env vars. # TODO: Replace with relevant packages, env vars.
Install ``__package_name__`` and set environment variable ``__MODULE_NAME___API_KEY``. Install ``__package_name__`` and set environment variable
``__MODULE_NAME___API_KEY``.
.. code-block:: bash .. code-block:: bash

View File

@@ -25,6 +25,9 @@ langchain-core = "^0.3.15"
[tool.ruff.lint] [tool.ruff.lint]
select = ["E", "F", "I", "T201"] select = ["E", "F", "I", "T201"]
[tool.ruff.lint.per-file-ignores]
"docs/**" = [ "ALL",]
[tool.coverage.run] [tool.coverage.run]
omit = ["tests/*"] omit = ["tests/*"]

View File

@@ -1,3 +1,5 @@
"""__module_name__ module."""
from __module_name__.chain import chain from __module_name__.chain import chain
__all__ = ["chain"] __all__ = ["chain"]

View File

@@ -1,3 +1,5 @@
"""Chain definition."""
from langchain_core.prompts import ChatPromptTemplate from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI from langchain_openai import ChatOpenAI

View File

@@ -0,0 +1 @@
"""Tests."""

View File

@@ -0,0 +1 @@
"""Server application."""

View File

@@ -1,3 +1,5 @@
"""Chain server."""
from fastapi import FastAPI from fastapi import FastAPI
from fastapi.responses import RedirectResponse from fastapi.responses import RedirectResponse
from langserve import add_routes from langserve import add_routes
@@ -6,7 +8,7 @@ app = FastAPI()
@app.get("/") @app.get("/")
async def redirect_root_to_docs() -> RedirectResponse: async def _redirect_root_to_docs() -> RedirectResponse:
return RedirectResponse("/docs") return RedirectResponse("/docs")
@@ -16,4 +18,4 @@ add_routes(app, NotImplemented)
if __name__ == "__main__": if __name__ == "__main__":
import uvicorn import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000) uvicorn.run(app, host="0.0.0.0", port=8000) # noqa: S104

View File

@@ -41,11 +41,9 @@ langchain = { path = "../langchain", editable = true }
[tool.ruff] [tool.ruff]
target-version = "py39" target-version = "py39"
exclude = [
"langchain_cli/integration_template", [tool.ruff.format]
"langchain_cli/package_template", docstring-code-format = true
"langchain_cli/project_template",
]
[tool.ruff.lint] [tool.ruff.lint]
select = [ "ALL",] select = [ "ALL",]

3
libs/cli/uv.lock generated
View File

@@ -667,9 +667,10 @@ test-integration = [
{ name = "transformers", specifier = ">=4.51.3,<5.0.0" }, { name = "transformers", specifier = ">=4.51.3,<5.0.0" },
] ]
typing = [ typing = [
{ name = "beautifulsoup4", specifier = ">=4.13.5,<5.0.0" },
{ name = "lxml-stubs", specifier = ">=0.5.1,<1.0.0" }, { name = "lxml-stubs", specifier = ">=0.5.1,<1.0.0" },
{ name = "mypy", specifier = ">=1.17.1,<1.18" }, { name = "mypy", specifier = ">=1.17.1,<1.18" },
{ name = "tiktoken", specifier = ">=0.8.0,<1.0.0" }, { name = "tiktoken", specifier = ">=0.11.0,<1.0.0" },
{ name = "types-requests", specifier = ">=2.31.0.20240218,<3.0.0.0" }, { name = "types-requests", specifier = ">=2.31.0.20240218,<3.0.0.0" },
] ]