Skip to content
Snippets Groups Projects
Commit aa579769 authored by Max Kimmich's avatar Max Kimmich
Browse files

Add HTTP API endpoints

parent cbd240bc
No related branches found
No related tags found
No related merge requests found
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"
...@@ -49,10 +49,9 @@ class PromptOptimization: ...@@ -49,10 +49,9 @@ class PromptOptimization:
self._init() self._init()
def _init(self): 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] = {} self.family_tree: dict[str, tuple[str, ...] | None] = {}
# all_prompts contains a list of Prompt objects that took part in the optimization # 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] = {} self.all_prompts: dict[str, Prompt] = {}
def reset(self): def reset(self):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment