diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4cef7cd --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +__pycache__/ +*.pyc +*.pyo +.git/ diff --git a/.env-example b/.env-example index c747ac8..5c54247 100644 --- a/.env-example +++ b/.env-example @@ -24,19 +24,3 @@ SPECBOT_AI_MODEL=gpt-4-0613 REPAIR_PRO_AI_MODEL=claude-3-5-sonnet-20240620 OPENAI_API_KEY=*** Provide your API Key *** OPENAI_BASE_URL=*** Provide your Base url *** - -# 数据库配置 -DB_NAME= -DB_USER= -DB_PASSWORD= -DB_HOST= -DB_PORT= - -# 模型名称配置 -MODEL_NAME= - -# 配置项 -VECTOR_EXTENSION= -TABLE_NAME= -VECTOR_DIMENSION= -LANGUAGE= \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9dacbb3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,36 @@ +# 使用 openEuler 22.03 基础镜像 +FROM openeuler/openeuler:22.03 + +# 设置工作目录为 /app +WORKDIR /app + +# 更新系统并安装必要的软件包 +RUN yum update -y && \ + yum install -y \ + python3 \ + python3-pip \ + python3-devel \ + gcc \ + make \ + && yum clean all + +# 创建符号链接,仅为 python 创建 +RUN ln -s /usr/bin/python3 /usr/bin/python + +# 复制 requirements.txt 到容器中 +COPY requirements.txt . + +# 安装Python依赖 +RUN pip install --no-cache-dir -r requirements.txt + +# 复制当前目录下的所有文件到容器中 +COPY . . + +# 按照模块安装 +RUN pip install . + +# 暴露容器的8000端口 +EXPOSE 8000 + +# 启动FastAPI应用 +CMD ["python", "infra_ai_service/server.py"] \ No newline at end of file diff --git a/README.CN.md b/README.CN.md index 5790ac5..4c2129a 100644 --- a/README.CN.md +++ b/README.CN.md @@ -1,18 +1,8 @@ # 注意事项 ## 前置条件 -- 需要安装qdrant本地服务 -```shell -# docker环境准备 -sudo apt update -sudo apt install docker.io -sudo systemctl start docker -sudo systemctl enable docker -# 安装 -sudo docker run -p 6333:6333 -d --name qdrant qdrant/qdrant -# 测试 -curl http://localhost:6333 -``` +- 需要安装数据库postgresql及其pgvector插件 +- 需要新增.env文件,将数据库配置,外部服务配置等添加,并将MODEL_NAME设置为multi-qa-MiniLM-L6-cos-v1 ## 本地启动 ```shell @@ -25,6 +15,14 @@ pytest . python infra_ai_service/server.py ``` +# 容器化部署 +```shell +# 构建容器 +docker build -t infra_ai_service . +# 运行ai_service服务 +docker run -p 8001:8000 -d --name infra_ai_service_imp ai_service + +``` ## 访问spec-repair API diff --git a/infra_ai_service/api/ai_enhance/embedding.py b/infra_ai_service/api/ai_enhance/embedding.py index 8aa4936..ee01548 100644 --- a/infra_ai_service/api/ai_enhance/embedding.py +++ b/infra_ai_service/api/ai_enhance/embedding.py @@ -1,7 +1,6 @@ from fastapi import APIRouter -from infra_ai_service.api.ai_enhance.text_process import TextInput -from infra_ai_service.model.model import EmbeddingOutput +from infra_ai_service.model.model import EmbeddingOutput, TextInput from infra_ai_service.service.embedding_service import create_embedding router = APIRouter() diff --git a/infra_ai_service/api/ai_enhance/text_process.py b/infra_ai_service/api/ai_enhance/text_process.py deleted file mode 100644 index d2cc5fe..0000000 --- a/infra_ai_service/api/ai_enhance/text_process.py +++ /dev/null @@ -1,11 +0,0 @@ -from fastapi import APIRouter - -from infra_ai_service.model.model import TextInput, TextOutput -from infra_ai_service.service.text_service import process_text - -router = APIRouter() - - -@router.post("/process/", response_model=TextOutput) -async def process_text_api(input_data: TextInput): - return await process_text(input_data.content) diff --git a/infra_ai_service/api/router.py b/infra_ai_service/api/router.py index 9359277..c4ec261 100644 --- a/infra_ai_service/api/router.py +++ b/infra_ai_service/api/router.py @@ -6,21 +6,19 @@ from infra_ai_service.api.ai_enhance.spec_repair_process import ( router as spec_repair_process, ) -from infra_ai_service.api.ai_enhance.text_process import ( - router as text_process_router, -) from infra_ai_service.api.ai_enhance.vector_search import ( router as vector_search_router, ) +from infra_ai_service.api.system.status import router as status_router api_router = APIRouter() api_router.include_router( spec_repair_process, prefix="/spec-repair", tags=["repair"] ) -api_router.include_router(text_process_router, prefix="/text", tags=["text"]) api_router.include_router( embedding_router, prefix="/embedding", tags=["embedding"] ) api_router.include_router( vector_search_router, prefix="/search", tags=["search"] ) +api_router.include_router(status_router, prefix="/status", tags=["status"]) diff --git a/infra_ai_service/api/system/__init__.py b/infra_ai_service/api/system/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/infra_ai_service/api/system/status.py b/infra_ai_service/api/system/status.py new file mode 100644 index 0000000..f94100c --- /dev/null +++ b/infra_ai_service/api/system/status.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter, Response, status + +router = APIRouter() + + +@router.get("/status/", status_code=status.HTTP_200_OK) +async def status(): + return Response(content="", media_type="application/json") diff --git a/infra_ai_service/service/text_service.py b/infra_ai_service/service/text_service.py deleted file mode 100644 index 9b5443c..0000000 --- a/infra_ai_service/service/text_service.py +++ /dev/null @@ -1,28 +0,0 @@ -import logging -import re - -from fastapi import HTTPException - -from infra_ai_service.model.model import TextOutput - -logger = logging.getLogger(__name__) - - -def clean_text(text: str) -> str: - try: - # 正确转义正则表达式中的特殊字符 - return re.sub(r"[{}\[\]()@.#\\_\':\/-]", "", text) - except re.error as e: - logger.error(f"Regex error: {str(e)}", exc_info=True) - raise HTTPException(status_code=400, detail="Regex processing error") - - -async def process_text(input_content: str) -> TextOutput: - try: - modified_text = clean_text(input_content) - return TextOutput(modified_content=modified_text) - except Exception as e: - logger.error(f"Error processing text: {str(e)}", exc_info=True) - raise HTTPException( - status_code=400, detail=f"Error processing text: {str(e)}" - ) diff --git a/tox.ini b/tox.ini index 71388c7..bd1162f 100644 --- a/tox.ini +++ b/tox.ini @@ -39,7 +39,7 @@ deps = coverage {[testenv]deps} commands = - pytest tests/ --cov=infra_ai_service --cov-report=term-missing + pytest tests/ --cov=infra_ai_service --cov-report=term-missing --disable-warnings coverage report --fail-under=50 coverage html