Spaces:
Sleeping
Sleeping
Upload run.py
Browse files- examples/run.py +44 -0
examples/run.py
ADDED
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import asyncio
|
2 |
+
import os
|
3 |
+
from dotenv import load_dotenv
|
4 |
+
|
5 |
+
from aworld.logs.util import logger
|
6 |
+
from aworld.output import WorkSpace, ArtifactType
|
7 |
+
from aworld.output.observer import on_artifact_create, get_observer
|
8 |
+
|
9 |
+
|
10 |
+
@on_artifact_create
|
11 |
+
async def handle_artifact_create(artifact):
|
12 |
+
logger.info(f"Artifact created: {artifact.artifact_id}")
|
13 |
+
|
14 |
+
|
15 |
+
@on_artifact_create(workspace_id="demo", filters={"artifact_type": "text"})
|
16 |
+
async def handle_specific_artifacts(artifact, **kwargs):
|
17 |
+
logger.info(f"text artifact created in specific workspace {kwargs['workspace_id']}: {artifact.artifact_id}")
|
18 |
+
|
19 |
+
|
20 |
+
class DemoClass:
|
21 |
+
def __init__(self):
|
22 |
+
observer = get_observer()
|
23 |
+
observer.register_create_handler(
|
24 |
+
self.artifact_create,
|
25 |
+
instance=self,
|
26 |
+
workspace_id="demo"
|
27 |
+
)
|
28 |
+
|
29 |
+
async def artifact_create(self, artifact, **kwargs):
|
30 |
+
logger.info(f"DemoClass : text artifact created in specific workspace {kwargs['workspace_id']}: {artifact.artifact_id}")
|
31 |
+
|
32 |
+
async def run():
|
33 |
+
load_dotenv()
|
34 |
+
DemoClass()
|
35 |
+
|
36 |
+
workspace = WorkSpace.from_local_storages(workspace_id="demo")
|
37 |
+
await workspace.create_artifact(ArtifactType.TEXT, "artifact_001", content="123")
|
38 |
+
await workspace.create_artifact(ArtifactType.TEXT, "artifact_001", content="456")
|
39 |
+
await workspace.update_artifact("artifact_001", content="7890")
|
40 |
+
await workspace.mark_as_completed("artifact_001")
|
41 |
+
# await workspace.delete_artifact("artifact_001")
|
42 |
+
|
43 |
+
if __name__ == '__main__':
|
44 |
+
asyncio.run(run())
|