From b90bc7b5cde549d55217d7427f18921c55ae75d7 Mon Sep 17 00:00:00 2001 From: PhilOutram Date: Tue, 16 Apr 2024 19:25:54 +0100 Subject: [PATCH] Fnc to interrogate model and return body text --- notebooks/api_test_po.ipynb | 414 ++++++++++++++++++++++++++++++++++++ 1 file changed, 414 insertions(+) create mode 100644 notebooks/api_test_po.ipynb diff --git a/notebooks/api_test_po.ipynb b/notebooks/api_test_po.ipynb new file mode 100644 index 0000000..5ec38e4 --- /dev/null +++ b/notebooks/api_test_po.ipynb @@ -0,0 +1,414 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "project_path = \"C:/Users/phil_/OneDrive/Coding/AI Hackathon - Apr 24\\meetings-capture-hackathon\"\n", + "data = \"/data/Sample Transcript - US Dept Commerce.txt\"\n", + "API_KEY = \"0pYnnTGEMsaridRPl07Jc9UgeqHNt2iqavwLHZdl\"\n", + "URL = \"https://nlic9bgao1.execute-api.us-east-1.amazonaws.com/api\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Open the file in read mode\n", + "with open(project_path+data, 'r') as file:\n", + " # Read the contents of the file\n", + " input_transcript = file.read()\n", + "\n", + "# Print the contents of the file\n", + "print(input_transcript)\n", + "\n", + "# input_transcript = pd.read(project_path+data)\n", + "\n", + "#df.head\n", + "\n", + "#https://aws-samples.github.io/bedrock-claude-chat/#tag/published_api/operation/post_message_conversation_post" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# df[\"transcript\"] = df.apply(\n", + "# lambda row: \", \".join(\n", + "# [str(row[col]).strip() for col in [\"Time\", \"Speaker\", \"Text\"]]\n", + "# ),\n", + "# axis=1,\n", + "# )\n", + "\n", + "# formatted = '\\n '.join(df[\"transcript\"])\n", + "\n", + "# formatted = \"Style: style1, Transcript:\" + formatted\n", + "\n", + "# print(formatted)\n", + "\n", + "print(input_transcript)" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "import requests\n", + "import json\n", + "import base64\n", + "import time" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'conversationId': '01HVM2BPR83FB9DK4ANG6BHNVC', 'messageId': '01HVM2BPR8P4850F15FWFBS5HY'}\n" + ] + } + ], + "source": [ + "data = {\n", + " \"message\": {\n", + " \n", + " \"content\": [\n", + " {\n", + " \"contentType\": \"text\",\n", + " \"mediaType\": \"string\",\n", + " \"body\": \"what does EI stand for?\"\n", + " }\n", + " ],\n", + " \"model\": \"claude-v3-sonnet\"\n", + " }\n", + " }\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json\",\n", + " \"X-API-Key\": f\"{API_KEY}\",\n", + " }\n", + "response = requests.post(URL+ \"/conversation\", json=data, headers=headers)\n", + "print(response.json())\n", + "json_respn = response.json()\n", + "\n", + "\n", + "headers = {\n", + " \"Content-Type\": \"application/json\",\n", + " \"X-API-Key\": f\"{API_KEY}\",\n", + " }\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [], + "source": [ + "def GetBodyText(input_url, input_conversation_id):\n", + " \"\"\"\n", + " Manipulate the input string based on the given number.\n", + "\n", + " Args:\n", + " input_string (str): The input string.\n", + " number (int): The number used for manipulation.\n", + "\n", + " Returns:\n", + " str: The manipulated string.\n", + " \"\"\" \n", + " output_ok = False\n", + "\n", + " # Start the while loop with the boolean condition\n", + " while not output_ok:\n", + " # Do something inside the loop\n", + " print(\"Checking output...\")\n", + " # Wait for 1 second\n", + " time.sleep(1)\n", + "\n", + " get_url = input_url + \"/conversation/\" + input_conversation_id \n", + " get = requests.get(\n", + " get_url, \n", + " headers=headers,\n", + " )\n", + "\n", + " output_json = get.json()\n", + "\n", + " # Check if the substring is present in the string\n", + " if 'errors' in output_json:\n", + " print(\"...output false\")\n", + " else: \n", + " print(\"...output true\")\n", + " output_ok = True\n", + " print(output_json)\n", + "\n", + " # Extract the body text\n", + " last_msg_id = output_json[\"lastMessageId\"]\n", + " return output_json[\"messageMap\"][last_msg_id][\"content\"][0][\"body\"]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Checking output...\n", + "...output false\n", + "Checking output...\n", + "...output true\n", + "{'id': '01HVM2BPR83FB9DK4ANG6BHNVC', 'title': 'New conversation', 'createTime': 1713291778954.0, 'messageMap': {'system': {'role': 'system', 'content': [{'contentType': 'text', 'mediaType': None, 'body': ''}], 'model': 'claude-v3-sonnet', 'children': ['01HVM2BPR8P4850F15FWFBS5HY'], 'parent': None}, '01HVM2BPR8P4850F15FWFBS5HY': {'role': 'user', 'content': [{'contentType': 'text', 'mediaType': 'string', 'body': 'what does EI stand for?'}], 'model': 'claude-v3-sonnet', 'children': ['01HVM2BWAE8WW66AS2X2G6WM0S'], 'parent': 'system'}, '01HVM2BWAE8WW66AS2X2G6WM0S': {'role': 'assistant', 'content': [{'contentType': 'text', 'mediaType': None, 'body': 'EI typically stands for \"emotional intelligence.\"\\n\\nEmotional intelligence refers to the ability to understand, manage, and reason about one\\'s own emotions and the emotions of others. It includes skills like:\\n\\n- Self-awareness - recognizing one\\'s own emotions and how they affect thoughts and behaviors.\\n\\n- Self-regulation - controlling disruptive emotions and impulses.\\n\\n- Motivation - using emotions to achieve goals.\\n\\n- Empathy - understanding the emotions of others.\\n\\n- Social skills - managing relationships and building networks.\\n\\nThe term \"emotional intelligence\" was popularized by psychologists like John Mayer, Peter Salovey, and Daniel Goleman in the 1990s. It has become an important concept in fields like psychology, business, education, and interpersonal relationships.'}], 'model': 'claude-v3-sonnet', 'children': [], 'parent': '01HVM2BPR8P4850F15FWFBS5HY'}}, 'lastMessageId': '01HVM2BWAE8WW66AS2X2G6WM0S', 'botId': '01HVKNBE4W2P7P3HG805X0FQNV'}\n", + "body text is...\n", + "EI typically stands for \"emotional intelligence.\"\n", + "\n", + "Emotional intelligence refers to the ability to understand, manage, and reason about one's own emotions and the emotions of others. It includes skills like:\n", + "\n", + "- Self-awareness - recognizing one's own emotions and how they affect thoughts and behaviors.\n", + "\n", + "- Self-regulation - controlling disruptive emotions and impulses.\n", + "\n", + "- Motivation - using emotions to achieve goals.\n", + "\n", + "- Empathy - understanding the emotions of others.\n", + "\n", + "- Social skills - managing relationships and building networks.\n", + "\n", + "The term \"emotional intelligence\" was popularized by psychologists like John Mayer, Peter Salovey, and Daniel Goleman in the 1990s. It has become an important concept in fields like psychology, business, education, and interpersonal relationships.\n" + ] + } + ], + "source": [ + "body_text = GetBodyText(URL, json_respn['conversationId'])\n", + "print(\"body text is...\")\n", + "print(body_text)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Checking output...\n", + "output true\n", + "01HVM0D5CTZ7RA00F0BY634YP4\n", + "conversationId\n", + "Here are some steps I would recommend for using AI to fact-check statements made in government meetings:\n", + "\n", + "1. Transcribe the meeting audio or text into a plain text document. This will allow you to easily process the content with AI tools.\n", + "\n", + "2. Use a named entity recognition (NER) model to identify statements in the text that are factual claims about entities like people, organizations, locations, dates, statistics etc.\n", + "\n", + "3. For each factual claim identified, use a search engine or fact-checking database to try to find authoritative sources that either confirm or refute the claim.\n", + "\n", + "4. Evaluate the sources found - their reliability, recency, and whether they directly address the claim made. Prioritize highly reputable sources like government data, scientific studies, etc.\n", + "\n", + "5. For claims you cannot find good evidence for or against, mark them as unverified.\n", + "\n", + "6. Compile your findings into a report listing the factual claims made, the evidence found for or against each one, and your assessment of their accuracy.\n", + "\n", + "7. Use a language model like myself to help rephrase the claims or find alternative ways to express them when needed for clarity.\n", + "\n", + "The key is leveraging AI's ability to quickly process and search large amounts of text data, while applying human judgment to evaluate the quality of evidence found. Let me know if you need any other specific advice as you go through this process.\n" + ] + } + ], + "source": [ + "output_ok = False\n", + "\n", + "# Start the while loop with the boolean condition\n", + "while not output_ok:\n", + " # Do something inside the loop\n", + " print(\"Checking output...\")\n", + " # Wait for 1 second\n", + " time.sleep(1)\n", + "\n", + " get_url = URL + \"/conversation/\" + json_respn['conversationId'] \n", + " get = requests.get(\n", + " get_url, \n", + " headers=headers,\n", + " )\n", + "\n", + " output_json = get.json()\n", + "\n", + " # Check if the substring is present in the string\n", + " if \"No conversation found with id\" in output_json:\n", + " print(\"output false\")\n", + " else: \n", + " print(\"output true\")\n", + " output_ok = True\n", + "\n", + "# Parse JSON\n", + "# data = json.loads(output_json)\n", + "\n", + "print(json_respn['conversationId']) \n", + "print('conversationId')\n", + "\n", + "# Extract the body text\n", + "last_msg_id = output_json[\"lastMessageId\"]\n", + "body_text = output_json[\"messageMap\"][last_msg_id][\"content\"][0][\"body\"]\n", + "# body_text = data[\"messageMap\"]['conversationId'][\"content\"][0][\"body\"]\n", + "\n", + "print(body_text)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '01HVKZMH9KVJ2SDSAQZZTVXNKC',\n", + " 'title': 'New conversation',\n", + " 'createTime': 1713288922495.0,\n", + " 'messageMap': {'system': {'role': 'system',\n", + " 'content': [{'contentType': 'text', 'mediaType': None, 'body': ''}],\n", + " 'model': 'claude-v3-sonnet',\n", + " 'children': ['01HVKZMH9K6GZP8DJFYTQ3E8MW'],\n", + " 'parent': None},\n", + " '01HVKZMH9K6GZP8DJFYTQ3E8MW': {'role': 'user',\n", + " 'content': [{'contentType': 'text',\n", + " 'mediaType': 'string',\n", + " 'body': 'what do I do with AI?'}],\n", + " 'model': 'claude-v3-sonnet',\n", + " 'children': ['01HVKZMX7QG0D1V5BHVTPMNFX9'],\n", + " 'parent': 'system'},\n", + " '01HVKZMX7QG0D1V5BHVTPMNFX9': {'role': 'assistant',\n", + " 'content': [{'contentType': 'text',\n", + " 'mediaType': None,\n", + " 'body': \"Here are some suggestions for how you could use AI to fact-check statements made in government meetings:\\n\\n1. Use a named entity recognition (NER) model to identify factual claims or statements in the meeting transcripts or minutes. NER can detect things like names, dates, numbers, etc. that may signal factual claims.\\n\\n2. Feed those extracted factual statements into a fact-checking AI system like Wolfram Alpha, Google Knowledge Graph, or a customized fact-checking model. These can verify whether the statements align with established facts and data sources.\\n\\n3. For claims that are identified as potentially false or lacking evidence, use an AI search engine or question-answering system to try to find credible sources that either confirm or refute the claim.\\n\\n4. Summarize the results, highlighting which factual claims were well-evidenced, which lacked evidence, and which appeared to be false based on authoritative sources.\\n\\n5. You could build a customized knowledge base of trusted data sources related to the government's scope to make the fact-checking more accurate and relevant.\\n\\n6. Use an AI writing assistant to help compose the final fact-checked minutes, separating verified facts from unsubstantiated claims.\\n\\nThe key is leveraging multiple AI capabilities - NER, fact-checking, search, Q&A, and writing aids - in conjunction with human oversight to thoroughly vet statements for accuracy and backing evidence. This AI-assisted process can make your minutes more reliable.\"}],\n", + " 'model': 'claude-v3-sonnet',\n", + " 'children': [],\n", + " 'parent': '01HVKZMH9K6GZP8DJFYTQ3E8MW'}},\n", + " 'lastMessageId': '01HVKZMX7QG0D1V5BHVTPMNFX9',\n", + " 'botId': '01HVKNBE4W2P7P3HG805X0FQNV'}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "responsed" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'null' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32mc:\\Users\\phil_\\OneDrive\\Coding\\AI Hackathon - Apr 24\\meetings-capture-hackathon\\notebooks\\api_test.ipynb Cell 9\u001b[0m line \u001b[0;36m1\n\u001b[0;32m 1\u001b[0m \u001b[39mimport\u001b[39;00m \u001b[39mjson\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[39m# Given JSON data\u001b[39;00m\n\u001b[0;32m 4\u001b[0m json_data \u001b[39m=\u001b[39m {\n\u001b[0;32m 5\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mid\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39m01HVM0D5CTZ7RA00F0BY634YP4\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 6\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mtitle\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mNew conversation\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 7\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mcreateTime\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m1713289729492.0\u001b[39m,\n\u001b[0;32m 8\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmessageMap\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[0;32m 9\u001b[0m \u001b[39m\"\u001b[39m\u001b[39msystem\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[0;32m 10\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mrole\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39msystem\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[1;32m---> 11\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mcontent\u001b[39m\u001b[39m\"\u001b[39m: [{\u001b[39m\"\u001b[39m\u001b[39mcontentType\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mtext\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mmediaType\u001b[39m\u001b[39m\"\u001b[39m: null, \u001b[39m\"\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39m\"\u001b[39m}],\n\u001b[0;32m 12\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmodel\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mclaude-v3-sonnet\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 13\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mchildren\u001b[39m\u001b[39m\"\u001b[39m: [\u001b[39m\"\u001b[39m\u001b[39m01HVM0D5CT7M1FX7EPNG561JHB\u001b[39m\u001b[39m\"\u001b[39m],\n\u001b[0;32m 14\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mparent\u001b[39m\u001b[39m\"\u001b[39m: null\n\u001b[0;32m 15\u001b[0m },\n\u001b[0;32m 16\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m01HVM0D5CT7M1FX7EPNG561JHB\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[0;32m 17\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mrole\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39muser\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 18\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mcontent\u001b[39m\u001b[39m\"\u001b[39m: [{\u001b[39m\"\u001b[39m\u001b[39mcontentType\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mtext\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mmediaType\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mstring\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mwhat do I do with AI?\u001b[39m\u001b[39m\"\u001b[39m}],\n\u001b[0;32m 19\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmodel\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mclaude-v3-sonnet\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 20\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mchildren\u001b[39m\u001b[39m\"\u001b[39m: [\u001b[39m\"\u001b[39m\u001b[39m01HVM0DDJQJ6FW61B37NQZ07N7\u001b[39m\u001b[39m\"\u001b[39m],\n\u001b[0;32m 21\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mparent\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39msystem\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 22\u001b[0m },\n\u001b[0;32m 23\u001b[0m \u001b[39m\"\u001b[39m\u001b[39m01HVM0DDJQJ6FW61B37NQZ07N7\u001b[39m\u001b[39m\"\u001b[39m: {\n\u001b[0;32m 24\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mrole\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39massistant\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 25\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mcontent\u001b[39m\u001b[39m\"\u001b[39m: [{\u001b[39m\"\u001b[39m\u001b[39mcontentType\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mtext\u001b[39m\u001b[39m\"\u001b[39m, \u001b[39m\"\u001b[39m\u001b[39mmediaType\u001b[39m\u001b[39m\"\u001b[39m: null, \u001b[39m\"\u001b[39m\u001b[39mbody\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mHere are some steps I would recommend for using AI to fact-check statements made in government meetings:\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m1. Transcribe the meeting audio or text into a plain text document. This will allow you to easily process the content with AI tools.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m2. Use a named entity recognition (NER) model to identify statements in the text that are factual claims about entities like people, organizations, locations, dates, statistics etc.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m3. For each factual claim identified, use a search engine or fact-checking database to try to find authoritative sources that either confirm or refute the claim.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m4. Evaluate the sources found - their reliability, recency, and whether they directly address the claim made. Prioritize highly reputable sources like government data, scientific studies, etc.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m5. For claims you cannot find good evidence for or against, mark them as unverified.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m6. Compile your findings into a report listing the factual claims made, the evidence found for or against each one, and your assessment of their accuracy.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39m7. Use a language model like myself to help rephrase the claims or find alternative ways to express them when needed for clarity.\u001b[39m\u001b[39m\\n\u001b[39;00m\u001b[39m\\n\u001b[39;00m\u001b[39mThe key is leveraging AI\u001b[39m\u001b[39m'\u001b[39m\u001b[39ms ability to quickly process and search large amounts of text data, while applying human judgment to evaluate the quality of evidence found. Let me know if you need any other specific advice as you go through this process.\u001b[39m\u001b[39m\"\u001b[39m}],\n\u001b[0;32m 26\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mmodel\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39mclaude-v3-sonnet\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 27\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mchildren\u001b[39m\u001b[39m\"\u001b[39m: [],\n\u001b[0;32m 28\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mparent\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39m01HVM0D5CT7M1FX7EPNG561JHB\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 29\u001b[0m }\n\u001b[0;32m 30\u001b[0m },\n\u001b[0;32m 31\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mlastMessageId\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39m01HVM0DDJQJ6FW61B37NQZ07N7\u001b[39m\u001b[39m\"\u001b[39m,\n\u001b[0;32m 32\u001b[0m \u001b[39m\"\u001b[39m\u001b[39mbotId\u001b[39m\u001b[39m\"\u001b[39m: \u001b[39m\"\u001b[39m\u001b[39m01HVKNBE4W2P7P3HG805X0FQNV\u001b[39m\u001b[39m\"\u001b[39m\n\u001b[0;32m 33\u001b[0m }\n\u001b[0;32m 35\u001b[0m \u001b[39m# Parse JSON\u001b[39;00m\n\u001b[0;32m 36\u001b[0m data \u001b[39m=\u001b[39m json\u001b[39m.\u001b[39mloads(json_data)\n", + "\u001b[1;31mNameError\u001b[0m: name 'null' is not defined" + ] + } + ], + "source": [ + "import json\n", + "\n", + "# Given JSON data\n", + "json_data = {\n", + " \"id\": \"01HVM0D5CTZ7RA00F0BY634YP4\",\n", + " \"title\": \"New conversation\",\n", + " \"createTime\": 1713289729492.0,\n", + " \"messageMap\": {\n", + " \"system\": {\n", + " \"role\": \"system\",\n", + " \"content\": [{\"contentType\": \"text\", \"mediaType\": null, \"body\": \"\"}],\n", + " \"model\": \"claude-v3-sonnet\",\n", + " \"children\": [\"01HVM0D5CT7M1FX7EPNG561JHB\"],\n", + " \"parent\": null\n", + " },\n", + " \"01HVM0D5CT7M1FX7EPNG561JHB\": {\n", + " \"role\": \"user\",\n", + " \"content\": [{\"contentType\": \"text\", \"mediaType\": \"string\", \"body\": \"what do I do with AI?\"}],\n", + " \"model\": \"claude-v3-sonnet\",\n", + " \"children\": [\"01HVM0DDJQJ6FW61B37NQZ07N7\"],\n", + " \"parent\": \"system\"\n", + " },\n", + " \"01HVM0DDJQJ6FW61B37NQZ07N7\": {\n", + " \"role\": \"assistant\",\n", + " \"content\": [{\"contentType\": \"text\", \"mediaType\": null, \"body\": \"Here are some steps I would recommend for using AI to fact-check statements made in government meetings:\\n\\n1. Transcribe the meeting audio or text into a plain text document. This will allow you to easily process the content with AI tools.\\n\\n2. Use a named entity recognition (NER) model to identify statements in the text that are factual claims about entities like people, organizations, locations, dates, statistics etc.\\n\\n3. For each factual claim identified, use a search engine or fact-checking database to try to find authoritative sources that either confirm or refute the claim.\\n\\n4. Evaluate the sources found - their reliability, recency, and whether they directly address the claim made. Prioritize highly reputable sources like government data, scientific studies, etc.\\n\\n5. For claims you cannot find good evidence for or against, mark them as unverified.\\n\\n6. Compile your findings into a report listing the factual claims made, the evidence found for or against each one, and your assessment of their accuracy.\\n\\n7. Use a language model like myself to help rephrase the claims or find alternative ways to express them when needed for clarity.\\n\\nThe key is leveraging AI's ability to quickly process and search large amounts of text data, while applying human judgment to evaluate the quality of evidence found. Let me know if you need any other specific advice as you go through this process.\"}],\n", + " \"model\": \"claude-v3-sonnet\",\n", + " \"children\": [],\n", + " \"parent\": \"01HVM0D5CT7M1FX7EPNG561JHB\"\n", + " }\n", + " },\n", + " \"lastMessageId\": \"01HVM0DDJQJ6FW61B37NQZ07N7\",\n", + " \"botId\": \"01HVKNBE4W2P7P3HG805X0FQNV\"\n", + "}\n", + "\n", + "# Parse JSON\n", + "data = json.loads(json_data)\n", + "\n", + "# Iterate through keys of messageMap to find the key with role 'assistant'\n", + "assistant_key = None\n", + "for key, value in data[\"messageMap\"].items():\n", + " if value[\"role\"] == \"assistant\":\n", + " assistant_key = key\n", + " break\n", + "\n", + "if assistant_key is not None:\n", + " print(f\"The key with role 'assistant' is: {assistant_key}\")\n", + "else:\n", + " print(\"No key with role 'assistant' found.\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "hackathon", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.13" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}