Skip to content

Commit

Permalink
add test_summerize() and implemented summerize()
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantisan committed Sep 28, 2023
1 parent f1a158b commit 1cdb86d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
4 changes: 1 addition & 3 deletions mind_palace/welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
30 changes: 29 additions & 1 deletion tests/unit/test_welcome.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import re

from tests.context import docs
import pytest

from tests.context import docs, extract
from tests.context import welcome as w

from . import test_docs


def test_parse_abstracts():
nodes = [
Expand All @@ -25,3 +29,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

0 comments on commit 1cdb86d

Please sign in to comment.