-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathinterface.py
More file actions
147 lines (123 loc) · 4.22 KB
/
interface.py
File metadata and controls
147 lines (123 loc) · 4.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from dataclasses import dataclass
from enum import Enum
from typing import Optional, List, Literal, Dict, Any
from pydantic import BaseModel
from virtuals_acp.models import ACPJobPhase, IDeliverable
class AcpOffering(BaseModel):
name: str
price: float
def __str__(self) -> str:
return f"Offering(name={self.name}, price={self.price})"
class AcpJobPhasesDesc(str, Enum):
REQUEST = "request"
NEGOTIATION = "pending_payment"
TRANSACTION = "in_progress"
EVALUATION = "evaluation"
COMPLETED = "completed"
REJECTED = "rejected"
EXPIRED = "expired"
ACP_JOB_PHASE_MAP: Dict[ACPJobPhase, AcpJobPhasesDesc] = {
ACPJobPhase.REQUEST: AcpJobPhasesDesc.REQUEST,
ACPJobPhase.NEGOTIATION: AcpJobPhasesDesc.NEGOTIATION,
ACPJobPhase.TRANSACTION: AcpJobPhasesDesc.TRANSACTION,
ACPJobPhase.EVALUATION: AcpJobPhasesDesc.EVALUATION,
ACPJobPhase.COMPLETED: AcpJobPhasesDesc.COMPLETED,
ACPJobPhase.REJECTED: AcpJobPhasesDesc.REJECTED,
ACPJobPhase.EXPIRED: AcpJobPhasesDesc.EXPIRED,
}
ACP_JOB_PHASE_REVERSE_MAP: Dict[str, ACPJobPhase] = {
"request": ACPJobPhase.REQUEST,
"pending_payment": ACPJobPhase.NEGOTIATION,
"in_progress": ACPJobPhase.TRANSACTION,
"evaluation": ACPJobPhase.EVALUATION,
"completed": ACPJobPhase.COMPLETED,
"rejected": ACPJobPhase.REJECTED,
"expired": ACPJobPhase.EXPIRED,
}
class AcpRequestMemo(BaseModel):
id: int
def __repr__(self) -> str:
return f"Memo(ID: {self.id})"
class ITweet(BaseModel):
type: Literal["buyer", "seller"]
tweet_id: str
content: str
created_at: int
class IAcpJob(BaseModel):
job_id: Optional[int]
client_name: Optional[str]
provider_name: Optional[str]
desc: str
price: str
provider_address: Optional[str]
phase: AcpJobPhasesDesc
memo: List[AcpRequestMemo]
tweet_history: Optional[List[Optional[ITweet]]]
def __repr__(self) -> str:
return (
f"Job ID: {self.job_id}, "
f"Client Name: {self.client_name}, "
f"Provider Name: {self.provider_name}, "
f"Description: {self.desc}, "
f"Price: {self.price}, "
f"Provider Address: {self.provider_address}, "
f"Phase: {self.phase.value}, "
f"Memo: {self.memo}, "
f"Tweet History: {self.tweet_history}"
)
class IInventory(IDeliverable):
job_id: int
client_name: Optional[str]
provider_name: Optional[str]
class AcpJobsSection(BaseModel):
as_a_buyer: List[IAcpJob]
as_a_seller: List[IAcpJob]
def __str__(self) -> str:
buyer_jobs = "\n".join([f"#{i+1} {str(job)}" for i, job in enumerate(self.as_a_buyer)])
seller_jobs = "\n".join([f"#{i+1} {str(job)}" for i, job in enumerate(self.as_a_seller)])
return f"As Buyer:\n{buyer_jobs}\n\nAs Seller:\n{seller_jobs}"
class AcpJobs(BaseModel):
active: AcpJobsSection
completed: List[IAcpJob]
cancelled: List[IAcpJob]
def __str__(self) -> str:
return (
f"💻 Jobs\n"
f"🌕 Active Jobs:\n{self.active}\n"
f"🟢 Completed:\n{self.completed}\n"
f"🔴 Cancelled:\n{self.cancelled}"
)
class AcpInventory(BaseModel):
acquired: List[IInventory]
produced: Optional[List[IInventory]]
def __str__(self) -> str:
return (
f"💼 Inventory\n"
f"Acquired: {self.acquired}\n"
f"Produced: {self.produced}"
)
class AcpState(BaseModel):
inventory: AcpInventory
jobs: AcpJobs
def __str__(self) -> str:
return (
f"🤖 Agent State".center(50, '=') + "\n"
f"{str(self.inventory)}\n"
f"{str(self.jobs)}\n"
f"State End".center(50, '=')
)
def to_serializable_dict(obj: Any) -> Any:
if isinstance(obj, Enum):
return obj.value
elif isinstance(obj, dict):
return {k: to_serializable_dict(v) for k, v in obj.items()}
elif isinstance(obj, list):
return [to_serializable_dict(item) for item in obj]
elif hasattr(obj, "__dict__"):
return {
k: to_serializable_dict(v)
for k, v in vars(obj).items()
if not k.startswith("_")
}
else:
return obj