diff --git a/api/main.py b/api/main.py new file mode 100644 index 0000000000000000000000000000000000000000..50a44372796685eaf9b450612d1887bb75ffca5b --- /dev/null +++ b/api/main.py @@ -0,0 +1,44 @@ +from fastapi import FastAPI, Request + +# from api.optimization import Backend + +DEBUG = True + +app = FastAPI(debug=DEBUG, title="Prompt Optimization Backend") + +# api = Backend(debug=DEBUG) + +def test(): + pass + + +# @app.get("/test") +# async def test_long_operation(request: Request): +# loop = asyncio.get_event_loop() +# result = await loop.run_in_executor(pool, test) +# return "ok" + + +# start optimization +@app.get("/run/{num_iterations}") +async def run(num_iterations: int) -> str: + # api.run_optimization(num_iterations) + return "ok" + + +# TODO turn actions into router and allow to set actions dynamically +# perform optimizer-specific action +@app.get("/action/evolve/") +async def evolve(prompt1: str, prompt2: str) -> str: + return f"This is the evolved prompt taking prompts {prompt1} and {prompt2} into account." + + +# get current genealogy of prompts +@app.get("/family_tree/get") +async def get_family() -> dict: + return dict() + + +@app.get("/") +def main(request: Request) -> str: + return "server running" diff --git a/optimization.py b/optimization.py index 9f18365c07f93fedd8753f5a082bb6dff17e11d0..417c12cbebac486ab0d94bf5c8027c3ac893bb72 100644 --- a/optimization.py +++ b/optimization.py @@ -49,10 +49,9 @@ class PromptOptimization: self._init() def _init(self): - # use caching for evaluation + # family_tree contains the relation of prompts to its parents self.family_tree: dict[str, tuple[str, ...] | None] = {} # all_prompts contains a list of Prompt objects that took part in the optimization - # converting prompts to Prompt object self.all_prompts: dict[str, Prompt] = {} def reset(self):