Skip to content

Commit

Permalink
Add Deployment Steps
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamTomkins committed May 22, 2024
1 parent dee5d56 commit 5269cd9
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 0 deletions.
66 changes: 66 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,72 @@ Now, clicking on the blue chat icon, you can go ahead and test out your first Fl

![Compile](images/rag/chat.png)

## Deploy Your Flow to Kalavai

When you have built the flow you want, and tested out the Chat function inside the Agent Builder, your next stop is to be able to execute that flow from code, so you can start to put it to good use!

We can do this, by deploying the Flow out to the Kalavai Network, by following these steps!

1. Download a copy of your Flow

1. Get a copy of the Flow API Key from the user interface.

You can see the key icon on the top right of the Agent Builder, click this to see your key management screen.
![Deploy](images/deploy/d_1.png)

From here, you can create a new key. These are the keys that people can use to access your flows. This means you do not need to share any other keys with external users.

![Deploy](images/deploy/d_2.png)

Give your new key a name, and click create secret key.

![Deploy](images/deploy/d_3.png)

This will give you the key you need, copy this to your clip board, and save it somewhere, you will need this in your code, to call your API. If you lose it, you cannot get it back, but you can at least generate new ones as you need.

![Deploy](images/deploy/d_4.png)
Finally this will take you back to the API keys screen.

![Deploy](images/deploy/d_5.png)

From you will want to go back to your flow, by clicking the name in the
top left corner.

![Deploy](images/deploy/d_6.png)

From here we will export your Flow, using the download button in the top left corner. Also, take a note of the _code_ icon here. This is where you can find code example to see how to access your flows once you deploy them!

![Deploy](images/deploy/d_7.png)

Moving on, name your flow and download it. From this point on we need to go back to using the main Kalavai interface, and we will click on __Deploy__ on the right hand side kalavai menu.



This shows us all our current deployments, you can see your Agent Builder here. We are going to want to create a new deployment, by clicking the Deploy button up at the top right.

![Deploy](images/deploy/d_9.png)

From here we will want to Name our new deployment, attach the json flow we previously downloaded, and copy in the API key that we copied from the Agent Builder in an earlier step.

![Deploy](images/deploy/d_12.png)

From this, your flow will successfully deploy, and you can see it here in your deployments list.

You can click the _endpoint_ link on the right to examine the documentation for your deployment! This will take you to the public url of your newly deployed AI Flow.

You will see a message saying `detail "Not Found"`. This is expected, as the endpoint is the machine-accessable url. To inspect to docs add "/docs" to the url to see what has actually been deployed!

For example, if your endpoint links to `https://adam.test.test.k8s.mvp.kalavai.net/` update it to `https://adam.test.test.k8s.mvp.kalavai.net/docs/` to see this FastAPI endpoint.

![Deploy](images/deploy/d_14.png)

You will not be able to execute here, as the endpoint is API protected, but you can move into the land of code, and see how to call this endpoint in the [Provided Notebook](notebooks/Call_Agent_Flow.ipynb)

You can inspect the Agent builder Code Tab to see various examples of code usage:

![Deploy](images/deploy/d_15.png)


## Exercised and Next Steps

Now that you have the basic structure in place, you can start to think about more complex knowledge-driven applications. A good place to start would be:
Expand Down
1 change: 1 addition & 0 deletions example_collections/example_collection.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions example_flows/Basic RAG Example.json

Large diffs are not rendered by default.

Binary file added images/deploy/d_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_11.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_12.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_14.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/deploy/d_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions notebooks/Call_Agent_Flow.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Call your Deployed Flows\n",
"\n",
"This is a notebook to show how to call your deployed flows using the `requests` library in raw python.\n"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"from typing import Optional\n",
"\n",
"# Update this to the base URL of your endpoint, available in the Kalavai dashboard\n",
"BASE_API_URL = \"https://adam.playground.test.k8s.mvp.kalavai.net/api/v1/process\"\n",
"\n",
"# Update this to the flow ID you want to run\n",
"FLOW_ID = \"24073dfd-c66a-441c-8951-78588f0bd2d7\"\n",
"\n",
"# You can tweak the flow by adding a tweaks dictionary\n",
"# e.g {\"OpenAI-XXXXX\": {\"model_name\": \"gpt-4\"}}\n",
"TWEAKS = {\n",
" \"KalavaiLlm-UTSYC\": {},\n",
" \"RetrievalQA-JFfxD\": {},\n",
" \"CombineDocsChain-RoWar\": {},\n",
" \"VectorStoreRetriever-HhAfJ\": {},\n",
" \"KalavaiDB-yi2jj\": {},\n",
" \"KalavaiEmbedding-u7wya\": {},\n",
" \"CharacterTextSplitter-o2vyX\": {},\n",
" \"TextLoader-QZBao\": {}\n",
"}\n",
"\n",
"def run_flow(inputs: dict, flow_id: str, tweaks: Optional[dict] = None, api_key: Optional[str] = None) -> dict:\n",
" \"\"\"\n",
" Run a flow with a given message and optional tweaks.\n",
"\n",
" :param message: The message to send to the flow\n",
" :param flow_id: The ID of the flow to run\n",
" :param tweaks: Optional tweaks to customize the flow\n",
" :return: The JSON response from the flow\n",
" \"\"\"\n",
" api_url = f\"{BASE_API_URL}/{flow_id}\"\n",
"\n",
" payload = {\"inputs\": inputs}\n",
" headers = None\n",
" if tweaks:\n",
" payload[\"tweaks\"] = tweaks\n",
" if api_key:\n",
" headers = {\"x-api-key\": api_key}\n",
" response = requests.post(api_url, json=payload, headers=headers)\n",
" return response.json()\n",
"\n",
"# Setup any tweaks you want to apply to the flow\n",
"inputs = {\"query\":\"Hello\"}\n",
"\n",
"# Get this from the LANGFLOW repository, as shown in the Documentatuin\n",
"api_key = \"sk-...\"\n",
"r = run_flow(inputs, flow_id=FLOW_ID, tweaks=TWEAKS, api_key=api_key)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "agent",
"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.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit 5269cd9

Please sign in to comment.