Skip to content

Commit

Permalink
graphreader wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasonjo committed Sep 19, 2024
1 parent 9049226 commit bbf26bd
Showing 1 changed file with 46 additions and 66 deletions.
112 changes: 46 additions & 66 deletions graphreader/graphreader_langgraph.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,19 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 17,
"id": "26942568-7ae9-426b-9237-3f53bd76e0a5",
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "f-string: unmatched '(' (2322120112.py, line 71)",
"output_type": "error",
"traceback": [
"\u001b[0;36m Cell \u001b[0;32mIn[17], line 71\u001b[0;36m\u001b[0m\n\u001b[0;31m response = {\"chosen_action\": chosen_action.get(\"function_name\"), \"neighbor_check_queue\": [], \"previous_actions\": [f\"neighbor_select({chosen_action.get(\"arguments\", [])[0]})\"]}\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m f-string: unmatched '('\n"
]
}
],
"source": [
"neighbor_select_system_prompt = \"\"\"\n",
"As an intelligent assistant, your primary objective is to answer questions based on information\n",
Expand Down Expand Up @@ -602,7 +611,7 @@
" chosen_action = parse_function(neighbor_select_results.chosen_action)\n",
" print(f\"Chosen action: {chosen_action}\")\n",
" # Empty neighbor select queue\n",
" response = {\"chosen_action\": chosen_action.get(\"function_name\"), \"neighbor_check_queue\": [], \"previous_actions\": [\"neighbor_select\"]}\n",
" response = {\"chosen_action\": chosen_action.get(\"function_name\"), \"neighbor_check_queue\": [], \"previous_actions\": [f\"neighbor_select({chosen_action.get(\"arguments\", [])[0]})\"]}\n",
" if chosen_action.get(\"function_name\") == \"read_neighbor_node\":\n",
" response[\"check_atomic_facts_queue\"] = [chosen_action.get(\"arguments\")[0]]\n",
" return response\n",
Expand All @@ -611,7 +620,7 @@
},
{
"cell_type": "code",
"execution_count": 11,
"execution_count": 18,
"id": "71098d92-8abc-4851-b491-bd36db1e8f71",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -688,7 +697,7 @@
},
{
"cell_type": "code",
"execution_count": 12,
"execution_count": 19,
"id": "c7b57214-a6db-4bf9-8616-4f1dd3ceac11",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -722,7 +731,7 @@
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 20,
"id": "1e37d7ba-2847-42c8-9f68-20cc517334d2",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -771,7 +780,7 @@
},
{
"cell_type": "code",
"execution_count": 14,
"execution_count": 21,
"id": "e22c45f8-1f41-4e0a-a921-9b3f51b7adc6",
"metadata": {},
"outputs": [
Expand All @@ -781,15 +790,19 @@
"text": [
"--------------------\n",
"Step: rational_plan\n",
"Rational plan: To answer this question, I need to find information on the specific battles Joan of Arc participated in during her military career and determine whether she experienced any defeats in those battles. This involves identifying the battles she was involved in and checking the outcomes of each.\n",
"Rational plan: To answer the question of whether Joan of Arc lost any battles, the plan involves:\n",
"\n",
"1. Identifying the major battles in which Joan of Arc participated.\n",
"2. Determining the outcomes of these battles (whether they were victories or defeats).\n",
"3. Summarizing the findings to establish if Joan of Arc experienced any losses during her military campaigns.\n",
"--------------------\n",
"Step: atomic_fact_check\n",
"Reading atomic facts about: ['defeats', 'Joan of Arc', 'siege of Orléans', 'Loire Campaign', 'battle']\n",
"Rational for next action after atomic check: To further confirm and detail the battles Joan of Arc lost, reading the text chunk that contains these atomic facts will provide more comprehensive information.\n",
"Reading atomic facts about: ['Joan of Arc', 'battle', 'victories', 'defeats', 'siege of Orléans']\n",
"Rational for next action after atomic check: Read more detailed information from the text chunks to confirm and elaborate on the outcomes of these battles.\n",
"Chosen action: {'function_name': 'read_chunk', 'arguments': [['3feaa3f3137a5f839bfc207bc5c2ffdb']]}\n",
"--------------------\n",
"Step: read chunk(3feaa3f3137a5f839bfc207bc5c2ffdb)\n",
"Rational for next action after reading chunks: The current text chunk confirms that Joan of Arc did indeed lose some battles, specifically mentioning her participation in the unsuccessful sieges of Paris and La Charité. This information directly answers the question.\n",
"Rational for next action after reading chunks: The current text chunk confirms that Joan of Arc faced defeats in battles such as the unsuccessful sieges of Paris and La Charité. This information directly answers the question about whether Joan of Arc lost any battles. Therefore, no further information is necessary to address the query.\n",
"Chosen action: {'function_name': 'termination', 'arguments': []}\n",
"--------------------\n",
"Step: Answer Reasoning\n"
Expand All @@ -799,15 +812,15 @@
"data": {
"text/plain": [
"{'answer': 'Yes, Joan of Arc did lose some battles, including the sieges of Paris and La Charité.',\n",
" 'analysis': 'The notebook content indicates that Joan of Arc participated in multiple battles and sieges, achieving successes like the siege of Orléans and the Loire Campaign. However, it also mentions her defeats, specifically pointing out the unsuccessful sieges of Paris and La Charité.',\n",
" 'analysis': 'The notebook content indicates that Joan of Arc participated in multiple battles, including successful ones like the siege of Orléans and the Loire Campaign. However, it also mentions that she faced defeats in other battles, specifically the unsuccessful sieges of Paris and La Charité.',\n",
" 'previous_actions': ['rational_plan',\n",
" 'initial_node_selection',\n",
" \"atomic_fact_check(['defeats', 'Joan of Arc', 'siege of Orléans', 'Loire Campaign', 'battle'])\",\n",
" \"atomic_fact_check(['Joan of Arc', 'battle', 'victories', 'defeats', 'siege of Orléans'])\",\n",
" 'read_chunks(3feaa3f3137a5f839bfc207bc5c2ffdb)',\n",
" 'answer_reasoning']}"
]
},
"execution_count": 14,
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -818,7 +831,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 22,
"id": "6f41c1ab-7973-4e20-888a-2be5c94475a4",
"metadata": {},
"outputs": [
Expand All @@ -828,17 +841,17 @@
"text": [
"--------------------\n",
"Step: rational_plan\n",
"Rational plan: To answer the question about the current weather in Spain, we need to access real-time weather data or forecasts from a reliable meteorological source, such as a weather website or application that provides updated information on temperature, precipitation, and other relevant weather conditions across different regions of Spain.\n",
"Rational plan: To answer the question about the current weather in Spain, we need to access real-time weather data or forecasts from a reliable meteorological source for various locations within Spain. This includes information on temperature, precipitation, humidity, and wind conditions.\n",
"--------------------\n",
"Step: atomic_fact_check\n",
"Reading atomic facts about: ['Spain']\n",
"Rational for next action after atomic check: Since there are no atomic facts provided in this step, it indicates that the current node might not contain relevant information regarding the current weather in Spain.\n",
"Reading atomic facts about: ['Spain', 'weather', 'real-time weather data', 'meteorological source', 'temperature']\n",
"Rational for next action after atomic check: Since there are no atomic facts related to the weather in Spain, it's necessary to explore neighboring nodes that might contain relevant information.\n",
"Chosen action: {'function_name': 'stop_and_read_neighbor', 'arguments': []}\n",
"Key elements: ['Spain']\n",
"Key elements: ['Spain', 'weather', 'real-time weather data', 'meteorological source', 'temperature']\n",
"--------------------\n",
"Step: neighbor select\n",
"Possible candidates: [{'possible_candidates': []}]\n",
"Rational for next action after selecting neighbor: Since the neighbor nodes list is empty, there are no further nodes to explore that could provide information relevant to the current question about the weather in Spain.\n",
"Rational for next action after selecting neighbor: Since there are no possible candidates in the neighbor nodes that could provide information about the current weather in Spain, and the notebook confirms no relevant atomic facts are available, we should conclude the search.\n",
"Chosen action: {'function_name': 'termination', 'arguments': []}\n",
"--------------------\n",
"Step: Answer Reasoning\n"
Expand All @@ -847,16 +860,16 @@
{
"data": {
"text/plain": [
"{'answer': 'I cannot provide the current weather in Spain directly. Please check a reliable weather website or application for the most accurate and up-to-date information.',\n",
" 'analysis': 'The notebook content indicates that to determine the current weather in Spain, one must access real-time data from a reliable meteorological source. This suggests that the information cannot be directly provided here without accessing updated weather services.',\n",
"{'answer': 'Currently, there is no available information about the weather in Spain.',\n",
" 'analysis': 'The notebook indicates that there are no relevant atomic facts available regarding the weather in Spain.',\n",
" 'previous_actions': ['rational_plan',\n",
" 'initial_node_selection',\n",
" \"atomic_fact_check(['Spain'])\",\n",
" \"atomic_fact_check(['Spain', 'weather', 'real-time weather data', 'meteorological source', 'temperature'])\",\n",
" 'neighbor_select',\n",
" 'answer_reasoning']}"
]
},
"execution_count": 15,
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -867,7 +880,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 23,
"id": "21900334-d1dc-4761-a576-61c4569f920e",
"metadata": {},
"outputs": [
Expand All @@ -877,43 +890,15 @@
"text": [
"--------------------\n",
"Step: rational_plan\n",
"Rational plan: To answer this question, we need to identify the cities Joan of Arc visited during her early life and then determine if any of these cities were locations where she won battles later in her life. We should look for information about her early life, including her place of birth and any travels she might have undertaken before becoming actively involved in military campaigns. Additionally, we need to compile a list of battles Joan of Arc participated in and the cities associated with these battles. By comparing these two lists, we can determine if there is any overlap.\n",
"Rational plan: To answer this question, we first need to identify the cities that Joan of Arc visited during her early life. Next, we need to list the cities where she won battles. Finally, we will compare these two lists to see if there are any cities that appear on both, indicating that she visited them in her early life and also won battles there later.\n",
"--------------------\n",
"Step: atomic_fact_check\n",
"Reading atomic facts about: ['Joan of Arc', 'young Joan', 'Orléans', 'Loire Campaign', 'siege of Orléans']\n",
"Rational for next action after atomic check: Review the text chunks to find more detailed information about the cities Joan visited during her early life and the battles she fought in those cities.\n",
"Reading atomic facts about: ['Joan of Arc', 'young Joan', 'Orléans', 'siege of Orléans', 'Loire Campaign']\n",
"Rational for next action after atomic check: Continue to identify other cities Joan of Arc visited in her early life and where she won battles to see if there are more matches.\n",
"Chosen action: {'function_name': 'read_chunk', 'arguments': [['3feaa3f3137a5f839bfc207bc5c2ffdb']]}\n",
"--------------------\n",
"Step: read chunk(3feaa3f3137a5f839bfc207bc5c2ffdb)\n",
"Rational for next action after reading chunks: We have detailed information about Joan's involvement in various battles and her early life, including her birthplace and initial travels to meet Charles VII. However, we still need to determine if any of the cities she visited early in her life were later battle sites. We should search for more specific information about her early travels and any other cities she might have visited before her military involvement.\n",
"Chosen action: {'function_name': 'search_more', 'arguments': []}\n",
"Neighbor rational: We have detailed information about Joan's involvement in various battles and her early life, including her birthplace and initial travels to meet Charles VII. However, we still need to determine if any of the cities she visited early in her life were later battle sites. We should search for more specific information about her early travels and any other cities she might have visited before her military involvement.\n",
"--------------------\n",
"Step: neighbor select\n",
"Possible candidates: ['Joan of Arc', 'The Messenger: The Story of Joan of Arc', 'Charles VII', 'young Joan', 'French war heroine', 'Joan', \"Joan's trial\", 'The Passion of Joan of Arc', 'siege of Orléans', \"Charles VII's coronation\", 'Hundred Years War', 'Loire Campaign', \"Hundred Years' War\", 'French army', 'King of France', 'Burgundian troops', 'French allies', 'Orléans', 'Burgundians', 'Archbishop of Paris', 'Compiègne', 'Saint Catherine', 'French morale', 'early 1430', 'battle', 'French nationalists', 'Bishop Pierre Cauchon', 'French Revolution', 'Rouen prison', 'northeast France', 'save France', 'French nation', 'French silent historical film', 'Saint Margaret', 'Paris', 'France', 'siege', 'French', 'Renée Jeanne Falconetti', 'unsuccessful siege', 'failed siege', 'La Charité', 'September 1429', 'military leader', 'religious martyr', 'medieval architecture', 'April 1429', 'English atrocities', 'Reims', 'birth']\n",
"Rational for next action after selecting neighbor: To find out if Joan of Arc visited any cities in her early life where she later won battles, we need to explore nodes related to her early life travels and the cities she visited before becoming actively involved in military campaigns. The node 'birth' might provide information about her early life locations, which is crucial to answer the question.\n",
"Chosen action: {'function_name': 'read_neighbor_node', 'arguments': ['birth']}\n",
"--------------------\n",
"Step: atomic_fact_check\n",
"Reading atomic facts about: ['birth']\n",
"Rational for next action after atomic check: stop_and_read_neighbor\n",
"Chosen action: {'function_name': 'stop_and_read_neighbor', 'arguments': []}\n",
"Key elements: ['birth']\n",
"--------------------\n",
"Step: neighbor select\n",
"Possible candidates: [{'possible_candidates': ['Joan of Arc', 'propertied peasant family', 'Domrémy', 'northeast France']}]\n",
"Rational for next action after selecting neighbor: To determine if Joan of Arc visited any cities in her early life where she later won battles, we need to explore more about her early life, specifically her travels and activities before she became involved in military campaigns. The neighbor node 'Domrémy' is directly related to her place of birth and may provide insights into her early life travels or experiences.\n",
"Chosen action: {'function_name': 'read_neighbor_node', 'arguments': ['Domrémy']}\n",
"--------------------\n",
"Step: atomic_fact_check\n",
"Reading atomic facts about: ['Domrémy']\n",
"Rational for next action after atomic check: stop_and_read_neighbor\n",
"Chosen action: {'function_name': 'stop_and_read_neighbor', 'arguments': []}\n",
"Key elements: ['Domrémy']\n",
"--------------------\n",
"Step: neighbor select\n",
"Possible candidates: [{'possible_candidates': ['Joan of Arc', 'birth', 'propertied peasant family', 'northeast France']}]\n",
"Rational for next action after selecting neighbor: Since we have already explored the nodes related to Joan of Arc's birth and early life in Domrémy, and we have gathered information about the battles she participated in, the next logical step is to determine if any of these battles occurred in cities she visited during her early life. However, none of the current neighboring nodes ('propertied peasant family', 'northeast France') seem relevant to answering the specific question about cities visited in her early life where she later won battles. Therefore, we should terminate the search as we have sufficient information to conclude that there is no overlap between her early life visits and battle locations based on the explored data.\n",
"Rational for next action after reading chunks: The current chunk confirms that Joan of Arc visited Orléans during her early life and later won a battle there. This information directly answers the question posed. No further information is needed from other chunks as the question specifically asks about cities visited in early life where battles were later won, and Orléans fits this description.\n",
"Chosen action: {'function_name': 'termination', 'arguments': []}\n",
"--------------------\n",
"Step: Answer Reasoning\n"
Expand All @@ -922,21 +907,16 @@
{
"data": {
"text/plain": [
"{'answer': 'No, Joan of Arc did not visit any cities in her early life where she won battles later. Her early life was spent in Domrémy, and she only visited cities such as Orléans, Paris, La Charité, and Compiègne during her military campaigns.',\n",
" 'analysis': \"The notebook content provides detailed information about Joan of Arc's early life and her military engagements. It mentions that Joan was born in Domrémy, northeast France, and later participated in several key battles and sieges, including Orléans, Paris, La Charité, and a relief effort for Compiègne. However, there is no mention of her visiting any of these cities before she began her military campaigns. The only location connected to her early life before her visions and military involvement is Domrémy.\",\n",
"{'answer': 'Yes, Joan of Arc visited Orléans in her early life where she later won a battle.',\n",
" 'analysis': 'The notebook content confirms that Joan of Arc visited Orléans during her early life and later won a battle there, leading to the lifting of the siege in April 1429. This information is consistent and repeated, indicating its reliability.',\n",
" 'previous_actions': ['rational_plan',\n",
" 'initial_node_selection',\n",
" \"atomic_fact_check(['Joan of Arc', 'young Joan', 'Orléans', 'Loire Campaign', 'siege of Orléans'])\",\n",
" \"atomic_fact_check(['Joan of Arc', 'young Joan', 'Orléans', 'siege of Orléans', 'Loire Campaign'])\",\n",
" 'read_chunks(3feaa3f3137a5f839bfc207bc5c2ffdb)',\n",
" 'neighbor_select',\n",
" \"atomic_fact_check(['birth'])\",\n",
" 'neighbor_select',\n",
" \"atomic_fact_check(['Domrémy'])\",\n",
" 'neighbor_select',\n",
" 'answer_reasoning']}"
]
},
"execution_count": 16,
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit bbf26bd

Please sign in to comment.