Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,41 @@
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
app = FastAPI()
|
| 4 |
|
| 5 |
@app.post("/")
|
| 6 |
-
def test():
|
| 7 |
-
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
from typing import Tuple, List
|
| 4 |
|
| 5 |
+
class RankingExecInfo:
|
| 6 |
+
def __init__(
|
| 7 |
+
self, prompt, response: str, input_token_count: int, output_token_count: int
|
| 8 |
+
):
|
| 9 |
+
self.prompt = prompt
|
| 10 |
+
self.response = response
|
| 11 |
+
self.input_token_count = input_token_count
|
| 12 |
+
self.output_token_count = output_token_count
|
| 13 |
+
|
| 14 |
+
def __repr__(self):
|
| 15 |
+
return str(self.__dict__)
|
| 16 |
+
|
| 17 |
+
class Result:
|
| 18 |
+
def __init__(
|
| 19 |
+
self,
|
| 20 |
+
query: str,
|
| 21 |
+
hits: List[Dict[str, Any]],
|
| 22 |
+
ranking_exec_summary: Optional[List[RankingExecInfo]] = None,
|
| 23 |
+
):
|
| 24 |
+
self.query = query
|
| 25 |
+
self.hits = hits
|
| 26 |
+
self.ranking_exec_summary = ranking_exec_summary
|
| 27 |
+
|
| 28 |
+
def __repr__(self):
|
| 29 |
+
return str(self.__dict__)
|
| 30 |
+
|
| 31 |
+
class RerankRequest(BaseModel):
|
| 32 |
+
query: str
|
| 33 |
+
hits: List(Tuple(int, str))
|
| 34 |
+
|
| 35 |
app = FastAPI()
|
| 36 |
|
| 37 |
@app.post("/")
|
| 38 |
+
def test(request: RerankRequest):
|
| 39 |
+
hits = request["hits"]
|
| 40 |
+
reranked = sorted(hits, key=lambda x: x[0])
|
| 41 |
+
return {"data": [(i + 1, item[1]) for i, item in enumerate(reranked)]}
|