Make Dockerfile and docker compose ready for build

This commit is contained in:
Phil Szalay 2025-02-11 09:49:29 +01:00
parent 07a6fbbb5f
commit 641cf04a6e
5 changed files with 91 additions and 19 deletions

View File

@ -26,6 +26,9 @@ ARG BUILD_HASH
WORKDIR /app WORKDIR /app
# Set the Node.js memory limit to 8GB
ENV NODE_OPTIONS="--max-old-space-size=8240"
COPY package.json package-lock.json ./ COPY package.json package-lock.json ./
RUN npm ci RUN npm ci

View File

@ -59,7 +59,6 @@ class Model(Base):
""" """
The model's id as used in the API. If set to an existing model, it will override the model. The model's id as used in the API. If set to an existing model, it will override the model.
""" """
user_id = Column(Text)
base_model_id = Column(Text, nullable=True) base_model_id = Column(Text, nullable=True)
""" """
@ -108,7 +107,6 @@ class Model(Base):
class ModelModel(BaseModel): class ModelModel(BaseModel):
id: str id: str
user_id: str
base_model_id: Optional[str] = None base_model_id: Optional[str] = None
name: str name: str
@ -151,12 +149,11 @@ class ModelForm(BaseModel):
class ModelsTable: class ModelsTable:
def insert_new_model( def insert_new_model(
self, form_data: ModelForm, user_id: str, company_id: str self, form_data: ModelForm, company_id: str
) -> Optional[ModelModel]: ) -> Optional[ModelModel]:
model = ModelModel( model = ModelModel(
**{ **{
**form_data.model_dump(), **form_data.model_dump(),
"user_id": user_id,
"company_id": company_id, "company_id": company_id,
"created_at": int(time.time()), "created_at": int(time.time()),
"updated_at": int(time.time()), "updated_at": int(time.time()),

View File

@ -0,0 +1,67 @@
"""Remove user_id column, add company_id column in model table
Revision ID: 6eb174dec7b4
Revises: 9ca43b058511
Create Date: 2025-02-10 16:14:39.127920
"""
from typing import Sequence, Union
from alembic import op
import sqlalchemy as sa
import open_webui.internal.db
from sqlalchemy.engine.reflection import Inspector
# revision identifiers, used by Alembic.
revision: str = '6eb174dec7b4'
down_revision: Union[str, None] = '9ca43b058511'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
def column_exists(table, column):
conn = op.get_bind()
inspector = Inspector.from_engine(conn)
columns = inspector.get_columns(table)
return any(c["name"] == column for c in columns)
def upgrade() -> None:
# Add company_id column if it doesn't exist
if not column_exists("model", "company_id"):
op.add_column('model', sa.Column('company_id', sa.String(), nullable=True))
# Make columns non-nullable
with op.batch_alter_table('model', schema=None) as batch_op:
batch_op.alter_column('company_id', nullable=False)
# Delete user_id column if it exists
if column_exists("model", "user_id"):
batch_op.drop_column('user_id')
# Add foreign key constraint if it doesn't exist
conn = op.get_bind()
inspector = Inspector.from_engine(conn)
foreign_keys = inspector.get_foreign_keys('model')
if not any(fk['referred_table'] == 'company' for fk in foreign_keys):
with op.batch_alter_table('model', schema=None) as batch_op:
batch_op.create_foreign_key(
'fk_user_company_id', 'company',
['company_id'], ['id'], ondelete='CASCADE'
)
def downgrade() -> None:
with op.batch_alter_table('model', schema=None) as batch_op:
# Remove foreign key constraint if it exists
foreign_keys = Inspector.from_engine(op.get_bind()).get_foreign_keys('model')
if any(fk['name'] == 'fk_user_company_id' for fk in foreign_keys):
batch_op.drop_constraint('fk_user_company_id', type_='foreignkey')
# Drop columns if they exist
if column_exists("model", "company_id"):
batch_op.drop_column('company_id')
# Add back user_id column if it doesn't exist
if not column_exists("model", "user_id"):
batch_op.add_column(sa.Column('user_id', sa.String(), nullable=True))

View File

@ -10,10 +10,10 @@ from beyond_the_loop.models.models import (
from open_webui.constants import ERROR_MESSAGES from open_webui.constants import ERROR_MESSAGES
from fastapi import APIRouter, Depends, HTTPException, Request, status from fastapi import APIRouter, Depends, HTTPException, Request, status
from open_webui.utils.auth import get_admin_user, get_verified_user from open_webui.utils.auth import get_admin_user, get_verified_user
from open_webui.utils.access_control import has_access, has_permission from open_webui.utils.access_control import has_access, has_permission
from beyond_the_loop.models.companies import Companies
router = APIRouter() router = APIRouter()
@ -68,7 +68,9 @@ async def create_new_model(
) )
else: else:
model = Models.insert_new_model(form_data, user.id) company = Companies.get_company_by_id(user.company_id)
model = Models.insert_new_model(form_data, company.id)
if model: if model:
return model return model
else: else:

View File

@ -1,34 +1,37 @@
version: '3.8'
services: services:
ollama: litellm:
volumes: container_name: litellm
- ollama:/root/.ollama image: ghcr.io/berriai/litellm:main-stable
container_name: ollama
pull_policy: always
tty: true
restart: unless-stopped restart: unless-stopped
image: ollama/ollama:${OLLAMA_DOCKER_TAG-latest} ports:
- "4000:4000"
volumes:
- ./litellm-config.yaml:/app/config.yaml
command: ["--config", "/app/config.yaml", "--port", "4000"]
extra_hosts:
- host.docker.internal:host-gateway
open-webui: open-webui:
build: build:
context: . context: .
args: args:
OLLAMA_BASE_URL: '/ollama' LITELLM_BASE_URL: '/litellm'
dockerfile: Dockerfile dockerfile: Dockerfile
image: ghcr.io/open-webui/open-webui:${WEBUI_DOCKER_TAG-main} image: ghcr.io/open-webui/open-webui:${WEBUI_DOCKER_TAG-main}
container_name: open-webui container_name: open-webui
volumes: volumes:
- open-webui:/app/backend/data - open-webui:/app/backend/data
depends_on: depends_on:
- ollama - litellm
ports: ports:
- ${OPEN_WEBUI_PORT-3000}:8080 - "8080:8080" # Open Web UI port
environment: environment:
- 'OLLAMA_BASE_URL=http://ollama:11434' - "OPENAI_API_BASE_URL=http://litellm:4000/v1" # Point Open Web UI to LiteLLM
- 'WEBUI_SECRET_KEY='
extra_hosts: extra_hosts:
- host.docker.internal:host-gateway - host.docker.internal:host-gateway
restart: unless-stopped restart: unless-stopped
volumes: volumes:
ollama: {}
open-webui: {} open-webui: {}