Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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",
"<p>\n",
"STEP 1: Invoke Corvic agent using the Model Context Protocol and ask a question about video game sales\n",
"</p>\n",
"<p>\n",
"STEP 2: (Optional) Parse the markdown and separate out the text and image data\n",
"</p>"
],
"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",
"<p/>\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>\"+html_content+\"</html>\", 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
}
]
}
32 changes: 32 additions & 0 deletions deployed-agents/Google Colab Workbook/README.md
Original file line number Diff line number Diff line change
@@ -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).
Loading