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 2b700f1
Show file tree
Hide file tree
Showing 2 changed files with 28 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
28 changes: 27 additions & 1 deletion tests/unit/test_welcome.py
Original file line number Diff line number Diff line change
@@ -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 = [
Expand All @@ -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")

Check failure on line 32 in tests/unit/test_welcome.py

View workflow job for this annotation

GitHub Actions / build (3.11)

Ruff (F821)

tests/unit/test_welcome.py:32:2: F821 Undefined name `pytest`
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 2b700f1

Please sign in to comment.