Skip to content
Merged
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
64 changes: 41 additions & 23 deletions 01-getting-started/end-to-end-example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"\n",
"# Introduction to Contextual AI Platform using the Python Client\n",
"\n",
"Contextual AI lets you create and use generative AI agents. This notebook introduces an end-to-end example workflow for creating a Retrieval-Augmented Generation (RAG) agent for a financial use case. This notebook uses the python client.\n",
"Contextual AI lets you create and use generative AI agents. This notebook introduces an end-to-end example workflow for creating a Retrieval-Augmented Generation (RAG) agent for a financial use case. This notebook uses the Python client.\n",
"\n",
"This notebook covers the following steps:\n",
"- Creating a Datastore\n",
Expand All @@ -24,7 +24,7 @@
"\n",
"The notebook can be run in under 15 minutes. The full documentation is available at [docs.contextual.ai](https://docs.contextual.ai/)\n",
"\n",
"To run this notebook interactively, you can open it in Google Colab. However, make sure to copy over the additional files.\n",
"To run this notebook interactively, open it in Google Colab. However, make sure to copy over the additional files.\n",
"\n",
"[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/ContextualAI/examples/blob/main/01-getting-started/end-to-end-example.ipynb)"
]
Expand Down Expand Up @@ -54,9 +54,17 @@
"from contextual import ContextualAI"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Add your API Key here. If you are using our US Cloud, you can leave the default values.\n",
"If you are on another instance, modify `base_url` to the appropriate address."
]
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": null,
"metadata": {
"id": "4wJG66VTIQvO"
},
Expand All @@ -66,8 +74,9 @@
"#os.environ[\"CONTEXTUAL_API_KEY\"] = API_KEY # You can store the API key is stored as the environment variable \n",
"\n",
"client = ContextualAI(\n",
" api_key=os.environ.get(\"CONTEXTUAL_API_KEY\"), # This is the default and can be omitted\n",
")"
" api_key=os.environ.get(\"CONTEXTUAL_API_KEY\"),\n",
" base_url=\"http://api.contextual.ai/v1\"\n",
") "
]
},
{
Expand All @@ -79,7 +88,7 @@
"## Step 1: Create your Datastore\n",
"\n",
"\n",
"You will need to first create a datastore for your agent using the /datastores endpoint. A datastore is secure storage for data. Each agent will have it's own datastore for storing data securely."
"You will need to first create a datastore for your agent using the /datastores endpoint. A datastore is secure storage for data. Each agent will have its own datastore for storing data securely."
]
},
{
Expand Down Expand Up @@ -110,7 +119,7 @@
"You can now ingest documents into your Agent's datastore using the /datastores endpoint. Documents must be a PDF or HTML file.\n",
"\n",
"\n",
"I am using a example PDF. You can also use your own documents here. If you have very long documents (hundreds of pages), processing can take longer."
"I am using an example PDF. You can also use your own documents here. If you have very long documents (hundreds of pages), processing can take longer."
]
},
{
Expand All @@ -133,7 +142,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's ingest the file"
"Let's ingest the file to start the parsing/extraction process."
]
},
{
Expand Down Expand Up @@ -169,6 +178,25 @@
"print(\"Document metadata:\", metadata)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can also export the parsed document for use outside of Contextual. \n",
"\n",
"**Note:** It may take a few minutes for the document to be ingested and processed. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"getdocs = client.datastores.documents.get_parse_result(datastore_id=datastore_id, document_id=document_id,output_types=\"markdown-document\")\n",
"getdocs.markdown_document"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -209,18 +237,7 @@
"source": [
"## Step 4: Query your Agent\n",
"\n",
"Let's query our agent to see if its working. The required information is the agent_id and messages. \n",
"\n",
"Optional information includes parameters for streaming, conversation_id, and model_id if using a different fine tuned model."
]
},
{
"cell_type": "markdown",
"metadata": {
"id": "QOW94UdMySbp"
},
"source": [
"**Note:** It may take a few minutes for the document to be ingested and processed. The Assistant will give a detailed answer once the documents are ingested."
"Let's query our agent to see if its working. The required information is the agent_id and messages. "
]
},
{
Expand Down Expand Up @@ -249,7 +266,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There is lots more information you can access from the query result. You can the retrieved documents for example. "
"There is much more information you can access from the query result. You can view the attributions in an image format. "
]
},
{
Expand Down Expand Up @@ -305,7 +322,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"Evaluation endpoints allow you to evaluate your Agent. Contextual support using a variety of evalulation frameworks, such as RAGAS, and different evaluation platfor, such as Langfuse. You will find additional integration examples in our examples repo.\n",
"Evaluation endpoints allow you to evaluate your Agent. Contextual support using a variety of evalulation frameworks, such as RAGAS, and different evaluation platforms, such as Langfuse. You will find additional examples around evaluation in this repo.\n",
"\n",
"For those using unit tests, we also offer our `lmunit` endpoint, get more details [here](https://contextual.ai/blog/lmunit/) \n",
"\n",
Expand Down Expand Up @@ -341,7 +358,8 @@
"source": [
"## Step 6: Improving your Agent\n",
"\n",
"Contexual AI provides many settings for improving overall performance including on the retrieval side or the generation side. A simple example is modifying the system prompt, you can modify the agent as follows.\n"
"Contexual AI provides many settings for improving overall performance including on the retrieval side or the generation side. A simple example is modifying the system prompt, you can modify the agent as follows.\n",
"For additional ways to improve the agent, look over the [Improve Agent Performance](https://github.com/ContextualAI/examples/tree/main/06-improve-agent-performance) notebook.\n"
]
},
{
Expand Down
Loading