From 3555882a0de152fd621c44d9f3fafba6386a0f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E6=B5=A9?= <107397001+cuiihaoo@users.noreply.github.com> Date: Thu, 29 Aug 2024 09:41:43 +0800 Subject: [PATCH] community[patch]: optimize xinference llm import (#25809) Thank you for contributing to LangChain! - [ ] **PR title**: "community: optimize xinference llm import" - [ ] **PR message**: - **Description:** from xinferece_client import RESTfulClient when there is no importing xinference. - **Dependencies:** xinferece_client - **Why do so:** the total xinference(pip install xinference[all]) is too heavy for installing, let alone it is useless for langchain user except RESTfulClient. The modification has maintained consistency with the xinference embeddings [embeddings/xinference](../blob/master/libs/community/langchain_community/embeddings/xinference.py#L89). --- .../langchain_community/llms/xinference.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libs/community/langchain_community/llms/xinference.py b/libs/community/langchain_community/llms/xinference.py index 3e38fb5fd0..8a6cb2ee56 100644 --- a/libs/community/langchain_community/llms/xinference.py +++ b/libs/community/langchain_community/llms/xinference.py @@ -17,6 +17,12 @@ class Xinference(LLM): pip install "xinference[all]" + If you're simply using the services provided by Xinference, you can utilize the xinference_client package: + + .. code-block:: bash + + pip install xinference_client + Check out: https://github.com/xorbitsai/inference To run, you need to start a Xinference supervisor on one server and Xinference workers on the other servers @@ -91,11 +97,14 @@ class Xinference(LLM): ): try: from xinference.client import RESTfulClient - except ImportError as e: - raise ImportError( - "Could not import RESTfulClient from xinference. Please install it" - " with `pip install xinference`." - ) from e + except ImportError: + try: + from xinference_client import RESTfulClient + except ImportError as e: + raise ImportError( + "Could not import RESTfulClient from xinference. Please install it" + " with `pip install xinference` or `pip install xinference_client`." + ) from e model_kwargs = model_kwargs or {}