ai-agent-book 精选快照(<2MB 代码与文档,来自 github.com/bojieli/ai-agent-book)
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
Build latest book artifacts / build (push) Canceled after 0s
dependency resolution / resolve (3.11) (push) Canceled after 0s
dependency resolution / resolve (3.13) (push) Canceled after 0s
deploy-pages / build (push) Canceled after 0s
deploy-pages / deploy (push) Canceled after 0s
i18n consistency check / check (push) Canceled after 0s
provider adoption tests / test (chapter2/context-compression) (push) Canceled after 0s
provider adoption tests / test (chapter2/prompt-injection) (push) Canceled after 0s
provider adoption tests / test (chapter2/system-hint) (push) Canceled after 0s
provider adoption tests / test (chapter3/log-sanitization) (push) Canceled after 0s
web-search-agent tests / test (push) Canceled after 0s
web-search-agent tests / agentbook (push) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
from aworld.trace.opentelemetry.memory_storage import TraceStorage
|
||||
from aworld.utils.import_package import import_package
|
||||
from aworld.trace.server.util import build_trace_tree
|
||||
|
||||
import_package('fastapi') # noqa
|
||||
from fastapi import FastAPI
|
||||
from fastapi.responses import JSONResponse, RedirectResponse
|
||||
|
||||
app = FastAPI()
|
||||
current_storage = None
|
||||
routes_setup = False
|
||||
|
||||
|
||||
def setup_routes(storage: TraceStorage):
|
||||
global current_storage
|
||||
current_storage = storage
|
||||
|
||||
global routes_setup
|
||||
|
||||
if routes_setup:
|
||||
return app
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
return RedirectResponse("/static/trace_ui.html")
|
||||
|
||||
@app.get('/api/trace/list')
|
||||
async def traces():
|
||||
trace_data = []
|
||||
for trace_id in current_storage.get_all_traces():
|
||||
spans = current_storage.get_all_spans(trace_id)
|
||||
spans_sorted = sorted(spans, key=lambda x: x.start_time)
|
||||
trace_tree = build_trace_tree(spans_sorted)
|
||||
trace_data.append({
|
||||
'trace_id': trace_id,
|
||||
'root_span': trace_tree,
|
||||
})
|
||||
response = {
|
||||
"data": trace_data
|
||||
}
|
||||
return JSONResponse(content=response)
|
||||
|
||||
@app.get('/api/traces/{trace_id}')
|
||||
async def get_trace(trace_id):
|
||||
spans = current_storage.get_all_spans(trace_id)
|
||||
spans_sorted = sorted(spans, key=lambda x: x.start_time)
|
||||
trace_tree = build_trace_tree(spans_sorted)
|
||||
return JSONResponse(content={
|
||||
'trace_id': trace_id,
|
||||
'root_span': trace_tree,
|
||||
})
|
||||
|
||||
routes_setup = True
|
||||
return app
|
||||
Reference in New Issue
Block a user