Skip to content

Commit

Permalink
feat: Watson Assistant + Watson Discovery + PaLM starter kit (watson-…
Browse files Browse the repository at this point in the history
…developer-cloud#150)

* feat: WA + WD + PaLM

* fix: rewording

* fix: remove discovery project id

---------

Co-authored-by: Anirudha Bapat <[email protected]>
  • Loading branch information
anirudhaBapat and anibapat committed Jul 10, 2023
1 parent 2c30249 commit 65d75b7
Show file tree
Hide file tree
Showing 4 changed files with 1,779 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,65 @@ If you want to experiment with different prompts or language models for the Open
Here is an example of how to use the `Search` action for this starter kit advanced conversational search example:

<img src="./assets/discovery-openai-example.png" width="300"/>

## Example 4: Connect your assistant to Watson Discovery and PaLM via custom extensions

This starter kit example shows how to configure your assistant to use Watson Discovery for document search, and then use those search results as input context for Google PaLM (Powerful Language Model). The PaLM generates a natural language answer for the query based on the documents provided by the search. The use of the PaLM API in this example was not made in partnership with, sponsorship with, or with endorsement from Google.

Before you upload the sample action for this starter kit, you first need to configure two custom extensions: [Watson Discovery](../watson-discovery/README.md) and [PaLM](../language-model-palm-api/README.md).

Follow the steps in the following two sections to configure your extensions before proceeding.

### Configure Watson Discovery extension

Follow the steps [here](#configure-watson-discovery-extension) to configure the Watson Discovery extension.

### Configure the PaLM answer generation extension

Follow the steps [here](../language-model-palm-api/README.md) to configure PaLM as a custom extension.

### Upload sample action

The starter kit includes [a JSON file with these sample actions](./discovery-palm-actions.json):

| Action | Description |
| --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Search | Connects to Watson Discovery to search for documents related to the user query. The "No Action Matches" action has been configured to send all input to this action, so whatever the user enters will be used as the search input. It invokes the "Generate Answer" action to generate a response to the query. |
| Generate Answer | Configures the query prompt and document passages resulting from search, and calls the action "Invoke PaLM ". It is not meant to be invoked directly, but rather by the "Search" action. |
| Invoke PaLM | Connects to PaLM api and, using as context the documents resulting from the search, asks the language model to generate an answer to the user query. It is not meant to be invoked directly, but rather by the "Generate Answer" action. |

To use the sample actions:

1. **After having configured both extensions**, download the sample actions from this starter kit: [`discovery-palm-actions.json`](./discovery-palm-actions.json).

1. Use **Actions Global Settings** to upload the JSON file to your assistant. For more information, see [Uploading](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-admin-backup-restore#backup-restore-import).

1. Under "Variables"/"Created by you" (within the Actions page), set the `discovery_project_id` session variable using the project ID value you obtained [when configuring Watson Discovery above](#configure-watson-discovery-extension).

**NOTE**: If you import the actions _before_ configuring the extensions, you will see some errors on the actions because it could not find the extensions. Simply configure the extensions as described above and re-import the action JSON file.

#### Session variables

Below is a list of the session variables used in this example. Most of them are automatically set with defaults in the sample [discovery-palm-actions.json](discovery-palm-actions.json), so you do not need to set them yourself unless you want to make changes. You must, however, [set](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-manage-info#store-session-variable) the `discovery_project_id` to point to the project id for your Watson Discovery collection, as noted above.

- `discovery_date_version` - Discovery date versions are documented in the [release notes](https://cloud.ibm.com/docs/discovery-data?topic=discovery-data-release-notes).
- `discovery_project_id`: You **MUST** set this value to be the project ID obtained [when configuring Watson Discovery above](#configure-watson-discovery-extension).
- `model_prompt`: You MAY change this to do prompt engineering, but a default will be used by the model if you don’t pass a prompt here.
- `model_response`: The text generated by the model in response to the `messages`.
- `passages` : Concatenation of top search results.
- `query_text`: You MAY change this to pass queries to Watson Discovery. By default the Search action passes the user’s input.text directly.
- `search_results`: Response object from [Discovery query](https://cloud.ibm.com/apidocs/discovery-data#query).
- `snippet` : Top results from the Watson Discovery document search.

### Language model

In this example We found the chat model, which is `chat-Bison-001`, to be more prone to making up information when we tested it & hence for this example, we have used PaLM's text generation model, which is `text-Bison-001`.
However, if you want to experiment and use PaLM's chat language model, which is `chat-Bison-001`, you can change the operation of the PaLM extension in the 'Invoke PaLM' action in step 1 and click on 'edit extension' as shown below.

<img src="./assets/discovery-palm-language-model-change-example.png" width="300"/>

### Example 4 usage

Here is an example of how to use the `Search` action for this starter kit advanced conversational search example:

<img src="./assets/discovery-palm-example.png" width="300"/>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 65d75b7

Please sign in to comment.