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

Feat: Add endpoints to create concepts with mapping and update visual… #20

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
Loading