From 4d6760bbf4d70d9dd49d8b43ad21cb5dcfb82955 Mon Sep 17 00:00:00 2001 From: Anuhya BS Date: Mon, 19 May 2025 09:57:43 -0500 Subject: [PATCH 1/3] Cleanup jupyter notebook --- .../jupyter-notebook-agent-testing.ipynb | 51 +++++++++++++++---- ...yter-notebook-agent-testing_dnowlaod.ipynb | 51 +++++++++++++++---- 2 files changed, 82 insertions(+), 20 deletions(-) diff --git a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb index 4a2ba3d..7376428 100644 --- a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb +++ b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb @@ -21,24 +21,47 @@ "metadata": {}, "outputs": [], "source": [ - "import asyncio\n", "import pandas as pd\n", "from mcp import ClientSession\n", - "from mcp.client.sse import sse_client\n", - "\n", + "from mcp.client.sse import sse_client" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e5eff532", + "metadata": {}, + "outputs": [], + "source": [ "# Paths\n", "# Input schema: id, question, expected_answer, ...\n", "INPUT_CSV_PATH = \"\"\n", "\n", "# Output schema: id, question, expected_answer, response, \n", - "OUTPUT_PATH = \"/PATH_TO_STORE_RESPONSES/output.xlsx\"\n", - "\n", + "OUTPUT_PATH = \"/PATH_TO_STORE_RESPONSES/output.xlsx\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5104231", + "metadata": {}, + "outputs": [], + "source": [ "# Corvic MCP setup\n", "MCP_URL = \"\"\n", "HEADERS = {\n", " \"Authorization\": \"YOUR-CORVIC-API-TOKEN\"\n", - "}\n", - "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42f7830d", + "metadata": {}, + "outputs": [], + "source": [ "async def query_agent(session, question):\n", " try:\n", " result = await session.call_tool(\n", @@ -49,8 +72,16 @@ " return result.content[0].text\n", " return \"No content returned\"\n", " except Exception as e:\n", - " return f\"Error: {e}\"\n", - "\n", + " return f\"Error: {e}\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "38f545cc", + "metadata": {}, + "outputs": [], + "source": [ "async def run():\n", " df = pd.read_csv(INPUT_CSV_PATH)\n", " results = []\n", @@ -76,7 +107,7 @@ " })\n", "\n", " pd.DataFrame(results).to_excel(OUTPUT_PATH, index=False)\n", - " print(f\"โœ… Done. Results saved to {OUTPUT_PATH}\")\n" + " print(f\"โœ… Done. Results saved to {OUTPUT_PATH}\")" ] }, { diff --git a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb index ce0c686..1f62cb0 100644 --- a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb +++ b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb @@ -21,24 +21,47 @@ "metadata": {}, "outputs": [], "source": [ - "import asyncio\n", "import pandas as pd\n", "from mcp import ClientSession\n", - "from mcp.client.sse import sse_client\n", - "\n", + "from mcp.client.sse import sse_client" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ddd5010c", + "metadata": {}, + "outputs": [], + "source": [ "# Paths\n", "# Input schema: id, question, expected_answer, ...\n", "INPUT_CSV_PATH = \"\"\n", "\n", "# Output schema: id, question, expected_answer, response, \n", - "OUTPUT_PATH = \"/PATH_TO_STORE_RESPONSES/output.xlsx\"\n", - "\n", + "OUTPUT_PATH = \"/PATH_TO_STORE_RESPONSES/output.xlsx\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1f8a6039", + "metadata": {}, + "outputs": [], + "source": [ "# Corvic MCP setup\n", "MCP_URL = \"\"\n", "HEADERS = {\n", " \"Authorization\": \"YOUR-CORVIC-API-TOKEN\"\n", - "}\n", - "\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b8495fe2", + "metadata": {}, + "outputs": [], + "source": [ "async def query_agent(session, question):\n", " try:\n", " result = await session.call_tool(\n", @@ -49,8 +72,16 @@ " return result.content[0].text\n", " return \"No content returned\"\n", " except Exception as e:\n", - " return f\"Error: {e}\"\n", - "\n", + " return f\"Error: {e}\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "29ffe35d", + "metadata": {}, + "outputs": [], + "source": [ "async def run():\n", " df = pd.read_csv(INPUT_CSV_PATH)\n", " results = []\n", @@ -76,7 +107,7 @@ " })\n", "\n", " pd.DataFrame(results).to_excel(OUTPUT_PATH, index=False)\n", - " print(f\"Done. Results saved to {OUTPUT_PATH}\")\n" + " print(f\"Done. Results saved to {OUTPUT_PATH}\")" ] }, { From 8226e79db0902717ffbfc870431c035d2d278ef3 Mon Sep 17 00:00:00 2001 From: Anuhya BS Date: Mon, 19 May 2025 09:57:43 -0500 Subject: [PATCH 2/3] Cleanup jupyter notebook --- .../jupyter-notebook-agent-testing.ipynb | 12 +- ...yter-notebook-agent-testing_dnowlaod.ipynb | 139 ------------------ 2 files changed, 6 insertions(+), 145 deletions(-) delete mode 100644 deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb diff --git a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb index 7376428..1f62cb0 100644 --- a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb +++ b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing.ipynb @@ -6,7 +6,7 @@ "metadata": {}, "source": [ "
\n", - " \"Corvic\n", + " \"Corvic\n", "
\n", "\n", "

Corvic AI Agent Testing via API

\n", @@ -29,7 +29,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e5eff532", + "id": "ddd5010c", "metadata": {}, "outputs": [], "source": [ @@ -44,7 +44,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d5104231", + "id": "1f8a6039", "metadata": {}, "outputs": [], "source": [ @@ -58,7 +58,7 @@ { "cell_type": "code", "execution_count": null, - "id": "42f7830d", + "id": "b8495fe2", "metadata": {}, "outputs": [], "source": [ @@ -78,7 +78,7 @@ { "cell_type": "code", "execution_count": null, - "id": "38f545cc", + "id": "29ffe35d", "metadata": {}, "outputs": [], "source": [ @@ -107,7 +107,7 @@ " })\n", "\n", " pd.DataFrame(results).to_excel(OUTPUT_PATH, index=False)\n", - " print(f\"โœ… Done. Results saved to {OUTPUT_PATH}\")" + " print(f\"Done. Results saved to {OUTPUT_PATH}\")" ] }, { diff --git a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb b/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb deleted file mode 100644 index 1f62cb0..0000000 --- a/deployed-agents/Jupyter-notebook/jupyter-notebook-agent-testing_dnowlaod.ipynb +++ /dev/null @@ -1,139 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "96c2383b", - "metadata": {}, - "source": [ - "
\n", - " \"Corvic\n", - "
\n", - "\n", - "

Corvic AI Agent Testing via API

\n", - "\n", - "Corvic AI agents deployed in production can be tested using APIs. This notebook demonstrates how to interact with deployed agents programmatically, enabling automated testing and integration into various workflows.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9f0b88c1", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "from mcp import ClientSession\n", - "from mcp.client.sse import sse_client" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ddd5010c", - "metadata": {}, - "outputs": [], - "source": [ - "# Paths\n", - "# Input schema: id, question, expected_answer, ...\n", - "INPUT_CSV_PATH = \"\"\n", - "\n", - "# Output schema: id, question, expected_answer, response, \n", - "OUTPUT_PATH = \"/PATH_TO_STORE_RESPONSES/output.xlsx\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1f8a6039", - "metadata": {}, - "outputs": [], - "source": [ - "# Corvic MCP setup\n", - "MCP_URL = \"\"\n", - "HEADERS = {\n", - " \"Authorization\": \"YOUR-CORVIC-API-TOKEN\"\n", - "}" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "b8495fe2", - "metadata": {}, - "outputs": [], - "source": [ - "async def query_agent(session, question):\n", - " try:\n", - " result = await session.call_tool(\n", - " \"query\", arguments={\"query_content\": question}\n", - " )\n", - "\n", - " if result.content and len(result.content) > 0:\n", - " return result.content[0].text\n", - " return \"No content returned\"\n", - " except Exception as e:\n", - " return f\"Error: {e}\"" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "29ffe35d", - "metadata": {}, - "outputs": [], - "source": [ - "async def run():\n", - " df = pd.read_csv(INPUT_CSV_PATH)\n", - " results = []\n", - "\n", - " async with sse_client(MCP_URL, headers=HEADERS) as (read, write):\n", - " async with ClientSession(read, write) as session:\n", - " await session.initialize()\n", - "\n", - " for _, row in df.iterrows():\n", - " query = row['question']\n", - " id_ = row['id']\n", - " expected = row['expected_answer']\n", - "\n", - " print(f\"Querying ID {id_}: {query}\")\n", - " response = await query_agent(session, query)\n", - " print(f\"Response: {response}\")\n", - "\n", - " results.append({\n", - " \"id\": id_,\n", - " \"question\": query,\n", - " \"expected_answer\": expected,\n", - " \"response\": response\n", - " })\n", - "\n", - " pd.DataFrame(results).to_excel(OUTPUT_PATH, index=False)\n", - " print(f\"Done. Results saved to {OUTPUT_PATH}\")" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "df7f433b", - "metadata": {}, - "outputs": [], - "source": [ - "\n", - "# To run inside notebook\n", - "await run()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "name": "python", - "version": "3.10.11" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 83726799b4d225feba8bd0d5d097753f27dc2454 Mon Sep 17 00:00:00 2001 From: Anand Chandrashekar Date: Thu, 22 May 2025 18:07:25 +0530 Subject: [PATCH 3/3] This commit contains an example of using Corvic MCP in a Google Colab environment --- .../Getting_started_with_Corvic.ipynb | 359 ++++++++++++++++++ .../Google Colab Workbook/README.md | 32 ++ 2 files changed, 391 insertions(+) create mode 100644 deployed-agents/Google Colab Workbook/Getting_started_with_Corvic.ipynb create mode 100644 deployed-agents/Google Colab Workbook/README.md diff --git a/deployed-agents/Google Colab Workbook/Getting_started_with_Corvic.ipynb b/deployed-agents/Google Colab Workbook/Getting_started_with_Corvic.ipynb new file mode 100644 index 0000000..974d8d4 --- /dev/null +++ b/deployed-agents/Google Colab Workbook/Getting_started_with_Corvic.ipynb @@ -0,0 +1,359 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "language_info": { + "name": "python" + } + }, + "cells": [ + { + "cell_type": "markdown", + "source": [ + "**Getting Started with Corvic using Colab**\n", + "In this example, we will accomplish a simple query to Corvic. This example is similar to the one mentioned [here](https://app.corvic.ai/docs/mcpIntegrations/openaiMcpWithCorvic) wherein we enquire about video game sales\n", + "\n", + "The following two steps are involved:\n", + "

\n", + "STEP 1: Invoke Corvic agent using the Model Context Protocol and ask a question about video game sales\n", + "

\n", + "

\n", + "STEP 2: (Optional) Parse the markdown and separate out the text and image data\n", + "

" + ], + "metadata": { + "id": "XbHo_dz8weuI" + } + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "\n", + "---\n", + "\n" + ], + "metadata": { + "id": "rIKZ3cASxrq_" + } + }, + { + "cell_type": "markdown", + "source": [ + "STEP 1: Invoke Corvic agent using the Model Context Protocol and ask a question about video game sales\n", + "

\n", + "Please note:\n", + "The MCP library is used for corvic agent invocation. Corvic returns markdown text. We will convert markdown and beautiful soup libraries to parse text and images" + ], + "metadata": { + "id": "rgYEqIKixUmr" + } + }, + { + "cell_type": "code", + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "XObia6wuZ6xe", + "outputId": "c3bbdc6f-3f9c-4989-c11f-27da08467500" + }, + "source": [ + "# mcp is used for corvic agent invocation\n", + "!pip install mcp\n", + "!pip install beautifulsoup4\n", + "!pip install markdown" + ], + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "source": [ + "import asyncio\n", + "from mcp import ClientSession\n", + "from mcp.client.sse import sse_client\n" + ], + "metadata": { + "id": "-lsdUACMaXRy" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "source": [ + "url=\"YOUR CORVIC MCP ENDPOINT\"\n", + "headers={\n", + " \"Authorization\": \"YOUR CORVIC API TOKEN\"\n", + " }\n" + ], + "metadata": { + "id": "nkQV-Ch_yJjr" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "code", + "source": [ + "async def run():\n", + " async with sse_client(\n", + " url,\n", + " headers=headers,\n", + " ) as (read, write):\n", + " async with ClientSession(read, write) as session:\n", + " # Initialize the connection\n", + " await session.initialize()\n", + "\n", + " # List available tools\n", + " tools = await session.list_tools()\n", + " print(tools)\n", + "\n", + " # Call a tool\n", + " result = await session.call_tool(\n", + " \"query\", arguments={\n", + " \"query_content\":\n", + " \"Group all the data by name and find the top titles by \"\n", + " \"global sales. Output the name and the total global sales \"\n", + " \" in a html tabular format.\"\n", + " \"Provide a bar chart for the same table with the game title\"\n", + " \" on X axis and global sales on Y axis\"}\n", + " )\n", + " return result\n", + "\n" + ], + "metadata": { + "id": "g9gQh1GbagQ8" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "The following line will invoke corvic and collect the markdown response in the corvic_response field" + ], + "metadata": { + "id": "0UWY8Vg7yfIG" + } + }, + { + "cell_type": "code", + "source": [ + "corvic_response=await run()" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/" + }, + "id": "zgiYun6jasQf", + "outputId": "d4f13259-1d02-4b86-a900-0dddc35f9c3c" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "You can write the Corvic response directly in an MD file and view it" + ], + "metadata": { + "id": "x_c1BBSy3P0j" + } + }, + { + "cell_type": "code", + "source": [ + "with open(\"vg_query.md\", \"a\") as file:\n", + " for content in corvic_response.content:\n", + " file.write(content.text)" + ], + "metadata": { + "id": "0-W9kSys3ZdN" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "You can directly view the markdown output as below." + ], + "metadata": { + "id": "gipmqzY64Iyi" + } + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": "" + }, + { + "cell_type": "code", + "source": [ + "from IPython.display import Markdown, display\n", + "display(Markdown(corvic_response.content[0].text))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "id": "zd96XjmO3lMP", + "outputId": "5a6f7044-70a9-4204-82ea-d642f1ed0a4d" + }, + "outputs": [], + "execution_count": null + }, + { + "metadata": {}, + "cell_type": "markdown", + "source": [ + "This completes Step 1\n", + "\n", + "---" + ] + }, + { + "cell_type": "markdown", + "source": [ + "STEP 2: Parse the markdown and display the text and images separately" + ], + "metadata": { + "id": "DcFN8jLTzSoX" + } + }, + { + "cell_type": "code", + "source": [ + "from types import NoneType\n", + "from bs4 import BeautifulSoup\n", + "import markdown\n", + "import base64\n", + "\n", + "\n", + "html_content = markdown.markdown(corvic_response.content[0].text)\n", + "html_view = BeautifulSoup(\"\"+html_content+\"\", features=\"html.parser\")\n", + "\n", + "html_node = html_view.find('html')\n", + "#Find images and strip from original html\n", + "image_data=[]\n", + "text_output=''\n", + "for c1 in html_node.children:\n", + " # print(str(type(c1)))\n", + " if 'bs4.element.NavigableString' not in str(type(c1)):\n", + " if len(list(c1.children)) > 0:\n", + " for c2 in c1.children:\n", + " # print(str(type(c2)) + \" \" + str(c2.name))\n", + " if \"img\" == str(c2.name):\n", + " b64encoded_img_string=c2.attrs['src'].replace('data:image/png;base64,', '')\n", + " image_data.append(base64.b64decode(b64encoded_img_string))\n", + " c2.decompose()\n", + " else:\n", + " # print(str(type(c2)) )\n", + " if 'NoneType' not in str(type(c2)):\n", + " text_output+=repr(c2)\n", + " else:\n", + " text_output+=repr(c1)" + ], + "metadata": { + "id": "LcQmN2unnod3" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "Here is the text output in a html format for better readability" + ], + "metadata": { + "id": "w5BOH3Dv4yS1" + } + }, + { + "cell_type": "code", + "source": [ + "from IPython.core.display import display, HTML\n", + "\n", + "display(HTML(html_node.prettify()))" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 372 + }, + "id": "Q6EVovBvp9JK", + "outputId": "2d23bdde-e67c-4c5b-fefa-da9d0a859b1b" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "Here is the first image from the Corvic response" + ], + "metadata": { + "id": "7oJEprsv5O3f" + } + }, + { + "cell_type": "code", + "source": [ + "from IPython import display\n", + "\n", + "display.Image(image_data[0])" + ], + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 422 + }, + "id": "2VblEuxLoxdp", + "outputId": "de8a6ede-37fd-4f67-cc94-28d49064cbc4" + }, + "outputs": [], + "execution_count": null + }, + { + "cell_type": "markdown", + "source": [ + "\n", + "\n", + "---\n", + "\n" + ], + "metadata": { + "id": "JNfQ9V8W4tKC" + } + }, + { + "cell_type": "markdown", + "source": [ + "Summary: You have been able to invoke the Corvic MCP from this Colab workbook.\n", + "You also explored the response in different ways allowing you great flexibility in using the output in your AI pipelines" + ], + "metadata": { + "id": "jg7vEXZn4YQ5" + } + }, + { + "cell_type": "code", + "source": [], + "metadata": { + "id": "EqEklB0q5IZZ" + }, + "outputs": [], + "execution_count": null + } + ] +} diff --git a/deployed-agents/Google Colab Workbook/README.md b/deployed-agents/Google Colab Workbook/README.md new file mode 100644 index 0000000..181cf6e --- /dev/null +++ b/deployed-agents/Google Colab Workbook/README.md @@ -0,0 +1,32 @@ +# ๐Ÿงช Google Colab Workbook for interacting with Corvic Agents via MCP + +This example demonstrates how to work with a deployed Corvic agent via MCP +We also explore how to view, and parse text and image outputs for downstream AI processing +--- + +## ๐Ÿ“˜ Use Case + +You want to explore Corvic Agent in an interactive Google Colab Environment +You want to view different parts of the response, including text and images +--- + +## โœ… Steps + +**Pre-requisites** +This example is similar to the one mentioned [here](https://app.corvic.ai/docs/mcpIntegrations/openaiMcpWithCorvic) +wherein we enquire about video game sales. Please complete the pre-requisites + +1. **Configure Corvic Agent Endpoint** + - Set `MCP_URL` to your deployed Corvic agent's endpoint. + - Set the `HEADERS` with your Corvic API token. + +2. **Understand the query Invoke the Corvic Agent via MCP** + - We invoke a question about video game sales and ask the agent to provide a HTML table and bar chart + +3. **Visualize the responses** + - We view the response from Corvic via a markdown viewer + - We parse text and image separately and view them + +--- + +Need help? Contact [support@corvic.ai](mailto:support@corvic.ai) or visit [https://www.corvic.ai](https://www.corvic.ai). \ No newline at end of file