mirror of
https://github.com/microsoft/autogen.git
synced 2025-07-06 08:30:50 +00:00

<!-- Thank you for your contribution! Please review https://microsoft.github.io/autogen/docs/Contribute before opening a pull request. --> <!-- Please add a reviewer to the assignee section when you create a PR. If you don't have the access to it, we will shortly find a reviewer and assign them to your PR. --> ## Why are these changes needed? - Adds ability to test model clients in UI after configrations, before they are used in agents or teams - Adds UI side by side comparison of sessions <img width="1878" alt="image" src="https://github.com/user-attachments/assets/f792d8d6-3f5d-4d8c-a365-5a9e9c00f49e" /> <img width="1877" alt="image" src="https://github.com/user-attachments/assets/5a115a5a-95e1-4956-a733-5f0065711fe3" /> <!-- Please give a short summary of the change and the problem this solves. --> ## Related issue number <!-- For example: "Closes #1234" --> Closes #4273 Closes #5728 ## Checks - [ ] I've included any doc changes needed for <https://microsoft.github.io/autogen/>. See <https://github.com/microsoft/autogen/blob/main/CONTRIBUTING.md> to build and test documentation locally. - [ ] I've added tests (if relevant) corresponding to the changes introduced in this PR. - [ ] I've made sure all auto checks have passed.
166 lines
6.3 KiB
Python
166 lines
6.3 KiB
Python
# defines how core data types in autogenstudio are serialized and stored in the database
|
|
|
|
from datetime import datetime
|
|
from enum import Enum
|
|
from typing import List, Optional, Union
|
|
|
|
from autogen_core import ComponentModel
|
|
from pydantic import ConfigDict, SecretStr
|
|
from sqlalchemy import ForeignKey, Integer, String
|
|
from sqlmodel import JSON, Column, DateTime, Field, SQLModel, func
|
|
|
|
from .types import (
|
|
GalleryComponents,
|
|
GalleryConfig,
|
|
GalleryMetadata,
|
|
MessageConfig,
|
|
MessageMeta,
|
|
SettingsConfig,
|
|
TeamResult,
|
|
)
|
|
|
|
|
|
class Team(SQLModel, table=True):
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), server_default=func.now()),
|
|
) # pylint: disable=not-callable
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
|
|
) # pylint: disable=not-callable
|
|
user_id: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
component: Union[ComponentModel, dict] = Field(sa_column=Column(JSON))
|
|
|
|
|
|
class Message(SQLModel, table=True):
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), server_default=func.now()),
|
|
) # pylint: disable=not-callable
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
|
|
) # pylint: disable=not-callable
|
|
user_id: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
config: Union[MessageConfig, dict] = Field(
|
|
default_factory=lambda: MessageConfig(source="", content=""), sa_column=Column(JSON)
|
|
)
|
|
session_id: Optional[int] = Field(
|
|
default=None, sa_column=Column(Integer, ForeignKey("session.id", ondelete="NO ACTION"))
|
|
)
|
|
run_id: Optional[int] = Field(default=None, sa_column=Column(Integer, ForeignKey("run.id", ondelete="CASCADE")))
|
|
|
|
message_meta: Optional[Union[MessageMeta, dict]] = Field(default={}, sa_column=Column(JSON))
|
|
|
|
|
|
class Session(SQLModel, table=True):
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), server_default=func.now()),
|
|
) # pylint: disable=not-callable
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
|
|
) # pylint: disable=not-callable
|
|
user_id: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
team_id: Optional[int] = Field(default=None, sa_column=Column(Integer, ForeignKey("team.id", ondelete="CASCADE")))
|
|
name: Optional[str] = None
|
|
|
|
|
|
class RunStatus(str, Enum):
|
|
CREATED = "created"
|
|
ACTIVE = "active"
|
|
COMPLETE = "complete"
|
|
ERROR = "error"
|
|
STOPPED = "stopped"
|
|
|
|
|
|
class Run(SQLModel, table=True):
|
|
"""Represents a single execution run within a session"""
|
|
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now, sa_column=Column(DateTime(timezone=True), server_default=func.now())
|
|
)
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now, sa_column=Column(DateTime(timezone=True), onupdate=func.now())
|
|
)
|
|
session_id: Optional[int] = Field(
|
|
default=None, sa_column=Column(Integer, ForeignKey("session.id", ondelete="CASCADE"), nullable=False)
|
|
)
|
|
status: RunStatus = Field(default=RunStatus.CREATED)
|
|
|
|
# Store the original user task
|
|
task: Union[MessageConfig, dict] = Field(
|
|
default_factory=lambda: MessageConfig(source="", content=""), sa_column=Column(JSON)
|
|
)
|
|
|
|
# Store TeamResult which contains TaskResult
|
|
team_result: Union[TeamResult, dict] = Field(default=None, sa_column=Column(JSON))
|
|
|
|
error_message: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
messages: Union[List[Message], List[dict]] = Field(default_factory=list, sa_column=Column(JSON))
|
|
|
|
model_config = ConfigDict(json_encoders={datetime: lambda v: v.isoformat()}) # type: ignore[call-arg]
|
|
user_id: Optional[str] = None
|
|
|
|
|
|
class Gallery(SQLModel, table=True):
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), server_default=func.now()),
|
|
) # pylint: disable=not-callable
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
|
|
) # pylint: disable=not-callable
|
|
user_id: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
config: Union[GalleryConfig, dict] = Field(
|
|
default_factory=lambda: GalleryConfig(
|
|
id="",
|
|
name="",
|
|
metadata=GalleryMetadata(author="", version=""),
|
|
components=GalleryComponents(agents=[], models=[], tools=[], terminations=[], teams=[]),
|
|
),
|
|
sa_column=Column(JSON),
|
|
)
|
|
|
|
model_config = ConfigDict(
|
|
json_encoders={
|
|
datetime: lambda v: v.isoformat(),
|
|
SecretStr: lambda v: v.get_secret_value(), # Add this line
|
|
}
|
|
) # type: ignore[call-arg]
|
|
|
|
|
|
class Settings(SQLModel, table=True):
|
|
__table_args__ = {"sqlite_autoincrement": True}
|
|
id: Optional[int] = Field(default=None, primary_key=True)
|
|
created_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), server_default=func.now()),
|
|
) # pylint: disable=not-callable
|
|
updated_at: datetime = Field(
|
|
default_factory=datetime.now,
|
|
sa_column=Column(DateTime(timezone=True), onupdate=func.now()),
|
|
) # pylint: disable=not-callable
|
|
user_id: Optional[str] = None
|
|
version: Optional[str] = "0.0.1"
|
|
config: Union[SettingsConfig, dict] = Field(default_factory=SettingsConfig, sa_column=Column(JSON))
|