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 27, 2023
1 parent ebe0530 commit 73d033c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
22 changes: 19 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,24 @@ 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",
"user": f"Summarize these research paper into a single, short paragraph:\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
11 changes: 11 additions & 0 deletions tests/unit/test_welcome.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,14 @@ 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 prompt["system"] == "You are a science journalist"
assert (
prompt["user"]
== "Summarize these research paper into a single, short paragraph:\n'''* this is abstract\n* second abstract''''"
)

0 comments on commit 73d033c

Please sign in to comment.