Skip to content

Commit

Permalink
FIX: Bug that cannot be answered when using the local service of Ollama.
Browse files Browse the repository at this point in the history
  • Loading branch information
xixihahaliu committed Aug 31, 2024
1 parent b60deb1 commit 6a5c37c
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 39 deletions.
22 changes: 11 additions & 11 deletions docker-compose-linux.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,9 +83,8 @@ services:
start_period: 90s
timeout: 20s
retries: 3
# ports:
# - "19530:19530"
# - "9091:9091"
ports:
- "19540:19530"
depends_on:
- "etcd"
- "minio"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -128,7 +128,7 @@ services:
tty: true
stdin_open: true

networks:
default:
name: QAnything
#networks:
# default:
# name: QAnything

21 changes: 10 additions & 11 deletions docker-compose-mac.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
networks:
default:
name: QAnything
#networks:
# default:
# name: QAnything

services:
elasticsearch:
container_name: es-container-local
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
Expand Down Expand Up @@ -88,9 +87,8 @@ services:
start_period: 90s
timeout: 20s
retries: 3
# ports:
# - "19530:19530"
# - "9091:9091"
ports:
- "19540:19530"
depends_on:
- "etcd"
- "minio"
Expand All @@ -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
Expand All @@ -120,6 +118,7 @@ services:
- "8777:8777"
environment:
- USER_IP=${USER_IP:-localhost}
- GATEWAY_IP=host.docker.internal
depends_on:
standalone:
condition: service_healthy
Expand Down
21 changes: 10 additions & 11 deletions docker-compose-win.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,9 +83,8 @@ services:
start_period: 90s
timeout: 20s
retries: 3
# ports:
# - "19530:19530"
# - "9091:9091"
ports:
- "19540:19530"
depends_on:
- "etcd"
- "minio"
Expand All @@ -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
Expand All @@ -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
Expand All @@ -128,7 +127,7 @@ services:
tty: true
stdin_open: true

networks:
default:
name: QAnything
#networks:
# default:
# name: QAnything

17 changes: 12 additions & 5 deletions qanything_kernel/configs/model_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion qanything_kernel/connector/llm/llm_for_openai_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import traceback
from openai import OpenAI
from typing import List, Optional
import json
Expand Down Expand Up @@ -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)

Expand Down
6 changes: 6 additions & 0 deletions qanything_kernel/qanything_server/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6a5c37c

Please sign in to comment.