Skip to content

Commit

Permalink
add new illustration
Browse files Browse the repository at this point in the history
  • Loading branch information
kajarenc committed Mar 28, 2024
1 parent e83e38a commit de6571a
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 27 deletions.
88 changes: 73 additions & 15 deletions langgraph_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@
"<img src=\"agent_loop.png\" width=\"700\"/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<img src=\"simpleagent.png\" width=\"700\"/>"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -37,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -48,7 +55,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -59,7 +66,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -70,7 +77,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'name': 'tavily_search_results_json', 'description': 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.', 'parameters': {'type': 'object', 'properties': {'query': {'description': 'search query to look up', 'type': 'string'}}, 'required': ['query']}}\n"
]
}
],
"source": [
"print(functions[0])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -79,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -134,7 +158,7 @@
},
{
"cell_type": "code",
"execution_count": 47,
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -183,19 +207,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"{'messages': [HumanMessage(content='Who is the current president of the Armenia? Please reverse the name'),\n",
" AIMessage(content='', additional_kwargs={'function_call': {'arguments': '{\"query\":\"current president of Armenia\"}', 'name': 'tavily_search_results_json'}}, response_metadata={'token_usage': {'completion_tokens': 21, 'prompt_tokens': 125, 'total_tokens': 146}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'function_call', 'logprobs': None}),\n",
" FunctionMessage(content='[{\\'url\\': \\'https://en.wikipedia.org/wiki/President_of_Armenia\\', \\'content\\': \\'If the Constitutional Court concludes that there are no grounds for impeaching the president of the Republic the impeachment is removed from the agenda of the National Assembly.\\\\nHealth issues[edit]\\\\nIn case of serious illness of the president of the Republic or other insurmountable obstacles which make it impossible for the President to perform their responsibilities, the National Assembly, upon the recommendation of the Government, the conclusion of the Constitutional Court and with a minimum of two-thirds majority vote of the total number of its members, adopts a decision that states the incapacity of the president of the Republic to discharge their powers. According to Article 111 of the constitution the president is the one who can call a referendum to make amendments in the Constitution of the Republic of Armenia[11]\\\\nThe president of the Republic accepts the resignation of the Government only in one of the following days/cases:\\\\nAfter the acceptance of the resignation of the Government by the president of the Republic the members of the Government continue performing their responsibilities until the new Government is formed.\\\\n In National Assembly\\\\\\'s special session the President should swear the following oath to the people \"Assuming the office of the President of the Republic of Armenia I swear to fulfill the requirements of the Constitution in an unreserved manner, to respect fundamental human and civil rights and freedoms, to ensure the protection, independence, territorial integrity and security of the Republic to the glory of the Republic of Armenia and to the welfare of the people of the Republic of Armenia\".[7]\\\\nConstitutional powers and duties[edit]\\\\n The content of the declaration of Martial Law should include the circumstances that justify the declaration, the justification for the need to declare martial law, the borders of a territory where martial law is declared, forces and means of ensuring the legal regime of martial law, the period of martial law, the date of entry into force of martial law, measures of civil protections and the list of additional commitments that should be done by the citizens of RA and foreign countries, stateless persons and organizations. Roles in the judicial branch[edit]\\\\nThe president of the Republic of Armenia appoints 4 members of the Constitutional Court and, if the National Assembly fails to appoint the president of the Constitutional Court in the period prescribed in Article 83 Clause 1 of the Constitution,[14] appoints the president of the Constitutional Court from among the members of the Constitutional Court.\\\\n\\'}, {\\'url\\': \\'https://www.president.am/en/\\', \\'content\\': \\'26 03, 2024 The President of the Republic received the Ambassador of Greece On the occasion of the Independence Day of Greece, President of the Republic Vahagn Khachaturyan received Ambassador Extraordinary and Plenipotentiary of Greece to Armenia Christos Sofianopoulos. Welcoming the guest, the President, in the person of the Amb assador, congratulated the leadership and people of Greece on ...\\'}]', name='tavily_search_results_json'),\n",
" AIMessage(content='The current president of Armenia is Vahagn Khachaturyan. \\n\\nNow, let\\'s reverse the name \"Vahagn Khachaturyan\".', additional_kwargs={'function_call': {'arguments': '{\"text\":\"Vahagn Khachaturyan\"}', 'name': 'reverse_text'}}, response_metadata={'token_usage': {'completion_tokens': 52, 'prompt_tokens': 765, 'total_tokens': 817}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'function_call', 'logprobs': None}),\n",
" FunctionMessage(content='nayrutahcahK ngahaV', name='reverse_text'),\n",
" AIMessage(content='The reversed name of the current president of Armenia, Vahagn Khachaturyan, is \"nayrutahcahK ngahaV\".', response_metadata={'token_usage': {'completion_tokens': 32, 'prompt_tokens': 838, 'total_tokens': 870}, 'model_name': 'gpt-3.5-turbo', 'system_fingerprint': 'fp_3bc1b5746c', 'finish_reason': 'stop', 'logprobs': None})]}"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain_core.messages import HumanMessage\n",
"\n",
"inputs = {\"messages\": [HumanMessage(content=\"Who is the current president of the Georgia? Please reverse the name\")]}\n",
"inputs = {\"messages\": [HumanMessage(content=\"Who is the current president of the Armenia? Please reverse the name\")]}\n",
"app.invoke(inputs)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -206,9 +246,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 20,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'The reversed name of the current president of Armenia, Vahagn Khachaturyan, is \"nayrutahcahK ngahaV\".'"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain_core.runnables import RunnableLambda\n",
"\n",
Expand All @@ -221,7 +272,7 @@
},
{
"cell_type": "code",
"execution_count": 44,
"execution_count": 21,
"metadata": {},
"outputs": [
{
Expand All @@ -231,7 +282,7 @@
"<IPython.core.display.Image object>"
]
},
"execution_count": 44,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -240,6 +291,13 @@
"from IPython.display import Image\n",
"Image(app.get_graph().draw_png())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
17 changes: 14 additions & 3 deletions prompt_engineering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Hello PyData Yerevan meetup attendees, jan! I hope you are all having a wonderful time exploring the world of data together. Enjoy the discussions and learning opportunities today, jan!'"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain_openai import ChatOpenAI\n",
"from langchain_core.prompts import ChatPromptTemplate\n",
Expand All @@ -30,7 +41,7 @@
"\n",
"chain = prompt | llm | output_parser\n",
"\n",
"chain.invoke({\"input\": \"Hello I am Karen and who are you?\"})\n"
"chain.invoke({\"input\": \"You are on PyData Yerevan meetup, say something to the audience.\"})\n"
]
},
{
Expand Down
50 changes: 41 additions & 9 deletions rag_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,18 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/kjavadyan/projects/PyData-March-Langchain/venv/lib/python3.11/site-packages/pydantic/_migration.py:283: UserWarning: `pydantic.error_wrappers:ValidationError` has been moved to `pydantic:ValidationError`.\n",
" warnings.warn(f'`{import_path}` has been moved to `{new_location}`.')\n"
]
}
],
"source": [
"from langchain_community.vectorstores import DocArrayInMemorySearch\n",
"from langchain_core.output_parsers import StrOutputParser\n",
Expand All @@ -27,17 +36,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"[Document(page_content='Bears like to eat honey'),\n",
" Document(page_content='Habet works at AUA')]"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"retriever = vectorstore.as_retriever(search_kwargs={\"k\": 2})\n",
"retriever.invoke(\"Where does Habet work?\")"
"retriever.invoke(\"Who likes to eat honey?\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -63,11 +84,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"'Gor is working at Microsoft.'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"chain.invoke(\"what Savva works?\")"
"chain.invoke(\"where is Gor working?\")"
]
},
{
Expand Down
Binary file added simpleagent.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit de6571a

Please sign in to comment.