Skip to content

Commit

Permalink
Adjust openai prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
sawyerh committed Jun 26, 2023
1 parent 2c00ee5 commit e3096e9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
14 changes: 8 additions & 6 deletions notebooks/openai-embeddings/highlights.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,24 +116,26 @@ def search_highlights(query: str):
<hr />
"""

display(Markdown(f"**Key takeaways:**"))
summarize_highlights(md_output)
summarize_highlights(query, md_output)

display(Markdown(f"**Top 10 results for '{query}':**"))
display(Markdown(md_output))


def summarize_highlights(raw_highlights_output: str):
def summarize_highlights(query: str, raw_highlights_output: str):
response = openai.ChatCompletion.create(
messages=[
{
"role": "system",
"content": "You are a helpful assistant that summarizes reading highlights. Given a group highlights by the user, create a list of up to 10 key takeaways. Respond using Markdown syntax. Format each takeaway as a bullet point. At the end of each takeaway, include a link to the original highlight using the following format: [🔗](link url).",
"content": "You are a helpful assistant that summarizes the user's reading highlights from book they've read. Given a user's query and raw output related to the user's query, write a 1-3 sentence introductory response, followed by a list of up to 10 key takeaways. Respond using Markdown syntax. Format the intro as bold text, and format each takeaway as a bullet point. At the end of each takeaway, include link(s) to the original highlight(s) using the following format: [🔗](link url).",
},
{
"role": "user",
"content": f"Query: {query}. Raw output:\n{raw_highlights_output}",
},
{"role": "user", "content": raw_highlights_output},
],
model=GPT_MODEL,
temperature=0,
temperature=0.1,
)

completion = response["choices"][0]["message"]["content"]
Expand Down
8 changes: 5 additions & 3 deletions notebooks/openai-embeddings/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
" ```\n",
" \n",
"1. Follow the instructions in `firebase/README.md` to export the Firestore data to JSON\n",
"1. Add the JSON file to `chroma-embeddings/data/firestore-highlights-export.json`.\n",
"1. Add the JSON file to `data/firestore-highlights-export.json`.\n",
"1. Add a `.env` file to this directory with an `OPENAI_API_KEY`"
]
},
Expand Down Expand Up @@ -93,7 +93,7 @@
"\n",
"Set the `query` variable below with your search. \n",
"\n",
"This query will be turned into its own embedding and then compared to all other embeddings in the database. The results will be sorted by similarity. The closer the distance is to 0, the more similar the embeddings are."
"This query will be turned into its own embedding and then compared to all other embeddings in the database. The results will be sorted by similarity."
]
},
{
Expand All @@ -102,7 +102,9 @@
"metadata": {},
"outputs": [],
"source": [
"query = \"tips for being a team lead\"\n",
"import highlights as utils\n",
"\n",
"query = \"tips for running strong engineering teams\"\n",
"utils.search_highlights(query)"
]
}
Expand Down

1 comment on commit e3096e9

@vercel
Copy link

@vercel vercel bot commented on e3096e9 Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.