This commit is contained in:
2026-09-22 15:42:25 +08:00
commit 8e86665096
60 changed files with 22339 additions and 0 deletions
@@ -0,0 +1,35 @@
"""
langchain-vertexai-shim
目的:ragas 0.4.3 在 import 时仍然从
langchain_community.chat_models.vertexai
拉取 ChatVertexAI,但该路径在新版 langchain-community 中已被移除,
官方维护迁到了独立分发 langchain-google-vertexai。
本包提供一个轻量垫片,把符号同步过去,让 `import ragas` 不再崩。
用法(uv sync 后自动生效):
import langchain_vertexai_shim # noqa: F401 — 只需 import 一次即可
import ragas
"""
import sys
import types
try:
from langchain_google_vertexai.chat_models import ChatVertexAI
except Exception: # pragma: no cover - optional dep 没装就静默跳过
ChatVertexAI = None # type: ignore[assignment]
import langchain_community.chat_models as _cm # noqa: E402
# 1) 注册子模块:langchain_community.chat_models.vertexai
_vertexai_module = types.ModuleType("langchain_community.chat_models.vertexai")
_vertexai_module.ChatVertexAI = ChatVertexAI
_cm.vertexai = _vertexai_module # 让 `from langchain_community.chat_models import vertexai` 可用
sys.modules.setdefault(
"langchain_community.chat_models.vertexai", _vertexai_module
)
__all__ = ["ChatVertexAI"]
__version__ = "0.1.0"
@@ -0,0 +1,13 @@
[project]
name = "langchain-vertexai-shim"
version = "0.1.0"
description = "Provide langchain_community.chat_models.vertexai.ChatVertexAI import path expected by ragas 0.4.3, which has moved to langchain-google-vertexai in newer langchain-community releases."
requires-python = ">=3.10"
dependencies = ["langchain-google-vertexai>=2.0"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["langchain_vertexai_shim"]