You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Removed beartype (#3528) ### What problem does this PR solve? The beartype configuration of main(64f50992e0fc4dce73e79f8b951a02e31cb2d638) is: ``` from beartype import BeartypeConf from beartype.claw import beartype_all # <-- you didn't sign up for this beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code ``` ragflow_server failed at a third-party package: ``` (ragflow-py3.10) zhichyu@iris:~/github.com/infiniflow/ragflow$ rm -rf logs/* && bash docker/launch_backend_service.sh Starting task_executor.py for task 0 (Attempt 1) Starting ragflow_server.py (Attempt 1) Traceback (most recent call last): File "/home/zhichyu/github.com/infiniflow/ragflow/api/ragflow_server.py", line 22, in <module> from api.utils.log_utils import initRootLogger File "/home/zhichyu/github.com/infiniflow/ragflow/api/utils/__init__.py", line 25, in <module> import requests File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/__init__.py", line 15, in <module> from ._base_connection import _TYPE_BODY File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/_base_connection.py", line 5, in <module> from .util.connection import _TYPE_SOCKET_OPTIONS File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/__init__.py", line 4, in <module> from .connection import is_connection_dropped File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 7, in <module> from .timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/timeout.py", line 20, in <module> _DEFAULT_TIMEOUT: Final[_TYPE_DEFAULT] = _TYPE_DEFAULT.token NameError: name 'Final' is not defined Traceback (most recent call last): File "/home/zhichyu/github.com/infiniflow/ragflow/rag/svr/task_executor.py", line 22, in <module> from api.utils.log_utils import initRootLogger File "/home/zhichyu/github.com/infiniflow/ragflow/api/utils/__init__.py", line 25, in <module> import requests File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/requests/__init__.py", line 43, in <module> import urllib3 File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/__init__.py", line 15, in <module> from ._base_connection import _TYPE_BODY File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/_base_connection.py", line 5, in <module> from .util.connection import _TYPE_SOCKET_OPTIONS File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/__init__.py", line 4, in <module> from .connection import is_connection_dropped File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/connection.py", line 7, in <module> from .timeout import _DEFAULT_TIMEOUT, _TYPE_TIMEOUT File "/home/zhichyu/github.com/infiniflow/ragflow/.venv/lib/python3.10/site-packages/urllib3/util/timeout.py", line 20, in <module> _DEFAULT_TIMEOUT: Final[_TYPE_DEFAULT] = _TYPE_DEFAULT.token NameError: name 'Final' is not defined ``` This third-package is out of our control. I have to remove beartype entirely. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
11 miesięcy temu
Feat: Support tool calling in Generate component (#7572) ### What problem does this PR solve? Hello, our use case requires LLM agent to invoke some tools, so I made a simple implementation here. This PR does two things: 1. A simple plugin mechanism based on `pluginlib`: This mechanism lives in the `plugin` directory. It will only load plugins from `plugin/embedded_plugins` for now. A sample plugin `bad_calculator.py` is placed in `plugin/embedded_plugins/llm_tools`, it accepts two numbers `a` and `b`, then give a wrong result `a + b + 100`. In the future, it can load plugins from external location with little code change. Plugins are divided into different types. The only plugin type supported in this PR is `llm_tools`, which must implement the `LLMToolPlugin` class in the `plugin/llm_tool_plugin.py`. More plugin types can be added in the future. 2. A tool selector in the `Generate` component: Added a tool selector to select one or more tools for LLM: ![image](https://github.com/user-attachments/assets/74a21fdf-9333-4175-991b-43df6524c5dc) And with the `bad_calculator` tool, it results this with the `qwen-max` model: ![image](https://github.com/user-attachments/assets/93aff9c4-8550-414a-90a2-1a15a5249d94) ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
5 miesięcy temu
Feat: Support tool calling in Generate component (#7572) ### What problem does this PR solve? Hello, our use case requires LLM agent to invoke some tools, so I made a simple implementation here. This PR does two things: 1. A simple plugin mechanism based on `pluginlib`: This mechanism lives in the `plugin` directory. It will only load plugins from `plugin/embedded_plugins` for now. A sample plugin `bad_calculator.py` is placed in `plugin/embedded_plugins/llm_tools`, it accepts two numbers `a` and `b`, then give a wrong result `a + b + 100`. In the future, it can load plugins from external location with little code change. Plugins are divided into different types. The only plugin type supported in this PR is `llm_tools`, which must implement the `LLMToolPlugin` class in the `plugin/llm_tool_plugin.py`. More plugin types can be added in the future. 2. A tool selector in the `Generate` component: Added a tool selector to select one or more tools for LLM: ![image](https://github.com/user-attachments/assets/74a21fdf-9333-4175-991b-43df6524c5dc) And with the `bad_calculator` tool, it results this with the `qwen-max` model: ![image](https://github.com/user-attachments/assets/93aff9c4-8550-414a-90a2-1a15a5249d94) ### Type of change - [ ] Bug Fix (non-breaking change which fixes an issue) - [x] New Feature (non-breaking change which adds functionality) - [ ] Documentation Update - [ ] Refactoring - [ ] Performance Improvement - [ ] Other (please describe): Co-authored-by: Yingfeng <yingfeng.zhang@gmail.com>
5 miesięcy temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #
  2. # Copyright 2024 The InfiniFlow Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #
  16. # from beartype import BeartypeConf
  17. # from beartype.claw import beartype_all # <-- you didn't sign up for this
  18. # beartype_all(conf=BeartypeConf(violation_type=UserWarning)) # <-- emit warnings from all code
  19. from api.utils.log_utils import initRootLogger
  20. from plugin import GlobalPluginManager
  21. initRootLogger("ragflow_server")
  22. import logging
  23. import os
  24. import signal
  25. import sys
  26. import time
  27. import traceback
  28. from concurrent.futures import ThreadPoolExecutor
  29. import threading
  30. import uuid
  31. from werkzeug.serving import run_simple
  32. from api import settings
  33. from api.apps import app
  34. from api.db.runtime_config import RuntimeConfig
  35. from api.db.services.document_service import DocumentService
  36. from api import utils
  37. from api.db.db_models import init_database_tables as init_web_db
  38. from api.db.init_data import init_web_data
  39. from api.versions import get_ragflow_version
  40. from api.utils import show_configs
  41. from rag.settings import print_rag_settings
  42. from rag.utils.redis_conn import RedisDistributedLock
  43. stop_event = threading.Event()
  44. RAGFLOW_DEBUGPY_LISTEN = int(os.environ.get('RAGFLOW_DEBUGPY_LISTEN', "0"))
  45. def update_progress():
  46. lock_value = str(uuid.uuid4())
  47. redis_lock = RedisDistributedLock("update_progress", lock_value=lock_value, timeout=60)
  48. logging.info(f"update_progress lock_value: {lock_value}")
  49. while not stop_event.is_set():
  50. try:
  51. if redis_lock.acquire():
  52. DocumentService.update_progress()
  53. redis_lock.release()
  54. stop_event.wait(6)
  55. except Exception:
  56. logging.exception("update_progress exception")
  57. finally:
  58. redis_lock.release()
  59. def signal_handler(sig, frame):
  60. logging.info("Received interrupt signal, shutting down...")
  61. stop_event.set()
  62. time.sleep(1)
  63. sys.exit(0)
  64. if __name__ == '__main__':
  65. logging.info(r"""
  66. ____ ___ ______ ______ __
  67. / __ \ / | / ____// ____// /____ _ __
  68. / /_/ // /| | / / __ / /_ / // __ \| | /| / /
  69. / _, _// ___ |/ /_/ // __/ / // /_/ /| |/ |/ /
  70. /_/ |_|/_/ |_|\____//_/ /_/ \____/ |__/|__/
  71. """)
  72. logging.info(
  73. f'RAGFlow version: {get_ragflow_version()}'
  74. )
  75. logging.info(
  76. f'project base: {utils.file_utils.get_project_base_directory()}'
  77. )
  78. show_configs()
  79. settings.init_settings()
  80. print_rag_settings()
  81. if RAGFLOW_DEBUGPY_LISTEN > 0:
  82. logging.info(f"debugpy listen on {RAGFLOW_DEBUGPY_LISTEN}")
  83. import debugpy
  84. debugpy.listen(("0.0.0.0", RAGFLOW_DEBUGPY_LISTEN))
  85. # init db
  86. init_web_db()
  87. init_web_data()
  88. # init runtime config
  89. import argparse
  90. parser = argparse.ArgumentParser()
  91. parser.add_argument(
  92. "--version", default=False, help="RAGFlow version", action="store_true"
  93. )
  94. parser.add_argument(
  95. "--debug", default=False, help="debug mode", action="store_true"
  96. )
  97. args = parser.parse_args()
  98. if args.version:
  99. print(get_ragflow_version())
  100. sys.exit(0)
  101. RuntimeConfig.DEBUG = args.debug
  102. if RuntimeConfig.DEBUG:
  103. logging.info("run on debug mode")
  104. RuntimeConfig.init_env()
  105. RuntimeConfig.init_config(JOB_SERVER_HOST=settings.HOST_IP, HTTP_PORT=settings.HOST_PORT)
  106. GlobalPluginManager.load_plugins()
  107. signal.signal(signal.SIGINT, signal_handler)
  108. signal.signal(signal.SIGTERM, signal_handler)
  109. thread = ThreadPoolExecutor(max_workers=1)
  110. thread.submit(update_progress)
  111. # start http server
  112. try:
  113. logging.info("RAGFlow HTTP server start...")
  114. run_simple(
  115. hostname=settings.HOST_IP,
  116. port=settings.HOST_PORT,
  117. application=app,
  118. threaded=True,
  119. use_reloader=RuntimeConfig.DEBUG,
  120. use_debugger=RuntimeConfig.DEBUG,
  121. )
  122. except Exception:
  123. traceback.print_exc()
  124. stop_event.set()
  125. time.sleep(1)
  126. os.kill(os.getpid(), signal.SIGKILL)