Skip to content

Commit

Permalink
scaffolded welcome.summarize_prompt()
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantisan committed Sep 28, 2023
1 parent 4cfa30b commit f1a158b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
27 changes: 24 additions & 3 deletions mind_palace/welcome.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import List

from docs import Section
from llama_index.llms import ChatMessage, OpenAI


def parse_abstracts(nodes) -> List[str]:
Expand All @@ -12,9 +13,29 @@ def parse_abstracts(nodes) -> List[str]:
]


def summarize(texts):
# TODO:
return
def summarize_prompt(abstracts: List[str]):
bullet_points = "\n".join([f"* {text}" for text in abstracts])
return {
"system": (
"You are a science journalist summarizing papers for your readers.\n"
"Instructions:\n"
"respond with fewer than 100 words\n"
"start your response with 'This collection of papers'"
),
"user": f"Summarize these research papers:\n'''{bullet_points}'''",
}


def summarize(gpt_model, texts: List[str]):
prompt = summarize_prompt(texts)
messages = [
ChatMessage(role="system", content=prompt["system"]),
ChatMessage(role="user", content=prompt["user"]),
]
resp = OpenAI(model=gpt_model).chat(messages)

# TODO: parse response
return resp


def get_welcome_message(nodes):
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_welcome.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

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

Expand All @@ -15,3 +17,11 @@ def test_parse_abstracts():
assert len(abstracts) == 1
assert isinstance(abstracts, list)
assert all(isinstance(abstract, str) for abstract in abstracts)


def test_summarize_prompt():
abstracts = ["this is abstract", "second abstract"]
prompt = w.summarize_prompt(abstracts)
assert isinstance(prompt, dict)
assert isinstance(prompt["system"], str)
assert re.search(r"'''\* this is abstract\n\* second abstract'''", prompt["user"])

0 comments on commit f1a158b

Please sign in to comment.