Skip to content

Commit

Permalink
Merge pull request #20 from SCAI-BIO/improve-api-endpoints
Browse files Browse the repository at this point in the history
Feat: Add endpoints to create concepts with mapping and update visual…
  • Loading branch information
tiadams authored Mar 22, 2024
2 parents bc8162b + a0289f2 commit b30562d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions index/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ def serve_visualization():
return db_plot_html


@app.patch("/visualization", tags=["visualization"])
def update_visualization():
global db_plot_html
db_plot_html = get_html_plot_for_current_database_state(repository)
return {"message": "DB visualization plot has been updated successfully"}


@app.put("/terminologies/{id}", tags=["terminologies"])
async def create_or_update_terminology(id: str, name: str):
try:
Expand All @@ -99,6 +106,22 @@ async def create_or_update_concept(id: str, terminology_id: str, name: str):
raise HTTPException(status_code=400, detail=f"Failed to create or update concept: {str(e)}")


@app.put("/concepts/{id}/mappings", tags=["concepts", "mappings"])
async def create_concept_and_attach_mapping(id: str, terminology_id: str, concept_name: str, text: str):
try:
terminology = repository.session.query(Terminology).filter(Terminology.id == terminology_id).first()
if not terminology:
raise HTTPException(status_code=404, detail=f"Terminology with id {terminology_id} not found")
concept = Concept(terminology=terminology, name=concept_name, id=id)
repository.store(concept)
embedding = embedding_model.get_embedding(text)
mapping = Mapping(concept=concept, text=text, embedding=embedding)
repository.store(mapping)
return {"message": f"Concept {id} created or updated successfully"}
except Exception as e:
raise HTTPException(status_code=400, detail=f"Failed to create or update concept: {str(e)}")


@app.put("/mappings/", tags=["mappings"])
async def create_or_update_mapping(concept_id: str, text: str):
try:
Expand Down
2 changes: 1 addition & 1 deletion index/db/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __init__(self, concept: Concept, text: str, embedding: list) -> object:
self.embedding_json = json.dumps(embedding) # Store embedding as JSON

def __str__(self):
return f"{self.concept_id} : {self.concept.name} | {self.text}"
return f"{self.concept.terminology.name} > {self.concept_id} : {self.concept.name} | {self.text}"

@property
def embedding(self):
Expand Down

0 comments on commit b30562d

Please sign in to comment.