Skip to content

Commit

Permalink
Add String siez liimt to SQLAlchemy models
Browse files Browse the repository at this point in the history
Fixed a bug where MySQL/MariaDB would not write to interactions table
since VARCHAR requires a fixed length size
  • Loading branch information
r0x0d committed Jan 20, 2025
1 parent 513bc6b commit ed63055
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 48 deletions.
8 changes: 8 additions & 0 deletions command_line_assistant/config/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
class DatabaseSchema:
"""This class represents the [history.database] section of our config.toml file.
Notes:
If you are running MySQL or MariaDB in a container and want to test it
out, don't set the host to "localhost", but set it to "127.0.0.1". The
"localhost" will use the mysql socket connector, and "127.0.0.1" will
use TCP connector.
Reference: https://stackoverflow.com/a/4448568
Attributes:
connection (str): The connection string.
"""
Expand Down
16 changes: 8 additions & 8 deletions command_line_assistant/daemon/database/models/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import uuid
from datetime import datetime

from sqlalchemy import Column, DateTime, ForeignKey, Integer, String
from sqlalchemy import Column, DateTime, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship

from command_line_assistant.daemon.database.models.base import GUID, BaseModel
Expand All @@ -30,11 +30,11 @@ class InteractionModel(BaseModel):
__tablename__ = "interaction"

id = Column(GUID(), primary_key=True, default=uuid.uuid4)
query_text = Column(String)
query_role = Column(String, default="user")
response_text = Column(String)
response_role = Column(String, default="assistant")
query_text = Column(Text)
query_role = Column(String(4), default="user")
response_text = Column(Text)
response_role = Column(String(9), default="assistant")
response_tokens = Column(Integer, default=0)
os_distribution = Column(String, default="RHEL")
os_version = Column(String, nullable=False)
os_arch = Column(String, nullable=False)
os_distribution = Column(String(4), default="RHEL")
os_version = Column(String(100), nullable=False)
os_arch = Column(String(7), nullable=False)
62 changes: 51 additions & 11 deletions data/release/xdg/config.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,71 @@
[output]
# ------------------ experimental
# Experimental settings for output. Not yet working.
#[output]
# otherwise recording via script session will be enforced
enforce_script = false
#enforce_script = false
# file with output(s) of regular commands (e.g. ls, echo, etc.)
file = "/tmp/command-line-assistant/output.txt"
#file = "/tmp/command-line-assistant/output.txt"
# Keep non-empty if your file contains only output of commands (not prompt itself)
prompt_separator = "$"
#prompt_separator = "$"
# ------------------ experimental

# History management configuration
[history]
# If the history for all conversation should be enabled or not. By default,
# this is enabled and will store in a database defined under
# [history.database]. The conversation is stored per-user.
enabled = true

# History Database settings. By default, sqlite is used.
[history.database]
# Available types for databases are: sqlite, postgresql and mysql. Mariadb can
# be used as well with "mysql" type.
type = "sqlite"
# Connection string refers to the path where the sqlite database will be
# placed. Only available with sqlite type.
connection_string = "/var/lib/command-line-assistant/history.db"

# In order to use postgresql, uncomment the following settings:
# [history.database]
# type = "postgresql"
# host = "localhost"
# port = "5432"
# database = "history"
# user = "your-user"
# password = "your-password"

# Or, to use mysql, uncomment the following:
# [history.database]
# type = "mysql"
# host = "localhost"
# port = "3306"
# database = "history"
# user = "your-user"
# password = "your-password"

# Backend settings for communicating with the external API.
[backend]
# The endpoint points to an API server.
endpoint = "http://localhost:8080"

# Configure authentication settings for backend
[backend.auth]
# cert_file = "/etc/pki/consumer/cert.pem"
# key_file = "/etc/pki/consumer/key.pem"
# verify_ssl = true

# The path to the certificate file generated by RHSM.
cert_file = "/etc/pki/consumer/cert.pem"
# The path to the key file generated by RHSM.
key_file = "/etc/pki/consumer/key.pem"
# If SSL verification should be set. Don't disabled tihs for production server.
verify_ssl = true

# Logging configuration settings
[logging]
level = "DEBUG"
responses = true # Global setting - don't log responses by default
# The default logging level for all messages logged by CLAD.
level = "INFO"
# Global setting to enable logging responses in an audit file and journald
responses = true
# Global setting to enable logging question in an audit file and journald
question = true # Global setting - don't log questions by default

# User-specific settings
# User-specific settings that can override the global settings based on user name.
# Note: The user must exist in order for this to work.
# users.admin = { responses = true, question = true }
1 change: 1 addition & 0 deletions packaging/command-line-assistant.spec
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ fi

%changelog
* Wed Jan 22 2025 Rodolfo Olivieri <rolivier@redhat.com> 0.2.0
- Add String siez liimt to SQLAlchemy models
- Add workaround for SQLite UUID types
- Update packaging to include selinux custom policy
- Fix returncode when running commands
Expand Down
20 changes: 10 additions & 10 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 33 additions & 17 deletions podman-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,38 @@
version: "3"

services:
mock-server:
image: mockoon/cli:latest
command: ["--data", "data", "--port", "3000"]
healthcheck:
test: ["CMD-SHELL", "curl -f http://localhost:3000/your-healthcheck-route || exit 1"]
interval: 30s
timeout: 5s
retries: 2
start_period: 10s
postgres:
image: postgres
shm_size: 128mb
environment:
POSTGRES_PASSWORD: cla
POSTGRES_DB: history
ports:
- 3000:3000
volumes:
- ./mocks/mockoon/routes.json:/data:Z
networks:
- demo
- 5432:5432

networks:
demo:
driver: bridge
mariadb:
image: mariadb
environment:
MARIADB_ROOT_PASSWORD: cla
MARIADB_DATABASE: history
ports:
- 3306:3306
expose:
- 3306

mysql:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: cla
MYSQL_DATABASE: history
ports:
- 3306:3306
expose:
- 3306

# Inspect DB
adminer:
image: adminer
restart: always
ports:
- 8080:8080
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,11 @@ scripts = { c = "command_line_assistant.initialize:initialize", clad = "command_
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"

[dependency-groups]
[project.optional-dependencies]
db = [
"psycopg2>=2.9.10",
"mysqlclient>=2.2.7",
]
dev = [
"pytest==8.3.4",
"pytest-cov==6.0.0",
Expand Down
3 changes: 2 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ def mock_config(tmp_path):
),
),
history=HistorySchema(
enabled=True, database=DatabaseSchema(connection_string=history_db)
enabled=True,
database=DatabaseSchema(type="sqlite", connection_string=history_db),
),
logging=LoggingSchema(
level="debug",
Expand Down

0 comments on commit ed63055

Please sign in to comment.