Skip to content

Commit

Permalink
minor improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
kajarenc committed Mar 26, 2024
1 parent eb1eeaa commit e83e38a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 42 deletions.
36 changes: 29 additions & 7 deletions langgraph_example.ipynb

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion prompt_engineering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"output_parser = StrOutputParser()\n",
"\n",
"chain = prompt | llm | output_parser\n",
"chain.get_graph()\n",
"\n",
"chain.invoke({\"input\": \"Hello I am Karen and who are you?\"})\n"
]
Expand Down
47 changes: 13 additions & 34 deletions rag_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -15,51 +15,41 @@
"\n",
"vectorstore = DocArrayInMemorySearch.from_texts(\n",
" [\n",
" \"Harrison works at Langchain\",\n",
" \"Harrison works at LangChain\",\n",
" \"Karen works at Snowflake\",\n",
" \"Gor works at Microsoft\",\n",
" \"Habet works at AUA\",\n",
" \"Bears like to eat honey\",\n",
" ],\n",
" embedding=OpenAIEmbeddings(),\n",
")\n"
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='Karen works at Snowflake'),\n",
" Document(page_content='Gor works at Microsoft')]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"retriever = vectorstore.as_retriever(search_kwargs={\"k\": 2})\n",
"retriever.invoke(\"Where does Karen work?\")"
"retriever.invoke(\"Where does Habet work?\")"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"template = \"\"\"Answer the question based only on the following context:\n",
"{context}\n",
"\n",
"Question: {question}\n",
"\n",
"Please answer \"I don't know\" if the context is not enough to answer a question.\n",
"\"\"\"\n",
"prompt = ChatPromptTemplate.from_template(template)\n",
"model = ChatOpenAI()\n",
"model = ChatOpenAI(temperature=0)\n",
"output_parser = StrOutputParser()\n",
"\n",
"setup_and_retrieval = RunnableParallel(\n",
Expand All @@ -73,22 +63,11 @@
},
{
"cell_type": "code",
"execution_count": 25,
"execution_count": null,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Bears like to eat honey.'"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"outputs": [],
"source": [
"chain.invoke(\"what bears like to eat?\")"
"chain.invoke(\"what Savva works?\")"
]
},
{
Expand Down

0 comments on commit e83e38a

Please sign in to comment.