Skip to content

Commit eb0c5b2

Browse files
author
dori
committed
fix adding sqlModel
1 parent 2f065bd commit eb0c5b2

File tree

7 files changed

+257
-297
lines changed

7 files changed

+257
-297
lines changed

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ dependencies = [
3232
"pydantic>=2.0.0",
3333
"jinja2>=3.1.0",
3434
"litellm>=1.0.0",
35+
"sqlmodel>=0.0.24",
3536
]
3637

3738
[project.urls]

src/mcp_as_a_judge/db/factory.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class DatabaseFactory:
1616
"""Factory for creating database providers."""
1717

1818
_providers: ClassVar[dict[str, type[ConversationHistoryDB]]] = {
19-
"in_memory": SQLiteProvider, # SQLite in-memory (:memory: or empty URL)
20-
"sqlite": SQLiteProvider, # SQLite file-based storage
19+
"in_memory": SQLiteProvider, # SQLModel SQLite in-memory (:memory: or empty URL)
20+
"sqlite": SQLiteProvider, # SQLModel SQLite file-based storage
2121
# Future providers can be added here:
2222
# "postgresql": PostgreSQLProvider,
2323
# "mysql": MySQLProvider,
@@ -52,7 +52,7 @@ def create_provider(cls, config: Config) -> ConversationHistoryDB:
5252

5353
# Create provider instance based on provider type
5454
if provider_name in ["in_memory", "sqlite"]:
55-
# Both use SQLiteProvider but with different URLs
55+
# SQLite-based providers (both SQLModel and legacy)
5656
return provider_class(
5757
max_context_records=config.database.max_context_records,
5858
retention_days=config.database.record_retention_days,

src/mcp_as_a_judge/db/interface.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@
88
from abc import ABC, abstractmethod
99
from datetime import datetime
1010

11-
from pydantic import BaseModel, Field
11+
from sqlmodel import Field, SQLModel
1212

1313

14-
class ConversationRecord(BaseModel):
15-
"""Model for conversation history records."""
14+
class ConversationRecord(SQLModel, table=True):
15+
"""SQLModel for conversation history records."""
1616

17-
id: str
18-
session_id: str
17+
__tablename__ = "conversation_history"
18+
19+
id: str | None = Field(default=None, primary_key=True)
20+
session_id: str = Field(index=True)
1921
source: str # tool name
2022
input: str # tool input query
2123
output: str # tool output string
2224
timestamp: datetime = Field(
23-
default_factory=datetime.utcnow
25+
default_factory=datetime.utcnow, index=True
2426
) # when the record was created
2527

2628

0 commit comments

Comments
 (0)