Skip to content

Feat/mysql support #222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,3 @@ bun.lockb
llmstudio/llm_engine/logs/execution_logs.jsonl
*.db
.prettierignore

12 changes: 7 additions & 5 deletions examples/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

start_servers(proxy=False, tracker=True)

# To test with MySQL or Postgres: before running this script update the LLMSTUDIO_TRACKING_URI env var in .env and do - cd examples & docker compose up
tracking_config = TrackingConfig(
host=os.environ["LLMSTUDIO_TRACKING_HOST"],
port=os.environ["LLMSTUDIO_TRACKING_PORT"]
Expand Down Expand Up @@ -210,18 +211,19 @@ def messages(img_path):
}
]

def run_send_imgs():
provider="bedrock"
model="us.amazon.nova-lite-v1:0"
def run_send_imgs(provider: str, model: str):
print(f"Running Chat With Images for Provider: '{provider}' and Model: '{model}'")
chat_input=messages(img_path="./libs/llmstudio/tests/integration_tests/test_data/llmstudio-logo.jpeg")
chat_request = build_chat_request(model=model, chat_input=chat_input, is_stream=False)
llm = LLMCore(provider=provider, api_key=os.environ["OPENAI_API_KEY"], region=os.environ["BEDROCK_REGION"], secret_key=os.environ["BEDROCK_SECRET_KEY"], access_key=os.environ["BEDROCK_ACCESS_KEY"])
response_sync = llm.chat(**chat_request)
#print(response_sync)
response_sync.clean_print()
#print(f"Answer: {response_sync.chat_output}")

#for p in response_sync:
# if p.metrics:
# p.clean_print()

run_send_imgs()
run_send_imgs(provider="bedrock", model="us.amazon.nova-lite-v1:0")
run_send_imgs(provider="openai", model="gpt-4o-mini")
#run_send_imgs(provider="openai", model="o4-mini")
30 changes: 30 additions & 0 deletions examples/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

services:
mysql:
image: mysql:8.0
container_name: llmstudio_mysql
restart: unless-stopped
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_DATABASE: tracker_db
volumes:
- mysql_data:/var/lib/mysql

postgres:
image: postgres:15
container_name: llmstudio_postgres
restart: unless-stopped
ports:
- "5432:5432" # Maps container 5432 to host 5433
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: tracker_db
volumes:
- postgres_data:/var/lib/postgresql/data

volumes:
mysql_data:
postgres_data:
1 change: 1 addition & 0 deletions libs/tracker/llmstudio_tracker/db/migrations/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def run_migrations_online() -> None:
target_metadata=target_metadata,
render_as_batch=is_sqlite,
compare_type=True,
compare_server_default=True,
version_table=alembic_table_name,
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Initial schema
"""initial_schema_setup

Revision ID: 6053ab0a97dc
Revision ID: 76452705dac2
Revises:
Create Date: 2025-05-05 11:27:42.586355
Create Date: 2025-05-19 16:07:58.586960

"""
from typing import Sequence, Union
Expand All @@ -11,7 +11,7 @@
from alembic import op

# revision identifiers, used by Alembic.
revision: str = "6053ab0a97dc"
revision: str = "76452705dac2"
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None
Expand All @@ -24,15 +24,16 @@ def upgrade() -> None:
"logs_default",
sa.Column("log_id", sa.Integer(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("session_id", sa.String(), nullable=True),
sa.Column("chat_input", sa.String(), nullable=True),
sa.Column("chat_output", sa.String(), nullable=True),
sa.Column("session_id", sa.String(length=191), nullable=True),
sa.Column("chat_input", sa.Text(), nullable=True),
sa.Column("chat_output", sa.Text(), nullable=True),
sa.Column("context", sa.JSON(), nullable=True),
sa.Column("provider", sa.String(), nullable=True),
sa.Column("model", sa.String(), nullable=True),
sa.Column("deployment", sa.String(), nullable=True),
sa.Column("provider", sa.String(length=191), nullable=True),
sa.Column("model", sa.String(length=191), nullable=True),
sa.Column("deployment", sa.String(length=191), nullable=True),
sa.Column("parameters", sa.JSON(), nullable=True),
sa.Column("metrics", sa.JSON(), nullable=True),
sa.Column("extras", sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint("log_id"),
)
with op.batch_alter_table("logs_default", schema=None) as batch_op:
Expand All @@ -42,15 +43,15 @@ def upgrade() -> None:

op.create_table(
"prompts",
sa.Column("prompt_id", sa.String(), nullable=False),
sa.Column("prompt_id", sa.String(length=191), nullable=False),
sa.Column("config", sa.JSON(), nullable=True),
sa.Column("prompt", sa.String(), nullable=True),
sa.Column("prompt", sa.Text(), nullable=True),
sa.Column("is_active", sa.Boolean(), nullable=True),
sa.Column("name", sa.String(), nullable=False),
sa.Column("model", sa.String(), nullable=False),
sa.Column("provider", sa.String(), nullable=False),
sa.Column("name", sa.String(length=191), nullable=False),
sa.Column("model", sa.String(length=191), nullable=False),
sa.Column("provider", sa.String(length=191), nullable=False),
sa.Column("version", sa.Integer(), nullable=False),
sa.Column("label", sa.String(), nullable=True),
sa.Column("label", sa.String(length=191), nullable=True),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("prompt_id"),
Expand All @@ -61,7 +62,7 @@ def upgrade() -> None:
op.create_table(
"sessions",
sa.Column("message_id", sa.Integer(), nullable=False),
sa.Column("session_id", sa.String(), nullable=True),
sa.Column("session_id", sa.String(length=191), nullable=True),
sa.Column("chat_history", sa.JSON(), nullable=True),
sa.Column("extras", sa.JSON(), nullable=True),
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
Expand Down

This file was deleted.

14 changes: 7 additions & 7 deletions libs/tracker/llmstudio_tracker/db/models/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from llmstudio_tracker.base_class import Base
from llmstudio_tracker.config import DB_TYPE
from llmstudio_tracker.db_utils import JSONEncodedDict
from sqlalchemy import JSON, Column, DateTime, Integer, String
from sqlalchemy import JSON, Column, DateTime, Integer, String, Text


class LogDefault(Base):
Expand Down Expand Up @@ -35,13 +35,13 @@ class LogDefault(Base):
created_at = Column(
DateTime(timezone=True), default=lambda: datetime.now(timezone.utc)
)
session_id = Column(String)
chat_input = Column(String)
chat_output = Column(String)
session_id = Column(String(191))
chat_input = Column(Text)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diogoncalves test on mdclone with postgresql and sqlite

chat_output = Column(Text)
context = Column(JSON)
provider = Column(String)
model = Column(String)
deployment = Column(String)
provider = Column(String(191))
model = Column(String(191))
deployment = Column(String(191))
parameters = Column(JSON)
metrics = Column(JSON)
extras = Column(JSON)
13 changes: 7 additions & 6 deletions libs/tracker/llmstudio_tracker/db/models/prompt_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
DateTime,
Integer,
String,
Text,
UniqueConstraint,
event,
func,
Expand All @@ -30,17 +31,17 @@ class PromptDefault(Base):
config = Column(JSONEncodedDict, nullable=True)
else:
prompt_id = Column(
String, primary_key=True, default=lambda: str(uuid.uuid4())
String(191), primary_key=True, default=lambda: str(uuid.uuid4())
) # Generate UUID as a string
config = Column(JSON, nullable=True)

prompt = Column(String)
prompt = Column(Text)
is_active = Column(Boolean, default=False)
name = Column(String, nullable=False)
model = Column(String, nullable=False)
provider = Column(String, nullable=False)
name = Column(String(191), nullable=False)
model = Column(String(191), nullable=False)
provider = Column(String(191), nullable=False)
version = Column(Integer, nullable=False)
label = Column(String)
label = Column(String(191))
updated_at = Column(
DateTime(timezone=True),
onupdate=lambda: datetime.now(timezone.utc),
Expand Down
2 changes: 1 addition & 1 deletion libs/tracker/llmstudio_tracker/db/models/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SessionDefault(Base):

else:
message_id = Column(Integer, primary_key=True, index=True)
session_id = Column(String, index=True)
session_id = Column(String(191), index=True)
chat_history = Column(JSON)
extras = Column(JSON)

Expand Down
Loading