|
| 1 | +# Teams File Upload Starter Kit |
| 2 | + |
| 3 | +> When using this starter kit to create assistant instances, please make sure to **first create and add the extensions |
| 4 | +to |
| 5 | +> the assistant, then upload the actions.** Therefore, the actions can be automatically associated with the extension. |
| 6 | +
|
| 7 | +## Goal |
| 8 | + |
| 9 | +This is a simple example of how to enable file upload in Watson Assistant with **Teams** channel, and |
| 10 | +forward the file to other services via custom extension for further processing. |
| 11 | + |
| 12 | +This starter kit implements the following features: |
| 13 | + |
| 14 | +- File uploading via Teams to watsonx Assistant and read file's metadata and content in the assistant actions. |
| 15 | +- Forward the file to Watson Discovery to perform custom in-file search. |
| 16 | +- Summarize the file content with watsonx.ai foundation models. |
| 17 | + |
| 18 | +> The file summarization feature only supports PDF files in English. |
| 19 | +
|
| 20 | +## Preparation |
| 21 | + |
| 22 | +Please note that you only need to follow the steps below if you want to try the in-file search and content summarization |
| 23 | +feature. |
| 24 | + |
| 25 | +If you are not interested in testing these features, you can skip this section. The two features |
| 26 | +can be disabled by setting the environment variable `WD_ENABLED` and `WATSONX_ENABLED` to `false` respectively. |
| 27 | + |
| 28 | +### In-file search with Watson Discovery |
| 29 | + |
| 30 | +If you would like to try the in-file search feature, you need to |
| 31 | +[create a Watson Discovery instance](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-getting-started&locale=zh-CN#before-you-begin-tool), |
| 32 | +then [create a project](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-projects) |
| 33 | +and [a collection](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-collections). |
| 34 | + |
| 35 | +Please follow [this guide](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-api-use) to |
| 36 | +prepare the following info: |
| 37 | + |
| 38 | +- `WD_API_URL`: The API URL of the Watson Discovery instance. |
| 39 | +- `WD_APIKEY`: The API key of the Watson Discovery instance. |
| 40 | +- `WD_PROJECT_ID`: The project ID of the project you created in the Watson Discovery instance |
| 41 | +- `WD_COLLECTION_ID`: The collection ID of the collection you created in the project above |
| 42 | + |
| 43 | +### Content summarization with watsonx.ai |
| 44 | + |
| 45 | +If you would like to try the summarization feature, you need to create a watsonx.ai project and obtain the following |
| 46 | +info: |
| 47 | + |
| 48 | +- `WATSONX_API_URL`: The API URL of the watsonx.ai instance. depends on the region of the |
| 49 | + instance. [See here](https://ibm.github.io/watson-machine-learning-sdk/setup_cloud.html#authentication) for possible |
| 50 | + values. |
| 51 | +- `WATSONX_API_KEY`: The API key of the watsonx.ai instance. |
| 52 | + Follow [this guide](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-credentials.html?context=wx&audience=wdp) |
| 53 | + to find it. |
| 54 | +- `WATSONX_PROJECT_ID`: The project ID of the watsonx.ai project that you want to use to call the LLM models. |
| 55 | + Follow [this guide](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-python-lib.html?context=wx&audience=wdp#project-id) |
| 56 | + to find it. |
| 57 | + |
| 58 | +## Setup Steps |
| 59 | + |
| 60 | +1. [Deploy the watsonx Assistant Teams File Upload API Server](#deploy-the-watsonx-assistant-teams-file-upload-api-server) |
| 61 | +2. Upload the custom extension and sample actions to watsonx Assistant |
| 62 | +3. Integrate the watsonx Assistant with Microsoft Teams |
| 63 | + - Create Teams app with **file upload** feature enabled |
| 64 | + |
| 65 | +## Deploy the watsonx Assistant Teams File Upload API Server |
| 66 | + |
| 67 | +The custom extension requires an API server to fetch the uploaded file from Teams and forward it to other services. The |
| 68 | +API server can be deployed locally or on the IBM Cloud Code Engine. |
| 69 | + |
| 70 | +### Local Deployment |
| 71 | + |
| 72 | +The server was developed with Python flask framework. To deploy the server locally, please follow the steps below: |
| 73 | + |
| 74 | +1. Install Python 3.8 or above |
| 75 | +2. Clone the repo and navigate to the `teams-file-upload/server` folder |
| 76 | +3. Create a virtual environment with `python3 -m venv venv`, and activate it with `source venv/bin/activate` |
| 77 | +4. Install the dependencies with `pip3 install -r requirements.txt` |
| 78 | +5. Copy the `.env-sample` file to `.env` and fill in the required information |
| 79 | +6. Start the server with `python3 app.py` |
| 80 | +7. The server will be running on `http://localhost:5050` by default. You should see "Teams File Upload API server is up |
| 81 | + and running." if open the link in browser. |
| 82 | + |
| 83 | +To allow Watson Assistant to access the API server, you need to expose the server to the internet. You can use tools |
| 84 | +like |
| 85 | +[ngrok](https://ngrok.com/) to do that. After installing ngrok, run `ngrok http 5050` to expose the server to the |
| 86 | +internet. |
| 87 | + |
| 88 | +### IBM Cloud Code Engine Deployment |
| 89 | + |
| 90 | +The server comes with the Dockerfile for Code Engine deployment. To deploy the server to Code Engine, please follow the |
| 91 | +steps below: |
| 92 | + |
| 93 | +1. Build the docker image |
| 94 | + 1. Copy the `.env-sample` file to `.env` and fill in the required information |
| 95 | + 2. Build the image with `docker build -t <image-name> .` The image name should follow the format |
| 96 | + of `<registry>/<namespace>/<image-name>:<tag>`. For example, `us.icr.io/tfu_ns/tfu_api_server:latest`. |
| 97 | +2. Push the image to the container registry with `docker push <image-name>` |
| 98 | +3. Create a Code Engine project |
| 99 | + and [deploy the image](https://cloud.ibm.com/docs/codeengine?topic=codeengine-deploy-app-crimage) |
| 100 | + |
| 101 | +## Upload the custom extension and sample actions to watsonx Assistant |
| 102 | + |
| 103 | +### Custom Extension Setup |
| 104 | + |
| 105 | +1. [Upload the extension](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-build-custom-extension). |
| 106 | + The `openapi.json` provided is for creating the extension. |
| 107 | +2. [Add the extension to the assistant](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-add-custom-extension). |
| 108 | + 1. In Authentication step, select `Bearer auth` as `Authentication type`, and fill the `Token` with the value of the |
| 109 | + environment variable `API_SERVER_KEY` that configured in `.env` file of the API server. |
| 110 | + 2. In Server variables section, enter the public URL of the API server and the port if needed. |
| 111 | + |
| 112 | +### Upload Sample Actions |
| 113 | + |
| 114 | +> Uploading actions will override all existing actions in the assistant. |
| 115 | +
|
| 116 | +We provided the following sample actions to demonstrate how you can access the uploaded file in the WA actions. |
| 117 | + |
| 118 | +| WA Action Name | WA Trigger Word | Description | |
| 119 | +|----------------------|-----------------|------------------------------------------------------------------------------------------------------------| |
| 120 | +| Upload to WD | "upload" | Upload or append one or more files to current session. | |
| 121 | +| Check File Status | "file status" | Check the info of the uploaded files in current session, and also their process status on Watson Discovery | |
| 122 | +| Summarize | "summarize" | Summarize the file content with watsonx.ai foundation models. | |
| 123 | +| Search | "search" | Search the file content with Watson Discovery. | |
| 124 | +| Clear Uploaded Files | "clear" | Clear the uploaded files by create a new session. | |
| 125 | + |
| 126 | +To upload the actions: |
| 127 | + |
| 128 | +1. Zip `action-skill.json` into a zip file `action-skill.zip` for uploading. |
| 129 | +2. [Uploading all actions](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-upload-download-actions) |
| 130 | + |
| 131 | +## Integrate the watsonx Assistant with Microsoft Teams |
| 132 | + |
| 133 | +Please follow this guide |
| 134 | +to [integrate watsonx Assistant with MS Teams](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-deploy-microsoft-teams). |
| 135 | + |
| 136 | +In order to support file uploading, you need to create a Teams app with **file upload** feature enabled. |
| 137 | + |
| 138 | +When following the guide above, |
| 139 | +in [Create your Teams app](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-deploy-microsoft-teams#deploy-microsoft-teams-app) |
| 140 | +section, before saving the bot configuration (step 8), you need to also enable the **Upload and download files** feature |
| 141 | +in the **What can your bot do?** section. |
| 142 | + |
| 143 | + |
| 144 | + |
| 145 | +## Example Usage |
| 146 | + |
| 147 | +### Upload files |
| 148 | + |
| 149 | +First type "upload" in the chat window, then upload a file. The file's info will be displayed in the chat window. |
| 150 | + |
| 151 | + |
| 152 | +You can type "upload" again to upload more files. The uploaded files will be appended to the current session. |
| 153 | + |
| 154 | + |
| 155 | +### Check file status |
| 156 | + |
| 157 | +Type "file status" in the chat window, and the file's info and process status will be displayed in the chat window. |
| 158 | +Note that files has been processed by WD (with status `available`) and is now available for search. |
| 159 | + |
| 160 | + |
| 161 | + |
| 162 | +### Summarize |
| 163 | + |
| 164 | +Type "summarize" in the chat window, select the file you want to summarize, and the summary will be displayed in the |
| 165 | +chat window after a few seconds. |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +### Search |
| 170 | + |
| 171 | +Type "search" in the chat window, select the file you want to search, and then enter your search query. The search |
| 172 | +result will be displayed in the chat window after a few seconds. |
| 173 | + |
| 174 | + |
0 commit comments