diff --git a/docs/docs/integrations/chat/lindorm_chat.ipynb b/docs/docs/integrations/chat/lindorm_chat.ipynb deleted file mode 100644 index bacf51f26c1496..00000000000000 --- a/docs/docs/integrations/chat/lindorm_chat.ipynb +++ /dev/null @@ -1,169 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lindorm Chat AI\n", - "\n", - "This notebook covers how to get started with Lindorm AI." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:05:51.857436Z", - "start_time": "2024-07-24T02:05:51.762532Z" - } - }, - "outputs": [], - "source": [ - "import environs\n", - "from lindormai.model_manager import ModelManager\n", - "\n", - "env = environs.Env()\n", - "env.read_env(\".env\")\n", - "\n", - "\n", - "class Config:\n", - " AI_CHAT_LLM_ENDPOINT = env.str(\"AI_CHAT_LLM_ENDPOINT\", \"\")\n", - " AI_CHAT_USERNAME = env.str(\"AI_CHAT_USERNAME\", \"root\")\n", - " AI_CHAT_PWD = env.str(\"AI_CHAT_PWD\", \"\")\n", - " AI_DEFAULT_CHAT_MODEL = \"qa_model_qwen_72b_chat\"\n", - "\n", - "\n", - "LDAI_CHAT_LLM_ENDPOINT = Config.AI_CHAT_LLM_ENDPOINT\n", - "LDAI_CHAT_USERNAME = Config.AI_CHAT_USERNAME\n", - "LDAI_CHAT_PWD = Config.AI_CHAT_PWD" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": "## Define Helper functions" - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:05:54.600274Z", - "start_time": "2024-07-24T02:05:54.596897Z" - } - }, - "outputs": [], - "source": [ - "def check_model_exist(model_mgr, model_name):\n", - " model_list = model_mgr.list()\n", - " for model in model_list:\n", - " if model_name == model[\"name\"] and \"READY\" == model[\"status\"]:\n", - " return True\n", - " return False\n", - "\n", - "\n", - "def create_llm_model(model_mgr, model_name, path, algo):\n", - " task = \"QUESTION_ANSWERING\"\n", - " result = model_mgr.create(name=model_name, task=task, path=path, algo=algo)\n", - " return result" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create & Deploy LLM Model" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:06:56.370737Z", - "start_time": "2024-07-24T02:06:55.945422Z" - } - }, - "outputs": [], - "source": [ - "ldai_model_mgr = ModelManager(LDAI_CHAT_LLM_ENDPOINT, LDAI_CHAT_USERNAME, LDAI_CHAT_PWD)\n", - "\n", - "llm_model_name = \"qa_model_qwen_72b_chat\"\n", - "llm_model_path = \"modelscope://qwen/qwen-72b-chat-int4\"\n", - "llm_model_algo = \"QWEN_72B_CHAT_INT4\"\n", - "\n", - "\n", - "if not check_model_exist(ldai_model_mgr, llm_model_name):\n", - " create_llm_model(ldai_model_mgr, llm_model_name, llm_model_path, llm_model_algo)\n", - "else:\n", - " print(f\"model {llm_model_name} exist!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Init ChatLindormAI" - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:07:02.025370Z", - "start_time": "2024-07-24T02:07:02.015903Z" - } - }, - "outputs": [], - "source": [ - "from langchain_community.chat_models.lindormai import ChatLindormAI\n", - "\n", - "ldai_chat = ChatLindormAI(\n", - " endpoint=LDAI_CHAT_LLM_ENDPOINT,\n", - " username=LDAI_CHAT_USERNAME,\n", - " password=LDAI_CHAT_PWD,\n", - " model_name=llm_model_name,\n", - ")" - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:07:11.773551Z", - "start_time": "2024-07-24T02:07:10.357496Z" - } - }, - "outputs": [], - "source": [ - "question = \"hello? who are you?\"\n", - "\n", - "print(ldai_chat.invoke(question))" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "python39", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.18" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/docs/docs/integrations/text_embedding/lindorm_ai.ipynb b/docs/docs/integrations/text_embedding/lindorm_ai.ipynb deleted file mode 100644 index 25b3b058628f3a..00000000000000 --- a/docs/docs/integrations/text_embedding/lindorm_ai.ipynb +++ /dev/null @@ -1,306 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Lindorm Embedding\n", - "This notebook covers how to get started with Lindorm Embedding AI model." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:05:51.857436Z", - "start_time": "2024-07-24T02:05:51.762532Z" - } - }, - "outputs": [], - "source": [ - "import environs\n", - "from lindormai.model_manager import ModelManager\n", - "\n", - "env = environs.Env()\n", - "env.read_env(\".env\")\n", - "\n", - "\n", - "class Config:\n", - " AI_EMB_ENDPOINT = env.str(\"AI_EMB_ENDPOINT\", \"\")\n", - " AI_USERNAME = env.str(\"AI_USERNAME\", \"root\")\n", - " AI_PWD = env.str(\"AI_PWD\", \"\")\n", - "\n", - " AI_DEFAULT_RERANK_MODEL = \"rerank_bge_large\"\n", - " AI_DEFAULT_EMBEDDING_MODEL = \"bge-large-zh-v1.5\"\n", - " AI_DEFAULT_XIAOBU2_EMBEDDING_MODEL = \"xiaobu2\"\n", - "\n", - "\n", - "LDAI_EMB_ENDPOINT = Config.AI_EMB_ENDPOINT\n", - "LDAI_EMB_USERNAME = Config.AI_USERNAME\n", - "LDAI_EMB_PWD = Config.AI_PWD" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Define Helper functions" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-24T02:05:54.600274Z", - "start_time": "2024-07-24T02:05:54.596897Z" - } - }, - "outputs": [], - "source": [ - "def check_model_exist(model_mgr, model_name):\n", - " model_list = model_mgr.list()\n", - " for model in model_list:\n", - " if model_name == model[\"name\"] and \"READY\" == model[\"status\"]:\n", - " return True\n", - " return False\n", - "\n", - "\n", - "def create_emb_model(model_mgr, model_name, path, algo):\n", - " task = \"FEATURE_EXTRACTION\"\n", - " result = model_mgr.create(name=model_name, task=task, path=path, algo=algo)\n", - " return result\n", - "\n", - "\n", - "def create_rerank_model(model_mgr, model_name, path, algo):\n", - " task = \"SEMANTIC_SIMILARITY\"\n", - " result = model_mgr.create(name=model_name, task=task, path=path, algo=algo)\n", - " return result" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create & Deploy Embedding Model" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-23T09:25:06.088025Z", - "start_time": "2024-07-23T09:25:05.459218Z" - } - }, - "outputs": [], - "source": [ - "ldai_model_mgr = ModelManager(LDAI_EMB_ENDPOINT, LDAI_EMB_USERNAME, LDAI_EMB_PWD)\n", - "\n", - "emb_model_name = \"bge_model\"\n", - "emb_model_path = \"huggingface://BAAI/bge-large-zh-v1.5\"\n", - "emb_model_algo = \"BGE_LARGE_ZH\"\n", - "\n", - "if not check_model_exist(ldai_model_mgr, emb_model_name):\n", - " print(\"model not exist! will create\")\n", - " create_emb_model(ldai_model_mgr, emb_model_name, emb_model_path, emb_model_algo)\n", - "else:\n", - " print(f\"model {emb_model_name} exist!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Init LindormAIEmbeddings" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:49:02.819467Z", - "start_time": "2024-07-17T02:49:02.816108Z" - } - }, - "outputs": [], - "source": [ - "from langchain_community.embeddings.lindorm_embedding import LindormAIEmbeddings\n", - "\n", - "ldai_emb = LindormAIEmbeddings(\n", - " endpoint=LDAI_EMB_ENDPOINT,\n", - " username=LDAI_EMB_USERNAME,\n", - " password=LDAI_EMB_PWD,\n", - " model_name=emb_model_name,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Embed single query" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:49:06.958717Z", - "start_time": "2024-07-17T02:49:06.811384Z" - } - }, - "outputs": [], - "source": [ - "query = \"辛弃疾\"\n", - "response = ldai_emb.embed_query(query)\n", - "print(f\"emb result: {response}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Embed multiple documents" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:49:45.172244Z", - "start_time": "2024-07-17T02:49:44.890615Z" - } - }, - "outputs": [], - "source": [ - "import random\n", - "import string\n", - "\n", - "docs = []\n", - "\n", - "for i in range(10):\n", - " doc = \"\".join(random.choices(string.ascii_letters + string.digits, k=10))\n", - " docs.append(doc)\n", - "\n", - "response = ldai_emb.embed_documents(docs)\n", - "print(f\"emb result: {response[0]}\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Create & Deploy Rerank Model" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:50:11.758904Z", - "start_time": "2024-07-17T02:50:11.635214Z" - } - }, - "outputs": [], - "source": [ - "rerank_model_name = \"rerank_bge_large\"\n", - "rerank_model_path = \"huggingface://BAAI/bge-reranker-large\"\n", - "rerank_model_algo = \"BGE_RERANKER_LARGE\"\n", - "\n", - "if not check_model_exist(ldai_model_mgr, rerank_model_name):\n", - " print(\"model not exist! will create\")\n", - " create_rerank_model(\n", - " ldai_model_mgr, rerank_model_name, rerank_model_path, rerank_model_algo\n", - " )\n", - "else:\n", - " print(f\"model {rerank_model_name} exist!\")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Init LindormAIRerank" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:50:59.083932Z", - "start_time": "2024-07-17T02:50:59.067503Z" - } - }, - "outputs": [], - "source": [ - "from langchain_community.document_compressors.lindormai_rerank import LindormAIRerank\n", - "\n", - "ldai_rerank = LindormAIRerank(\n", - " endpoint=LDAI_EMB_ENDPOINT,\n", - " username=LDAI_EMB_USERNAME,\n", - " password=LDAI_EMB_PWD,\n", - " model_name=rerank_model_name,\n", - ")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Rerank documents" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "metadata": { - "ExecuteTime": { - "end_time": "2024-07-17T02:51:06.757905Z", - "start_time": "2024-07-17T02:51:06.525800Z" - } - }, - "outputs": [], - "source": [ - "from langchain_core.documents import Document\n", - "\n", - "docs = []\n", - "doc1 = Document(\"一只小狗\")\n", - "doc2 = Document(\"一个滑滑梯\")\n", - "docs.append(doc1)\n", - "docs.append(doc2)\n", - "\n", - "result = ldai_rerank.compress_documents(docs, \"两只小狗\")\n", - "print(result)" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "python39", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.18" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} diff --git a/libs/community/langchain_community/vectorstores/lindorm_search_store.py b/libs/community/langchain_community/vectorstores/lindorm_search_store.py index 73c435ef88ea1d..6a96a6a1c6be3d 100644 --- a/libs/community/langchain_community/vectorstores/lindorm_search_store.py +++ b/libs/community/langchain_community/vectorstores/lindorm_search_store.py @@ -13,7 +13,7 @@ from langchain_core.runnables import run_in_executor from langchain_core.vectorstores import VectorStore from tenacity import retry, stop_after_attempt, wait_fixed -from tqdm import tqdm +# from tqdm import tqdm IMPORT_OPENSEARCH_PY_ERROR = ( "Could not import OpenSearch. Please install it with `pip install opensearch-py`." @@ -329,7 +329,7 @@ def __init__( self.embed_jobs: List[Any] = [] self.write_jobs: List[Any] = [] - self.progress_bar = tqdm() + # self.progress_bar = tqdm() self.total_done = 0 # init route info @@ -797,11 +797,6 @@ def __add_texts( logger.info("All texts existed, Finish") return ids - self.progress_bar = tqdm( - total=self.total_done + total_items, - initial=self.total_done, - ) - for offset in range(0, total_items, bulk_size): texts_bulk = texts[offset : offset + bulk_size] metadatas_bulk = ( diff --git a/libs/community/tests/integration_tests/chat_models/test_lindorm.py b/libs/community/tests/integration_tests/chat_models/test_lindorm.py index 60d49ca920397f..5b8ed787c8536c 100644 --- a/libs/community/tests/integration_tests/chat_models/test_lindorm.py +++ b/libs/community/tests/integration_tests/chat_models/test_lindorm.py @@ -1,19 +1,17 @@ """Test Lindorm AI Chat Model.""" -import environs +import os from langchain_core.messages import AIMessage, BaseMessage, HumanMessage from langchain_core.outputs import ChatGeneration, LLMResult from langchain_community.chat_models.lindorm_chat import ChatLindormAI -env = environs.Env() -env.read_env(".env") class Config: - AI_CHAT_LLM_ENDPOINT = env.str("AI_CHAT_LLM_ENDPOINT", "") - AI_CHAT_USERNAME = env.str("AI_CHAT_USERNAME", "root") - AI_CHAT_PWD = env.str("AI_CHAT_PWD", "") + AI_CHAT_LLM_ENDPOINT = os.environ.get("AI_CHAT_LLM_ENDPOINT", "") + AI_CHAT_USERNAME = os.environ.get("AI_CHAT_USERNAME", "root") + AI_CHAT_PWD = os.environ.get("AI_CHAT_PWD", "") AI_DEFAULT_CHAT_MODEL = "qa_model_qwen_72b_chat" diff --git a/libs/community/tests/integration_tests/document_compressors/test_lindormai_rerank.py b/libs/community/tests/integration_tests/document_compressors/test_lindormai_rerank.py index c6a0651406de92..8044179d499a43 100644 --- a/libs/community/tests/integration_tests/document_compressors/test_lindormai_rerank.py +++ b/libs/community/tests/integration_tests/document_compressors/test_lindormai_rerank.py @@ -1,21 +1,20 @@ """Test Lindorm AI rerank Model.""" import asyncio +import os + from typing import Any -import environs from langchain_core.documents import Document from langchain_community.document_compressors.lindormai_rerank import LindormAIRerank -env = environs.Env() -env.read_env(".env") class Config: - AI_LLM_ENDPOINT = env.str("AI_LLM_ENDPOINT", "") - AI_USERNAME = env.str("AI_USERNAME", "root") - AI_PWD = env.str("AI_PWD", "") + AI_LLM_ENDPOINT = os.environ.get("AI_LLM_ENDPOINT", "") + AI_USERNAME = os.environ.get("AI_USERNAME", "root") + AI_PWD = os.environ.get("AI_PWD", "") AI_DEFAULT_RERANK_MODEL = "rerank_bge_v2_m3" diff --git a/libs/community/tests/integration_tests/embeddings/test_lindorm.py b/libs/community/tests/integration_tests/embeddings/test_lindorm.py index 9beaa2c3dad526..a2186913d57084 100644 --- a/libs/community/tests/integration_tests/embeddings/test_lindorm.py +++ b/libs/community/tests/integration_tests/embeddings/test_lindorm.py @@ -1,17 +1,14 @@ """Test Lindorm AI embeddings.""" -import environs +import os from langchain_community.embeddings.lindorm_embedding import LindormAIEmbeddings -env = environs.Env() -env.read_env(".env") - class Config: - AI_LLM_ENDPOINT = env.str("AI_LLM_ENDPOINT", "") - AI_USERNAME = env.str("AI_USERNAME", "root") - AI_PWD = env.str("AI_PWD", "") + AI_LLM_ENDPOINT = os.environ.ge("AI_LLM_ENDPOINT", "") + AI_USERNAME = os.environ.get("AI_USERNAME", "root") + AI_PWD = os.environ.get("AI_PWD", "") AI_DEFAULT_EMBEDDING_MODEL = "bge_m3_model" diff --git a/libs/community/tests/integration_tests/storage/test_lindorm.py b/libs/community/tests/integration_tests/storage/test_lindorm.py index 1437c53a4ee007..3825492c1d1b97 100644 --- a/libs/community/tests/integration_tests/storage/test_lindorm.py +++ b/libs/community/tests/integration_tests/storage/test_lindorm.py @@ -1,27 +1,24 @@ """Test Lindorm Search ByteStore.""" import logging - -import environs +import os from langchain_community.storage.lindorm_search_bytestore import LindormSearchByteStore logger = logging.getLogger(__name__) -env = environs.Env() -env.read_env(".env") class Config: - AI_LLM_ENDPOINT = env.str("AI_LLM_ENDPOINT", "") - AI_EMB_ENDPOINT = env.str("AI_EMB_ENDPOINT", "") - AI_USERNAME = env.str("AI_USERNAME", "root") - AI_PWD = env.str("AI_PWD", "") + AI_LLM_ENDPOINT = os.environ.get("AI_LLM_ENDPOINT", "") + AI_EMB_ENDPOINT = os.environ.get("AI_EMB_ENDPOINT", "") + AI_USERNAME = os.environ.get("AI_USERNAME", "root") + AI_PWD = os.environ.get("AI_PWD", "") AI_DEFAULT_RERANK_MODEL = "rerank_bge_v2_m3" AI_DEFAULT_EMBEDDING_MODEL = "bge_m3_model" - SEARCH_ENDPOINT = env.str("SEARCH_ENDPOINT", "SEARCH_ENDPOINT") - SEARCH_USERNAME = env.str("SEARCH_USERNAME", "root") - SEARCH_PWD = env.str("SEARCH_PWD", "") + SEARCH_ENDPOINT = os.environ.get("SEARCH_ENDPOINT", "SEARCH_ENDPOINT") + SEARCH_USERNAME = os.environ.get("SEARCH_USERNAME", "root") + SEARCH_PWD = os.environ.get("SEARCH_PWD", "") DEFAULT_BUILD_PARAMS = { diff --git a/libs/community/tests/integration_tests/vectorstores/test_lindorm.py b/libs/community/tests/integration_tests/vectorstores/test_lindorm.py index 97f01ab1687ea3..56ad4afdd73e36 100644 --- a/libs/community/tests/integration_tests/vectorstores/test_lindorm.py +++ b/libs/community/tests/integration_tests/vectorstores/test_lindorm.py @@ -1,5 +1,6 @@ """Test Lindorm Search Store.""" +import os import asyncio import copy import logging @@ -8,7 +9,6 @@ from functools import partial from typing import Any -import environs from langchain_core.documents import Document from langchain_text_splitters import CharacterTextSplitter from opensearchpy.helpers import scan @@ -17,21 +17,19 @@ from langchain_community.embeddings.lindorm_embedding import LindormAIEmbeddings from langchain_community.vectorstores.lindorm_search_store import LindormSearchStore -env = environs.Env() -env.read_env(".env") class Config: - AI_LLM_ENDPOINT = env.str("AI_LLM_ENDPOINT", "") - AI_EMB_ENDPOINT = env.str("AI_EMB_ENDPOINT", "") - AI_USERNAME = env.str("AI_USERNAME", "root") - AI_PWD = env.str("AI_PWD", "") + AI_LLM_ENDPOINT = os.environ.get("AI_LLM_ENDPOINT", "") + AI_EMB_ENDPOINT = os.environ.get("AI_EMB_ENDPOINT", "") + AI_USERNAME = os.environ.get("AI_USERNAME", "root") + AI_PWD = os.environ.get("AI_PWD", "") AI_DEFAULT_RERANK_MODEL = "rerank_bge_v2_m3" AI_DEFAULT_EMBEDDING_MODEL = "bge_m3_model" - SEARCH_ENDPOINT = env.str("SEARCH_ENDPOINT", "SEARCH_ENDPOINT") - SEARCH_USERNAME = env.str("SEARCH_USERNAME", "root") - SEARCH_PWD = env.str("SEARCH_PWD", "") + SEARCH_ENDPOINT = os.environ.get("SEARCH_ENDPOINT", "SEARCH_ENDPOINT") + SEARCH_USERNAME = os.environ.get("SEARCH_USERNAME", "root") + SEARCH_PWD = os.environ.get("SEARCH_PWD", "") logger = logging.getLogger(__name__)