37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from fastapi import FastAPI, HTTPException
|
|
from pydantic import BaseModel
|
|
from typing import Any
|
|
import uvicorn
|
|
import json
|
|
|
|
app = FastAPI(
|
|
title="Remember Service",
|
|
description="An OpenAPI-compatible service that allows an LLM to save details by remembering them.",
|
|
version="1.0.0"
|
|
)
|
|
|
|
class RememberRequest(BaseModel):
|
|
"""
|
|
The request model for the remember tool.
|
|
"""
|
|
content: Any
|
|
metadata: dict = {}
|
|
|
|
@app.post("/remember",
|
|
summary="Store information to remember",
|
|
description="Saves the provided content and optional metadata. This endpoint is designed to be called by an LLM as a tool.")
|
|
def remember_endpoint(request: RememberRequest):
|
|
"""
|
|
Endpoint to remember information.
|
|
Prints the received payload to stdout in JSON format.
|
|
"""
|
|
payload = {
|
|
"content": request.content,
|
|
"metadata": request.metadata
|
|
}
|
|
print(json.dumps(payload, indent=2, ensure_ascii=False))
|
|
return {"status": "remembered"}
|
|
|
|
if __name__ == "__main__":
|
|
uvicorn.run(app, host="0.0.0.0", port=8000)
|