Skip to content

Commit

Permalink
feat: initialize agent_ui package
Browse files Browse the repository at this point in the history
  • Loading branch information
shiyu authored and BroKun committed Jul 31, 2024
1 parent a26d249 commit 2eca94a
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 89 deletions.
20 changes: 20 additions & 0 deletions examples/agentuniverse_ui_application.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from agentuniverse.base.agentuniverse import AgentUniverse
from agentuniverse_product.agentuniverse_product import AgentUniverseProduct
import sys

print(sys.path)


class ProductApplication:
"""
Product application.
"""

@classmethod
def start(cls):
AgentUniverse().start()
AgentUniverseProduct().start()


if __name__ == "__main__":
ProductApplication.start()
10 changes: 10 additions & 0 deletions packages/agent_ui/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# python generated files
__pycache__/
*.py[oc]
build/
dist/
wheels/
*.egg-info

# venv
.venv
1 change: 1 addition & 0 deletions packages/agent_ui/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.14
3 changes: 3 additions & 0 deletions packages/agent_ui/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# agent_ui

Describe your project here.
30 changes: 30 additions & 0 deletions packages/agent_ui/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[project]
name = "agent_ui"
version = "0.1.0"
description = "Add your description here"
authors = [
{ name = "shiyu", email = "[email protected]" }
]

packages = [
{ include = "agent_ui" }
]

dependencies = []
readme = "README.md"
requires-python = ">= 3.10"

[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[tool.rye]
managed = true

dev-dependencies = []

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build.targets.wheel]
packages = ["src/agent_ui"]
2 changes: 2 additions & 0 deletions packages/agent_ui/src/agent_ui/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def hello() -> str:
return "Hello from agent_ui!"
32 changes: 32 additions & 0 deletions packages/agent_ui/src/agent_ui/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
from contextlib import asynccontextmanager
import webbrowser
import uvicorn
from agent_ui.routers.main import api_router
import os

PORT = 3000


@asynccontextmanager
async def lifespan(app: FastAPI):
url = f"http://localhost:{PORT}"
webbrowser.open(url)
print(f"Server is running at {url}")
yield
print('finished')

app = FastAPI(lifespan=lifespan)

app.include_router(api_router, prefix='/api/v1')

# 挂载 static 目录,使其可以访问静态文件
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
dist_dir = os.path.join(BASE_DIR, 'dist')
app.mount("/", StaticFiles(directory=dist_dir, html=True), name="dist")


def start_ui_serve():
uvicorn.run("agent_ui.start:app",
host="localhost", port=PORT, reload=True)
6 changes: 6 additions & 0 deletions packages/agent_ui/src/agent_ui/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from agentuniverse.base.agentuniverse import AgentUniverse
from agent_ui.start import start_ui_serve


if __name__ == "__main__":
start_ui_serve()
Empty file.
Empty file.
15 changes: 15 additions & 0 deletions packages/agent_ui/src/agent_ui/routers/demos/router.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from fastapi import APIRouter, HTTPException
# from sqlalchemy.orm import Session
# from fastapi import Depends
# from packages.magent.src.temps.au_agent import RagAgent
# from agentuniverse.base.agentuniverse import AgentUniverse


router = APIRouter()
demos_router = router


@router.get("/detail")
async def get_account_by_id():
print('finish')
return True
7 changes: 7 additions & 0 deletions packages/agent_ui/src/agent_ui/routers/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from fastapi import APIRouter
from .demos.router import demos_router

api_router = APIRouter()

api_router.include_router(
demos_router, prefix="/agentuniverse", tags=["agentuniverse"])
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ dependencies = []
virtual = true

[tool.rye.workspace]
members = ["api"]
members = ["api", "packages/*", "examples/*"]
Loading

0 comments on commit 2eca94a

Please sign in to comment.