Skip to content

Commit

Permalink
feat: combining tools and models to implement AI functions
Browse files Browse the repository at this point in the history
  • Loading branch information
polebug committed Jan 21, 2025
1 parent abea8bd commit 400de79
Show file tree
Hide file tree
Showing 15 changed files with 410 additions and 171 deletions.
51 changes: 0 additions & 51 deletions openagent/agents/__init__.py

This file was deleted.

8 changes: 0 additions & 8 deletions openagent/agents/feed.py

This file was deleted.

8 changes: 0 additions & 8 deletions openagent/agents/finance.py

This file was deleted.

10 changes: 0 additions & 10 deletions openagent/agents/twitter.py

This file was deleted.

27 changes: 25 additions & 2 deletions openagent/database/models/agent.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import enum
from typing import List

from sqlalchemy import Column, Integer, String, DateTime, JSON, Enum
from datetime import datetime, UTC

from openagent.database.models.base import Base
from openagent.tools import ToolConfig


class AgentStatus(enum.Enum):
class AgentStatus(str, enum.Enum):
INACTIVE = "inactive"
ACTIVE = "active"

def __str__(self):
return self.value


class Agent(Base):
__tablename__ = "agents"
Expand All @@ -28,11 +33,29 @@ class Agent(Base):
telegram = Column(String)
website = Column(String)
tool_configs = Column(JSON)
status = Column(Enum(AgentStatus), nullable=False)
status = Column(
Enum(AgentStatus, values_callable=lambda x: [e.value for e in x]),
nullable=False,
)
created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
updated_at = Column(
DateTime,
default=lambda: datetime.now(UTC),
onupdate=lambda: datetime.now(UTC),
nullable=False,
)

def __init__(self, *args, **kwargs):
if "status" in kwargs and isinstance(kwargs["status"], AgentStatus):
kwargs["status"] = kwargs["status"].value
super().__init__(*args, **kwargs)

@property
def tool_configs_list(self) -> List[ToolConfig]:
if not self.tool_configs:
return []
return [ToolConfig.model_validate(config) for config in self.tool_configs]

@tool_configs_list.setter
def tool_configs_list(self, configs: List[ToolConfig]):
self.tool_configs = [config.model_dump() for config in configs]
13 changes: 12 additions & 1 deletion openagent/database/models/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,29 @@ class ToolType(enum.Enum):
TEXT_GENERATION = "text_generation"
SOCIAL_INTEGRATION = "social_integration"

def __str__(self):
return self.value


class Tool(Base):
__tablename__ = "tools"

id = Column(Integer, primary_key=True)
name = Column(String, nullable=False)
description = Column(Text)
type = Column(Enum(ToolType), nullable=False)
type = Column(
Enum(ToolType, values_callable=lambda x: [e.value for e in x]),
nullable=False,
)
created_at = Column(DateTime, default=lambda: datetime.now(UTC), nullable=False)
updated_at = Column(
DateTime,
default=lambda: datetime.now(UTC),
onupdate=lambda: datetime.now(UTC),
nullable=False,
)

def __init__(self, *args, **kwargs):
if "type" in kwargs and isinstance(kwargs["type"], ToolType):
kwargs["type"] = kwargs["type"].value
super().__init__(*args, **kwargs)
3 changes: 1 addition & 2 deletions openagent/router/routes/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from .chat import router as chat_router
from .agent import router as agent_router
from .model import router as model_router
from .tool import router as tool_router

__all__ = ["chat_router", "agent_router", "model_router", "tool_router"]
__all__ = ["agent_router", "model_router", "tool_router"]
Loading

0 comments on commit 400de79

Please sign in to comment.