Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Local Microservice for CheckList in Explainability api #436

Open
wants to merge 4 commits into
base: explainability_api
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Microservice runs test
  • Loading branch information
KhanhThiVo committed Jan 31, 2023
commit bde0866505ceb1c676de1ea7c61388868e8db5c8
13 changes: 0 additions & 13 deletions explainability-api/microservice/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,3 @@ def predict(model_inputs: dict, skill_id: str) -> list:
return model_outputs


# ############ Code from notebook ###################

with open("../checklists/extractive_model_tests.json") as f:
extractive_model_tests = json.load(f)

skills_response = requests.get("https://square.ukp-lab.de/api/skill-manager/skill")
skills = skills_response.json()

query = create_query(skills[-1], extractive_model_tests['tests'])
query_min = query.copy()
query_min['request'] = query_min['request'][:1]

predict(query_min, skills[-1]['id'])
28 changes: 19 additions & 9 deletions explainability-api/microservice/checklist_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,35 @@

router = APIRouter()

# Dev purpose
# Dev purpose hard coded
with open("../checklists/extractive_model_tests.json") as f:
extractive_model_tests = json.load(f)


@router.get('/checklist/{skill_id}', name="run checklist", response_model=List)
def run_checklist(skill_id: str) -> list:
# async def run_checklist(skill_id, test_cases: List = None) -> list:
# test id: '63a6246c2e30fd4c06f7a0be'
try:
skill = requests.get(f'https://square.ukp-lab.de/api/skill-manager/skill/{skill_id}')
@router.get('/')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove this endpoint

def read_root():
return {"Hello": "World"}


@router.get('/checklist/{skill_id}', name="run checklist")
def run_checklist(skill_id: str, n: int = None) -> list:
# tested with this skill_id: 63cdbd06a8b0d566ef20cb54
try:
skill_response = requests.get(f'https://square.ukp-lab.de/api/skill-manager/skill/{skill_id}')
skill = skill_response.json()
skill_id = skill["id"]
skill_type = skill["skill_type"]

test_cases = extractive_model_tests['tests']
model_inputs = checklist.create_query(skill, test_cases)
# get predictions

if n is not None:
model_inputs['request'] = model_inputs["request"][:n] # if all would be too much
else:
model_inputs['request'] = model_inputs["request"] # if all would be too much
model_outputs = checklist.predict(model_inputs, skill_id)
return model_outputs

return model_outputs

except Exception as e:
print(e)