ecemumutlu commited on
Commit
f66ecbf
·
1 Parent(s): 57ba66f

Fix endpoint errors

Browse files
Files changed (3) hide show
  1. app.py +6 -1
  2. svc/router.py +11 -3
  3. svc/schemas.py +8 -5
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  from fastapi import FastAPI
2
  from fastapi.middleware.cors import CORSMiddleware
3
  from svc.router import router
@@ -22,4 +23,8 @@ app.include_router(router, prefix="/api")
22
 
23
  @app.get("/")
24
  async def health_check():
25
- return {"status": "healthy"}
 
 
 
 
 
1
+ import uvicorn
2
  from fastapi import FastAPI
3
  from fastapi.middleware.cors import CORSMiddleware
4
  from svc.router import router
 
23
 
24
  @app.get("/")
25
  async def health_check():
26
+ return {"status": "healthy"}
27
+
28
+
29
+ if __name__ == "__main__":
30
+ uvicorn.run(app, host="0.0.0.0", port=8080)
svc/router.py CHANGED
@@ -7,7 +7,7 @@ from fastapi.security import OAuth2PasswordRequestForm
7
  from auth.authentication import get_current_user, create_access_token
8
  from dotenv import load_dotenv
9
  import os
10
-
11
  router = APIRouter()
12
 
13
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
@@ -32,6 +32,7 @@ async def protected_route(username: str = Depends(get_current_user)):
32
  @router.post("/chat", response_model=LMHarnessTaskResponse)
33
  def inference_model(request: LMHarnessTaskRequest, username: str = Depends(get_current_user)):
34
  try:
 
35
  results = evaluator.simple_evaluate(
36
  model=request.model,
37
  model_args=request.model_args,
@@ -45,6 +46,13 @@ def inference_model(request: LMHarnessTaskRequest, username: str = Depends(get_c
45
  except Exception as e:
46
  raise HTTPException(status_code=500, detail=f"lm-harness task execution failed for model: {request.model_args}")
47
 
48
- logger.info(results)
49
- return LMHarnessTaskResponse(results=results)
 
 
 
 
 
 
 
50
 
 
7
  from auth.authentication import get_current_user, create_access_token
8
  from dotenv import load_dotenv
9
  import os
10
+ import json
11
  router = APIRouter()
12
 
13
  logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
 
32
  @router.post("/chat", response_model=LMHarnessTaskResponse)
33
  def inference_model(request: LMHarnessTaskRequest, username: str = Depends(get_current_user)):
34
  try:
35
+ logger.info("Inside")
36
  results = evaluator.simple_evaluate(
37
  model=request.model,
38
  model_args=request.model_args,
 
46
  except Exception as e:
47
  raise HTTPException(status_code=500, detail=f"lm-harness task execution failed for model: {request.model_args}")
48
 
49
+ results["config"]["model_dtype"] = request.precision
50
+ results["config"]["model_name"] = request.model
51
+ results["config"]["model_sha"] = request.model_sha
52
+
53
+ dumped = json.dumps(results, indent=2)
54
+ logger.info("-------------------results------------------\n")
55
+ logger.info(dumped)
56
+ logger.info("-------------------results end------------------\n")
57
+ return LMHarnessTaskResponse(results=dumped)
58
 
svc/schemas.py CHANGED
@@ -1,4 +1,4 @@
1
- from pydantic import BaseModel
2
  from typing import List, Optional, Union, Any
3
 
4
 
@@ -16,14 +16,17 @@ class User(BaseModel):
16
 
17
  class LMHarnessTaskRequest(BaseModel):
18
  model: str
19
- model_args: Optional[Union[str, dict]] = None
20
- tasks: Optional[List[Union[str, dict, object]]] = None
21
  num_fewshot: Optional[int] = None
22
  batch_size: Optional[int] = None
23
  device: Optional[str] = None
24
- limit: Optional[Union[int, float]] = None
25
  write_out: bool = False # Whether to write out an example document and model input, for checking task integrity
 
 
 
26
 
27
 
28
  class LMHarnessTaskResponse(BaseModel):
29
- results: dict[Any,Any]
 
1
+ from pydantic import BaseModel, Json
2
  from typing import List, Optional, Union, Any
3
 
4
 
 
16
 
17
  class LMHarnessTaskRequest(BaseModel):
18
  model: str
19
+ model_args: Optional[str] = None
20
+ tasks: Optional[List[str]] = None
21
  num_fewshot: Optional[int] = None
22
  batch_size: Optional[int] = None
23
  device: Optional[str] = None
24
+ limit: Optional[int] = None
25
  write_out: bool = False # Whether to write out an example document and model input, for checking task integrity
26
+ precision: str
27
+ model_name: str
28
+ model_sha: str
29
 
30
 
31
  class LMHarnessTaskResponse(BaseModel):
32
+ results: Json # dict[Any,Any]