langchain[patch]: make hub work with older langchainhub versions (#19076)

Make it work with older clients
This commit is contained in:
Eugene Yurtsev 2024-03-15 18:37:52 -04:00 committed by GitHub
parent 0a784074d1
commit 0ddfe7fc9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -80,12 +80,19 @@ def pull(
:param api_key: The API key to use to authenticate with the LangChain Hub API. :param api_key: The API key to use to authenticate with the LangChain Hub API.
""" """
client = _get_client(api_url=api_url, api_key=api_key) client = _get_client(api_url=api_url, api_key=api_key)
res_dict = client.pull_repo(owner_repo_commit)
obj = loads(json.dumps(res_dict["manifest"])) if hasattr(client, "pull_repo"):
if isinstance(obj, BasePromptTemplate): # >= 0.1.15
if obj.metadata is None: res_dict = client.pull_repo(owner_repo_commit)
obj.metadata = {} obj = loads(json.dumps(res_dict["manifest"]))
obj.metadata["lc_hub_owner"] = res_dict["owner"] if isinstance(obj, BasePromptTemplate):
obj.metadata["lc_hub_repo"] = res_dict["repo"] if obj.metadata is None:
obj.metadata["lc_hub_commit_hash"] = res_dict["commit_hash"] obj.metadata = {}
return obj obj.metadata["lc_hub_owner"] = res_dict["owner"]
obj.metadata["lc_hub_repo"] = res_dict["repo"]
obj.metadata["lc_hub_commit_hash"] = res_dict["commit_hash"]
return obj
# Then it's < 0.1.15
resp: str = client.pull(owner_repo_commit)
return loads(resp)