diff --git a/docker-compose-linux.yaml b/docker-compose-linux.yaml index c77e23e2..40718f45 100644 --- a/docker-compose-linux.yaml +++ b/docker-compose-linux.yaml @@ -4,9 +4,8 @@ services: image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2 user: root privileged: true - # ports: - # - 9200:9200 - # - 9300:9300 + ports: + - "9210:9200" restart: on-failure environment: - discovery.type=single-node @@ -84,9 +83,8 @@ services: start_period: 90s timeout: 20s retries: 3 - # ports: - # - "19530:19530" - # - "9091:9091" + ports: + - "19540:19530" depends_on: - "etcd" - "minio" @@ -95,8 +93,8 @@ services: container_name: mysql-container-local privileged: true image: mysql:8.4 - # ports: - # - "3306:3306" + ports: + - "3316:3306" command: --max-connections=10000 environment: - MYSQL_ROOT_PASSWORD=123456 @@ -114,10 +112,12 @@ services: - ${DOCKER_VOLUME_DIRECTORY:-.}/:/workspace/QAnything/ ports: - "8777:8777" + network_mode: "host" environment: - NCCL_LAUNCH_MODE=PARALLEL - GPUID=${GPUID:-0} - USER_IP=${USER_IP:-localhost} + - Gateway_IP=${Gateway_IP:-localhost} depends_on: standalone: condition: service_healthy @@ -128,7 +128,7 @@ services: tty: true stdin_open: true -networks: - default: - name: QAnything +#networks: +# default: +# name: QAnything diff --git a/docker-compose-mac.yaml b/docker-compose-mac.yaml index 2d6b9d48..75b424f1 100644 --- a/docker-compose-mac.yaml +++ b/docker-compose-mac.yaml @@ -1,6 +1,6 @@ -networks: - default: - name: QAnything +#networks: +# default: +# name: QAnything services: elasticsearch: @@ -8,9 +8,8 @@ services: image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2 user: root privileged: true - # ports: - # - 9200:9200 - # - 9300:9300 + ports: + - "9210:9200" restart: on-failure environment: - discovery.type=single-node @@ -88,9 +87,8 @@ services: start_period: 90s timeout: 20s retries: 3 - # ports: - # - "19530:19530" - # - "9091:9091" + ports: + - "19540:19530" depends_on: - "etcd" - "minio" @@ -99,8 +97,8 @@ services: container_name: mysql-container-local privileged: true image: docker.io/library/mysql:8.4 -# ports: -# - "3306:3306" + ports: + - "3316:3306" command: --max-connections=10000 environment: - MYSQL_ROOT_PASSWORD=123456 @@ -120,6 +118,7 @@ services: - "8777:8777" environment: - USER_IP=${USER_IP:-localhost} + - GATEWAY_IP=host.docker.internal depends_on: standalone: condition: service_healthy diff --git a/docker-compose-win.yaml b/docker-compose-win.yaml index 9993c1c9..1361eea1 100644 --- a/docker-compose-win.yaml +++ b/docker-compose-win.yaml @@ -4,9 +4,8 @@ services: image: docker.elastic.co/elasticsearch/elasticsearch:8.13.2 user: root privileged: true - # ports: - # - 9200:9200 - # - 9300:9300 + ports: + - "9210:9200" restart: on-failure environment: - discovery.type=single-node @@ -84,9 +83,8 @@ services: start_period: 90s timeout: 20s retries: 3 - # ports: - # - "19530:19530" - # - "9091:9091" + ports: + - "19540:19530" depends_on: - "etcd" - "minio" @@ -95,8 +93,8 @@ services: container_name: mysql-container-local privileged: true image: mysql:8.4 - # ports: - # - "3306:3306" + ports: + - "3316:3306" command: --max-connections=10000 environment: - MYSQL_ROOT_PASSWORD=123456 @@ -118,6 +116,7 @@ services: - NCCL_LAUNCH_MODE=PARALLEL - GPUID=${GPUID:-0} - USER_IP=${USER_IP:-localhost} + - GATEWAY_IP=host.docker.internal depends_on: standalone: condition: service_healthy @@ -128,7 +127,7 @@ services: tty: true stdin_open: true -networks: - default: - name: QAnything +#networks: +# default: +# name: QAnything diff --git a/qanything_kernel/configs/model_config.py b/qanything_kernel/configs/model_config.py index 9462a09e..9262b56c 100644 --- a/qanything_kernel/configs/model_config.py +++ b/qanything_kernel/configs/model_config.py @@ -2,6 +2,8 @@ from dotenv import load_dotenv load_dotenv() +# 获取环境变量GATEWAY_IP +GATEWAY_IP = os.getenv("GATEWAY_IP", "localhost") # LOG_FORMAT = "%(levelname) -5s %(asctime)s" "-1d: %(message)s" # logger = logging.getLogger() # logger.setLevel(logging.INFO) @@ -94,18 +96,23 @@ VECTOR_SEARCH_SCORE_THRESHOLD = 0.3 KB_SUFFIX = '_240625' -MILVUS_HOST_LOCAL = 'milvus-standalone-local' -MILVUS_PORT = 19530 +# MILVUS_HOST_LOCAL = 'milvus-standalone-local' +# MILVUS_PORT = 19530 +MILVUS_HOST_LOCAL = GATEWAY_IP +MILVUS_PORT = 19540 MILVUS_COLLECTION_NAME = 'qanything_collection' + KB_SUFFIX -ES_URL = 'http://es-container-local:9200/' +# ES_URL = 'http://es-container-local:9200/' +ES_URL = f'http://{GATEWAY_IP}:9210/' ES_USER = None ES_PASSWORD = None ES_TOP_K = 30 ES_INDEX_NAME = 'qanything_es_index' + KB_SUFFIX -MYSQL_HOST_LOCAL = 'mysql-container-local' -MYSQL_PORT_LOCAL = 3306 +# MYSQL_HOST_LOCAL = 'mysql-container-local' +# MYSQL_PORT_LOCAL = 3306 +MYSQL_HOST_LOCAL = GATEWAY_IP +MYSQL_PORT_LOCAL = 3316 MYSQL_USER_LOCAL = 'root' MYSQL_PASSWORD_LOCAL = '123456' MYSQL_DATABASE_LOCAL = 'qanything' diff --git a/qanything_kernel/connector/llm/llm_for_openai_api.py b/qanything_kernel/connector/llm/llm_for_openai_api.py index 276406c3..268061cd 100644 --- a/qanything_kernel/connector/llm/llm_for_openai_api.py +++ b/qanything_kernel/connector/llm/llm_for_openai_api.py @@ -1,3 +1,4 @@ +import traceback from openai import OpenAI from typing import List, Optional import json @@ -121,7 +122,7 @@ async def _call(self, messages: List[dict], streaming: bool = False) -> str: yield "data: " + json.dumps(delta, ensure_ascii=False) except Exception as e: - debug_logger.info(f"Error calling OpenAI API: {e}") + debug_logger.info(f"Error calling OpenAI API: {traceback.format_exc()}") delta = {'answer': f"{e}"} yield "data: " + json.dumps(delta, ensure_ascii=False) diff --git a/qanything_kernel/qanything_server/handler.py b/qanything_kernel/qanything_server/handler.py index debad2af..32d58369 100644 --- a/qanything_kernel/qanything_server/handler.py +++ b/qanything_kernel/qanything_server/handler.py @@ -31,6 +31,9 @@ INVALID_USER_ID = f"fail, Invalid user_id: . user_id 必须只含有字母,数字和下划线且字母开头" +# 获取环境变量GATEWAY_IP +GATEWAY_IP = os.getenv("GATEWAY_IP", "localhost") +debug_logger.info(f"GATEWAY_IP: {GATEWAY_IP}") # 异步包装器,用于在后台执行带有参数的同步函数 async def run_in_background(func, *args): @@ -645,6 +648,9 @@ async def local_doc_chat(req: request): need_web_search = safe_get(req, 'networking', False) api_base = safe_get(req, 'api_base', '') + # 如果api_base中包含0.0.0.0或127.0.0.1或localhost,替换为GATEWAY_IP + api_base = api_base.replace('0.0.0.0', GATEWAY_IP).replace('127.0.0.1', GATEWAY_IP).replace('localhost', GATEWAY_IP) + api_key = safe_get(req, 'api_key', 'ollama') api_context_length = safe_get(req, 'api_context_length', 4096) top_p = safe_get(req, 'top_p', 0.99)