Spaces:
Sleeping
Sleeping
Upload 3 files
Browse files- aworld/cmd/__init__.py +22 -0
- aworld/cmd/cli.py +47 -0
- aworld/cmd/data_model.py +78 -0
aworld/cmd/__init__.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# coding: utf-8
|
| 2 |
+
# Copyright (c) 2025 inclusionAI.
|
| 3 |
+
|
| 4 |
+
from .data_model import (
|
| 5 |
+
BaseAWorldAgent,
|
| 6 |
+
ChatCompletionRequest,
|
| 7 |
+
ChatCompletionResponse,
|
| 8 |
+
ChatCompletionChoice,
|
| 9 |
+
ChatCompletionMessage,
|
| 10 |
+
AgentModel,
|
| 11 |
+
SessionModel,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
__all__ = [
|
| 15 |
+
"BaseAWorldAgent",
|
| 16 |
+
"ChatCompletionRequest",
|
| 17 |
+
"ChatCompletionResponse",
|
| 18 |
+
"ChatCompletionChoice",
|
| 19 |
+
"ChatCompletionMessage",
|
| 20 |
+
"AgentModel",
|
| 21 |
+
"SessionModel",
|
| 22 |
+
]
|
aworld/cmd/cli.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import click
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
@click.group()
|
| 6 |
+
def main(*args, **kwargs):
|
| 7 |
+
print(
|
| 8 |
+
"""\
|
| 9 |
+
AWorld CLI Help:
|
| 10 |
+
aworld web: run aworld web ui server
|
| 11 |
+
aworld api: run aworld api server
|
| 12 |
+
aworld web_legacy: run aworld web agent (legacy), Streamlit Web UI
|
| 13 |
+
aworld help: show help"""
|
| 14 |
+
)
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
@main.command("web")
|
| 18 |
+
@click.option(
|
| 19 |
+
"--port", type=int, default=8000, help="Port to run the AWorld api server"
|
| 20 |
+
)
|
| 21 |
+
@click.argument("args", nargs=-1)
|
| 22 |
+
def main_web(port, args=None, **kwargs):
|
| 23 |
+
from .web import web_server
|
| 24 |
+
web_server.run_server(port, args, **kwargs)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@main.command("api")
|
| 28 |
+
@click.option(
|
| 29 |
+
"--port", type=int, default=8000, help="Port to run the AWorld api server"
|
| 30 |
+
)
|
| 31 |
+
@click.argument("args", nargs=-1)
|
| 32 |
+
def main_api(port, args=None, **kwargs):
|
| 33 |
+
from .web import api_server
|
| 34 |
+
api_server.run_server(port, args, **kwargs)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
@main.command("web_legacy")
|
| 38 |
+
@click.option(
|
| 39 |
+
"--port", type=int, default=8000, help="Port to run the AWorld agent web app"
|
| 40 |
+
)
|
| 41 |
+
@click.argument("args", nargs=-1)
|
| 42 |
+
def main_web_legacy(port, args=None, **kwargs):
|
| 43 |
+
from .web_legacy import web_server
|
| 44 |
+
web_server.run_web_server(port, args, **kwargs)
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|
aworld/cmd/data_model.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import datetime
|
| 2 |
+
import uuid
|
| 3 |
+
from abc import abstractmethod
|
| 4 |
+
from typing import Any, AsyncGenerator, List, Optional
|
| 5 |
+
from pydantic import BaseModel, Field
|
| 6 |
+
|
| 7 |
+
from aworld.output.base import Output
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class ChatCompletionMessage(BaseModel):
|
| 11 |
+
role: str = Field(..., description="The role of the message")
|
| 12 |
+
content: str = Field(..., description="The content of the message")
|
| 13 |
+
trace_id: str = Field(None, description="The trace id")
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class ChatCompletionRequest(BaseModel):
|
| 17 |
+
user_id: str = Field(None, description="The user id")
|
| 18 |
+
session_id: str = Field(
|
| 19 |
+
None,
|
| 20 |
+
description="The session id, if not provided, a new session will be created",
|
| 21 |
+
)
|
| 22 |
+
query_id: str = Field(None, description="The query id")
|
| 23 |
+
trace_id: str = Field(None, description="The trace id")
|
| 24 |
+
model: str = Field(..., description="The model to use")
|
| 25 |
+
messages: List[ChatCompletionMessage] = Field(
|
| 26 |
+
..., description="The messages to send to the agent"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ChatCompletionChoice(BaseModel):
|
| 31 |
+
index: int = 0
|
| 32 |
+
delta: ChatCompletionMessage = Field(
|
| 33 |
+
..., description="The delta message from the agent"
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class ChatCompletionResponse(BaseModel):
|
| 38 |
+
object: str = "chat.completion.chunk"
|
| 39 |
+
id: str = uuid.uuid4().hex
|
| 40 |
+
choices: List[ChatCompletionChoice] = Field(
|
| 41 |
+
..., description="The choices from the agent"
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
class AgentModel(BaseModel):
|
| 46 |
+
id: str = Field(..., description="The agent id")
|
| 47 |
+
name: Optional[str] = Field(None, description="The agent name")
|
| 48 |
+
description: Optional[str] = Field(None, description="The agent description")
|
| 49 |
+
path: str = Field(..., description="The agent path")
|
| 50 |
+
instance: Any = Field(..., description="The agent module instance", exclude=True)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
class BaseAWorldAgent:
|
| 54 |
+
@abstractmethod
|
| 55 |
+
def name(self) -> str:
|
| 56 |
+
pass
|
| 57 |
+
|
| 58 |
+
@abstractmethod
|
| 59 |
+
def description(self) -> str:
|
| 60 |
+
pass
|
| 61 |
+
|
| 62 |
+
@abstractmethod
|
| 63 |
+
async def run(
|
| 64 |
+
self, prompt: str = None, request: ChatCompletionRequest = None
|
| 65 |
+
) -> AsyncGenerator[Output, None]:
|
| 66 |
+
pass
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class SessionModel(BaseModel):
|
| 70 |
+
user_id: str = Field(..., description="The user id")
|
| 71 |
+
session_id: str = Field(..., description="The session id")
|
| 72 |
+
name: str = Field(None, description="The session name")
|
| 73 |
+
description: str = Field(None, description="The session description")
|
| 74 |
+
created_at: datetime.datetime = Field(None, description="The session created at")
|
| 75 |
+
updated_at: datetime.datetime = Field(None, description="The session updated at")
|
| 76 |
+
messages: List[ChatCompletionMessage] = Field(
|
| 77 |
+
None, description="The messages in the session"
|
| 78 |
+
)
|