Skip to content

Commit

Permalink
Added debugging to edge endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
jrichardson97 committed Mar 6, 2024
1 parent c676dca commit c32d1f8
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ For webapps developed against a local deployment of this service, the `PYTHON_EN
## Redis server
Start server: redis-server --dbfilename aragorn_cache.rdb --dir /home/joeyr/data/kg_summarizer

## API Location
https://kg-summarizer.apps.renci.org/docs

## Todo

22 changes: 16 additions & 6 deletions kg_summarizer/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from starlette.middleware.base import BaseHTTPMiddleware
from typing import Optional
from pydantic import BaseModel
import pathlib
import logging
import kg_summarizer.config as CFG
import json

import kg_summarizer.config as CFG
from kg_summarizer.trapi import EdgeContainer
from kg_summarizer.ai import generate_response
from kg_summarizer.utils import LoggingUtil
Expand Down Expand Up @@ -39,12 +41,13 @@ class EdgeItem(BaseModel):
parameters: Parameters


KG_SUM_VERSION = "0.0.9"
KG_SUM_VERSION = "0.0.10"

# declare the application and populate some details
app = FastAPI(
title="Knowledge Graph Summarizer - A FastAPI UI/web service",
version=KG_SUM_VERSION,
debug=True,
)

app.add_middleware(
Expand Down Expand Up @@ -84,7 +87,14 @@ async def summarize_abstract_handler(item: AbstractItem):

@app.post("/summarize/edge")
async def summarize_edge_handler(item: EdgeItem):
edge = EdgeContainer(item.edge)
if item.edge:
summary = ""
edge = EdgeContainer(item.edge)
else:
summary = f"{50*'*'}\nNo edge passed - loading example\n{50*'*'}\n"
p = pathlib.Path(__file__).parents[1].joinpath("data/edge_david_example.json")
with open(p) as f:
edge = EdgeContainer(json.load(f))

spo_sentence = edge.format_spo_sentence()

Expand All @@ -95,12 +105,12 @@ async def summarize_edge_handler(item: EdgeItem):
Summarize the following edge publication abstracts listed in the knowledge graph. Make sure the summary supports the statement '{spo_sentence}'. Only use information explicitly stated in the publication abstracts. I repeat, do not make up any information.
"""

if edge["edge"]["publications"] or edge["edge"]["sentences"]:
if edge.edge["publications"] or edge.edge["sentences"]:
logger.info(f"GPT Prompt: {system_prompt}")
logger.info(f"GPT Mode: {item.parameters.llm.gpt_model}")
logger.info(f"GPT Temperature: {item.parameters.llm.temperature}")
logger.info(f"GPT Input: {edge}")
summary = generate_response(
summary += generate_response(
system_prompt,
str(edge),
item.parameters.llm.gpt_model,
Expand All @@ -110,7 +120,7 @@ async def summarize_edge_handler(item: EdgeItem):
logger.info(
"Edge contained no publications or sentences. Returning with standarized summary."
)
summary = f"The edge '{spo_sentence}' contains no publications or supporting sentences for an LLM to summarize."
summary += f"The edge '{spo_sentence}' contains no publications or supporting sentences for an LLM to summarize."

logger.info(f"Edge Summary: {summary}")
return summary
10 changes: 6 additions & 4 deletions kg_summarizer/trapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ class GraphContainer:
response: dict
verbose: bool = True
result_idx: int = 0
fetch_pubs: bool = True
graph_type: str = field(init=False) # lookup or creative
sorted_results: list = field(default_factory=list, init=False)
result: dict = field(default_factory=dict, init=False)
Expand Down Expand Up @@ -191,7 +192,7 @@ def set_result(self, idx):
self.result_idx = idx
self.result = self.sorted_results[idx]
self.get_node_info()
self.get_edge_info()
self.get_edge_info(fetch_pubs=self.fetch_pubs)
self.vprint(f"Result: \n{self.result}\n")

def vprint(self, msg):
Expand Down Expand Up @@ -241,9 +242,10 @@ def parse_node_attributes(attr_list_of_dicts, node_norm_name):
node_attr_data["same_as"] = list(set(node_attr_data["same_as"]))

# Fetch publications
node_attr_data["publications"] = get_publications(
node_attr_data["publications"]
)
if self.fetch_pubs:
node_attr_data["publications"] = get_publications(
node_attr_data["publications"]
)

return node_attr_data

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name="kg-summarizer",
version="0.0.9",
version="0.0.10",
author="Joey Richardson",
author_email="[email protected]",
url="https://github.com/jrichardson97/kg-summarizer",
Expand Down

0 comments on commit c32d1f8

Please sign in to comment.