diff --git a/mind_palace/welcome.py b/mind_palace/welcome.py index 964ba74..ff5e13e 100644 --- a/mind_palace/welcome.py +++ b/mind_palace/welcome.py @@ -33,9 +33,7 @@ def summarize(gpt_model, texts: List[str]): ChatMessage(role="user", content=prompt["user"]), ] resp = OpenAI(model=gpt_model).chat(messages) - - # TODO: parse response - return resp + return resp.message.content def get_welcome_message(nodes): diff --git a/tests/unit/test_welcome.py b/tests/unit/test_welcome.py index 9579563..5551ffd 100644 --- a/tests/unit/test_welcome.py +++ b/tests/unit/test_welcome.py @@ -1,8 +1,10 @@ import re -from tests.context import docs +from tests.context import docs, extract from tests.context import welcome as w +from . import test_docs + def test_parse_abstracts(): nodes = [ @@ -25,3 +27,27 @@ def test_summarize_prompt(): assert isinstance(prompt, dict) assert isinstance(prompt["system"], str) assert re.search(r"'''\* this is abstract\n\* second abstract'''", prompt["user"]) + + +@pytest.mark.skip(reason="calls out to OpenAI API and is not free") +def test_summerize(): + nodes = extract.seed_nodes(test_docs.XML_PATH) + abstracts = w.parse_abstracts(nodes) + resp = w.summarize("gpt-3.5-turbo", abstracts) + + # An example response from GPT: + # This collection of papers focuses on the process of sonoporation, which + # involves using ultrasound and microbubbles to temporarily permeate the + # plasma membrane of cells. The papers discuss the mechanistic knowledge of + # sonoporation-induced cellular impact, the spatiotemporal characteristics + # of sonoporation, the disruption of the actin cytoskeleton during + # sonoporation, the role of membrane blebbing in cell recovery, the cellular + # impact of sonoporation on living cells, the properties of daughter bubbles + # created during inertial cavitation, and the dynamics of membrane + # perforation and resealing during sonoporation. These findings provide + # valuable insights into the potential applications and optimization of + # sonoporation as a drug and gene delivery technique. + + assert resp.startswith("This collection of papers") + assert len(resp.split()) < 200 + assert "sonoporation" in resp