Skip to content

Commit 7ba78de

Browse files
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # frontend/components.d.ts
2 parents 6de49c8 + 0542967 commit 7ba78de

File tree

33 files changed

+708
-436
lines changed

33 files changed

+708
-436
lines changed

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Python
2+
backend/__pycache__
3+
backend/app.egg-info
4+
backend/*.pyc
5+
backend/.mypy_cache
6+
backend/.coverage
7+
backend/htmlcov
8+
backend/.venv
9+
backend/.gitignore
10+
backend/README.md
11+
backend/scripts
12+
backend/.DS_Store

.github/workflows/build_docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: Build and push Docker image
4949
uses: docker/build-push-action@v4
5050
with:
51-
context: ./backend
51+
context: .
5252
push: true
5353
tags: |
5454
${{ secrets.DOCKERHUB_REGISTRY }}/dataease-v2/sqlbot:latest

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,6 @@ cython_debug/
184184
.pypirc
185185

186186
.DS_Store
187-
test.py
187+
test.py
188+
189+

Dockerfile

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Build stage
2+
FROM registry.cn-qingdao.aliyuncs.com/dataease/python:3.11-slim-bookworm AS builder
3+
4+
# Set build environment variables
5+
ENV PYTHONUNBUFFERED=1
6+
ENV SQLBOT_HOME=/opt/sqlbot
7+
ENV APP_HOME=${SQLBOT_HOME}/app
8+
ENV UI_HOME=${SQLBOT_HOME}/frontend
9+
ENV PYTHONPATH=${SQLBOT_HOME}/app
10+
ENV PATH="${APP_HOME}/.venv/bin:$PATH"
11+
ENV UV_COMPILE_BYTECODE=1
12+
ENV UV_LINK_MODE=copy
13+
ENV DEBIAN_FRONTEND=noninteractive
14+
15+
# Create necessary directories
16+
RUN mkdir -p ${APP_HOME} ${UI_HOME}
17+
18+
WORKDIR ${APP_HOME}
19+
20+
# Install uv tool
21+
COPY --from=ghcr.io/astral-sh/uv:0.7.8 /uv /uvx /bin/
22+
23+
# COPY ../frontend/dist /opt/sqlbot/frontend/dist
24+
COPY frontend/dist ${UI_HOME}/dist
25+
26+
# Install dependencies
27+
RUN test -f "./uv.lock" && \
28+
--mount=type=cache,target=/root/.cache/uv \
29+
--mount=type=bind,source=backend/uv.lock,target=uv.lock \
30+
--mount=type=bind,source=backend/pyproject.toml,target=pyproject.toml \
31+
uv sync --frozen --no-install-project || echo "uv.lock file not found, skipping intermediate-layers"
32+
33+
COPY ./backend ${APP_HOME}
34+
35+
# Final sync to ensure all dependencies are installed
36+
RUN --mount=type=cache,target=/root/.cache/uv \
37+
uv sync
38+
39+
# Runtime stage
40+
FROM registry.cn-qingdao.aliyuncs.com/dataease/python:3.11-slim-bookworm
41+
42+
# Set runtime environment variables
43+
ENV PYTHONUNBUFFERED=1
44+
ENV SQLBOT_HOME=/opt/sqlbot
45+
ENV PYTHONPATH=${SQLBOT_HOME}/app
46+
ENV PATH="${SQLBOT_HOME}/app/.venv/bin:$PATH"
47+
48+
RUN apt-get update && apt-get install -y --no-install-recommends \
49+
curl \
50+
&& apt-get clean \
51+
&& rm -rf /var/lib/apt/lists/*
52+
53+
# Copy necessary files from builder
54+
COPY --from=builder ${SQLBOT_HOME} ${SQLBOT_HOME}
55+
56+
WORKDIR ${SQLBOT_HOME}/app
57+
58+
# Add health check
59+
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
60+
CMD curl -f http://localhost:8000 || exit 1
61+
62+
# Run with uvicorn
63+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--workers", "4", "--proxy-headers"]

backend/.dockerignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

backend/Dockerfile

Lines changed: 0 additions & 52 deletions
This file was deleted.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""009_modify_chat
2+
3+
Revision ID: 1f077c30e476
4+
Revises: 35d925df4568
5+
Create Date: 2025-05-30 16:11:08.020715
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
import sqlmodel.sql.sqltypes
11+
from sqlalchemy.dialects import postgresql
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '1f077c30e476'
15+
down_revision = '35d925df4568'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade():
21+
# ### commands auto generated by Alembic - please adjust! ###
22+
op.drop_table('chat_record')
23+
op.create_table('chat_record',
24+
sa.Column('id', sa.Integer(), sa.Identity(always=True), nullable=False),
25+
sa.Column('chat_id', sa.Integer(), nullable=True),
26+
sa.Column('create_time', sa.DateTime(timezone=True), nullable=True),
27+
sa.Column('finish_time', sa.DateTime(timezone=True), nullable=True),
28+
sa.Column('create_by', sa.BigInteger(), nullable=True),
29+
sa.Column('datasource', sa.Integer(), nullable=False),
30+
sa.Column('engine_type', sqlmodel.sql.sqltypes.AutoString(length=64), nullable=False),
31+
sa.Column('question', sa.Text(), nullable=True),
32+
sa.Column('sql_answer', sa.Text(), nullable=True),
33+
sa.Column('sql', sa.Text(), nullable=True),
34+
sa.Column('sql_exec_result', sa.Text(), nullable=True),
35+
sa.Column('data', sa.Text(), nullable=True),
36+
sa.Column('chart_answer', sa.Text(), nullable=True),
37+
sa.Column('chart', sa.Text(), nullable=True),
38+
sa.Column('full_sql_message', sa.Text(), nullable=True),
39+
sa.Column('full_chart_message', sa.Text(), nullable=True),
40+
sa.Column('finish', sa.Boolean(), nullable=True),
41+
sa.Column('error', sa.Text(), nullable=True),
42+
sa.Column('run_time', sa.Float(), nullable=False),
43+
sa.PrimaryKeyConstraint('id')
44+
)
45+
# ### end Alembic commands ###
46+
47+
48+
def downgrade():
49+
# ### commands auto generated by Alembic - please adjust! ###
50+
op.drop_table('chat_record')
51+
op.create_table('chat_record',
52+
sa.Column('id', sa.Integer(), sa.Identity(always=True), nullable=False),
53+
sa.Column('chat_id', sa.Integer(), nullable=True),
54+
sa.Column('create_time', sa.DateTime(timezone=True), nullable=True),
55+
sa.Column('create_by', sa.BigInteger(), nullable=True),
56+
sa.Column('datasource', sa.Integer(), nullable=False),
57+
sa.Column('engine_type', sqlmodel.sql.sqltypes.AutoString(length=64), nullable=False),
58+
sa.Column('question', sa.Text(), nullable=True),
59+
sa.Column('full_question', sa.Text(), nullable=True),
60+
sa.Column('answer', sa.Text(), nullable=True),
61+
sa.Column('run_time', sa.Float(), nullable=False),
62+
sa.PrimaryKeyConstraint('id')
63+
)
64+
# ### end Alembic commands ###

backend/apps/ai_model/__init__.py

Whitespace-only changes.

backend/apps/ai_model/llm.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# todo

backend/apps/chat/schemas/chat_base_schema.py renamed to backend/apps/ai_model/model_factory.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
from abc import ABC, abstractmethod
44
from langchain_core.language_models import BaseLLM as LangchainBaseLLM
55
from langchain_openai import ChatOpenAI
6+
7+
from apps.system.models.system_model import AiModelDetail
8+
9+
610
# from langchain_community.llms import Tongyi, VLLM
711

812
class LLMConfig(BaseModel):
@@ -84,4 +88,16 @@ def create_llm(cls, config: LLMConfig) -> BaseLLM:
8488
@classmethod
8589
def register_llm(cls, model_type: str, llm_class: Type[BaseLLM]):
8690
"""Register new model type"""
87-
cls._llm_types[model_type] = llm_class
91+
cls._llm_types[model_type] = llm_class
92+
93+
94+
# todo
95+
def get_llm_config(aimodel: AiModelDetail) -> LLMConfig:
96+
config = LLMConfig(
97+
model_type="openai",
98+
model_name=aimodel.name,
99+
api_key=aimodel.api_key,
100+
api_base_url=aimodel.endpoint,
101+
additional_params={"temperature": aimodel.temperature}
102+
)
103+
return config

0 commit comments

Comments
 (0)