Spaces:
Sleeping
Sleeping
Upload models.py
Browse files
AWorld-main/aworlddistributed/aworldspace/db/models.py
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from sqlalchemy import Column, String, Integer, Text, DateTime, JSON, create_engine
|
2 |
+
from sqlalchemy.orm import declarative_base
|
3 |
+
from datetime import datetime
|
4 |
+
from typing import Optional
|
5 |
+
from base import AworldTask, AworldTaskResult
|
6 |
+
|
7 |
+
Base = declarative_base()
|
8 |
+
|
9 |
+
|
10 |
+
class AworldTaskModel(Base):
|
11 |
+
__tablename__ = 'aworld_tasks'
|
12 |
+
|
13 |
+
task_id = Column(String, primary_key=True)
|
14 |
+
agent_id = Column(String)
|
15 |
+
agent_input = Column(Text)
|
16 |
+
session_id = Column(String)
|
17 |
+
user_id = Column(String)
|
18 |
+
llm_provider = Column(String)
|
19 |
+
llm_model_name = Column(String)
|
20 |
+
llm_api_key = Column(String)
|
21 |
+
llm_base_url = Column(String)
|
22 |
+
llm_custom_input = Column(Text)
|
23 |
+
task_system_prompt = Column(Text)
|
24 |
+
mcp_servers = Column(JSON)
|
25 |
+
node_id = Column(String)
|
26 |
+
client_id = Column(String)
|
27 |
+
status = Column(String, default='INIT')
|
28 |
+
history_messages = Column(Integer, default=100)
|
29 |
+
max_steps = Column(Integer, default=100)
|
30 |
+
max_retries = Column(Integer, default=5)
|
31 |
+
ext_info = Column(JSON, default=dict)
|
32 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
33 |
+
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
34 |
+
|
35 |
+
|
36 |
+
class AworldTaskResultModel(Base):
|
37 |
+
__tablename__ = 'aworld_tasks_results'
|
38 |
+
|
39 |
+
task_result_id = Column(Integer, primary_key=True, autoincrement=True)
|
40 |
+
task_id = Column(String)
|
41 |
+
server_host = Column(String)
|
42 |
+
data = Column(JSON)
|
43 |
+
created_at = Column(DateTime, default=datetime.utcnow)
|
44 |
+
|
45 |
+
|
46 |
+
def orm_to_pydantic_task(orm_obj: AworldTaskModel) -> AworldTask:
|
47 |
+
return AworldTask(**{c.name: getattr(orm_obj, c.name) for c in orm_obj.__table__.columns})
|
48 |
+
|
49 |
+
|
50 |
+
def pydantic_to_orm_task(pydantic_obj: AworldTask) -> AworldTaskModel:
|
51 |
+
return AworldTaskModel(**pydantic_obj.model_dump())
|
52 |
+
|
53 |
+
|
54 |
+
def orm_to_pydantic_result(orm_obj: AworldTaskResultModel) -> AworldTaskResult:
|
55 |
+
return AworldTaskResult(
|
56 |
+
server_host=orm_obj.server_host,
|
57 |
+
data=orm_obj.data
|
58 |
+
)
|
59 |
+
|
60 |
+
|
61 |
+
def pydantic_to_orm_result(pydantic_obj: AworldTaskResult) -> AworldTaskResultModel:
|
62 |
+
return AworldTaskResultModel(
|
63 |
+
task_id=pydantic_obj.task.task_id if pydantic_obj.task else None,
|
64 |
+
server_host=pydantic_obj.server_host,
|
65 |
+
data=pydantic_obj.data
|
66 |
+
)
|