diff --git a/integrations/extensions/starter-kits/language-model-watsonx/README.md b/integrations/extensions/starter-kits/language-model-watsonx/README.md index d0e4d722..ee93fe1a 100644 --- a/integrations/extensions/starter-kits/language-model-watsonx/README.md +++ b/integrations/extensions/starter-kits/language-model-watsonx/README.md @@ -13,14 +13,17 @@ The watsonx specification in the starter kit describes one endpoint and a few of | Endpoint | Description | | ---------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Generation | Used with watsonx text completion models such as `google/flan-ul2` and `google/flan-t5-xxl`. You provide text as a prompt, and it returns the text that follows that prompt. | +| Generation from a deployed prompt | Used with a deployed watsonx prompt. You provide the prompt deployment ID, and the prompt variables. ## Prerequisites -### Create an API key and a project ID +### Create an API key, project ID, and prompt deployment 1. Log in to [watsonx](https://dataplatform.cloud.ibm.com/wx/home?context=wx&apps=cos&nocache=true&onboarding=true&quick_start_target=watsonx) and [generate an API key](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/ml-authentication.html?context=cpdaas). Save this API key somewhere safe and accessible. You need this API key to set up the watsonx custom extension later. 1. To find your watsonx project id, go to [watsonx.ai](https://dataplatform.test.cloud.ibm.com/wx) and find Projects/ (this could be your `sandbox`, which is created for you by default). Click on the link, then follow the Project's Manage tab (Project -> Manage -> General -> Details) to find the project id. +1. [Create your prompt](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-lab.html?context=wx&audience=wdp#creating-and-running-a-prompt) in Prompt Lab. Create the [prompt variables](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/fm-prompt-variables.html?context=wx&audience=wdp#creating-prompt-variables) you need. Once your prompt is saved, [deploy your prompt](https://dataplatform.cloud.ibm.com/docs/content/wsj/analyze-data/prompt-template-deploy.html?context=wx) and note your deployment ID. + ### Create an assistant This starter kit requires that you use the [new IBM watsonx Assistant](https://cloud.ibm.com/docs/watson-assistant?topic=watson-assistant-welcome-new-assistant). @@ -63,6 +66,7 @@ The starter kit includes [a JSON file with sample actions](./watsonx-actions.jso | ----------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Invoke watsonx Generation API | Connects to watson.ai with the selected model and the model input | | Invoke watsonx Generation Stream API | Connects to watsonx.ai with the selected model and model input and streams the response back to the user. | +| Invoke watsonx Deployed Prompt API | Connects to the deployed prompt using the specified deployment ID and prompt variables. | | Test model | Simple test action that asks what model, length, temperature, prompt you want, asks if you want to stream the response and then calls "Invoke watsonx Generation API" or "Invoke watsonx Generation Stream API" based on if streaming was required so the model can generate a response to the specified prompt. | | No Action Matches | This is created by watsonx Assistant, but for this starter kit it is configured to trigger the "Invoke watsonx Generation Stream API" as a sub-action using the defaults and the user input. | @@ -94,6 +98,19 @@ Here is an example of how to use the `Test model` action: +
+ +Here is an example of how to use the `Invoke watsonx Deployed Prompt API` action: + +1. Set the `deployment-id`. +2. For `parameters.prompt_variables`: + - Use the expression: `{ "input": "1. What is your Prompt ", "name": "" }` + - Replace the key-value pairs with the appropriate variables from your deployed prompt. + +This setup allows you to use a deployed watsonx prompt with any number of prompt variables, passing the user's input as a variable to generate a response for example. + + + ### Limitations Adding large values for max_new_tokens & min_new_tokens can result in timeouts, if you see any timeouts please adjust the values of those tokens. diff --git a/integrations/extensions/starter-kits/language-model-watsonx/assets/deployed_prompt_example.png b/integrations/extensions/starter-kits/language-model-watsonx/assets/deployed_prompt_example.png new file mode 100644 index 00000000..3d4a04bd Binary files /dev/null and b/integrations/extensions/starter-kits/language-model-watsonx/assets/deployed_prompt_example.png differ diff --git a/integrations/extensions/starter-kits/language-model-watsonx/watsonx-actions.json b/integrations/extensions/starter-kits/language-model-watsonx/watsonx-actions.json index c1d07e2d..9bff5ff2 100644 --- a/integrations/extensions/starter-kits/language-model-watsonx/watsonx-actions.json +++ b/integrations/extensions/starter-kits/language-model-watsonx/watsonx-actions.json @@ -3,8 +3,8 @@ "type": "action", "valid": true, "status": "Available", - "created": "2024-06-21T14:17:07.728Z", - "updated": "2024-07-11T17:16:52.580Z", + "created": "2024-10-10T08:10:42.574Z", + "updated": "2024-10-15T11:44:57.580Z", "language": "en", "skill_id": "fb7c641b-64b5-42cf-b57f-95f4b2d8c1d4", "workspace": { @@ -788,9 +788,9 @@ "type": "integration_interaction", "method": "POST", "internal": { - "spec_hash_id": "a0c4bc7edb01c8ff165651f82ee8f51064aae76f6a5f399126ad8e14dfe2469a", - "match_scenario": 5, - "catalog_item_id": "0aaa8850-fc91-41e5-81a1-ccd139799bb3" + "spec_hash_id": "3408d5415323ca392bb94b1fdfd03f6259f0ff1e35a65e5750e2740ba2908435", + "match_scenario": 10, + "catalog_item_id": "1ed41f7c-8373-4a95-af6b-21498918cdf0" }, "request_mapping": { "body": [ @@ -829,6 +829,18 @@ "skill_variable": "model_parameters_min_new_tokens" }, "parameter": "parameters.min_new_tokens" + }, + { + "value": { + "skill_variable": "model_parameters_stop_sequences" + }, + "parameter": "parameters.stop_sequences" + }, + { + "value": { + "skill_variable": "model_parameters_repetition_penalty" + }, + "parameter": "parameters.repetition_penalty" } ], "query": [ @@ -991,9 +1003,9 @@ "type": "integration_interaction", "method": "POST", "internal": { - "spec_hash_id": "a0c4bc7edb01c8ff165651f82ee8f51064aae76f6a5f399126ad8e14dfe2469a", - "match_scenario": 5, - "catalog_item_id": "0aaa8850-fc91-41e5-81a1-ccd139799bb3" + "spec_hash_id": "5c85784df236387770379b6901bb0de4c0bd69368a0950a675f8e507c38196de", + "match_scenario": 10, + "catalog_item_id": "1ed41f7c-8373-4a95-af6b-21498918cdf0" }, "request_mapping": { "body": [ @@ -1015,6 +1027,12 @@ }, "parameter": "project_id" }, + { + "value": { + "skill_variable": "model_parameters_temperature" + }, + "parameter": "parameters.temperature" + }, { "value": { "skill_variable": "model_parameters_max_new_tokens" @@ -1029,9 +1047,15 @@ }, { "value": { - "skill_variable": "model_parameters_temperature" + "skill_variable": "model_parameters_stop_sequences" }, - "parameter": "parameters.temperature" + "parameter": "parameters.stop_sequences" + }, + { + "value": { + "skill_variable": "model_parameters_repetition_penalty" + }, + "parameter": "parameters.repetition_penalty" } ], "query": [ @@ -1143,6 +1167,223 @@ "data_type": "any" } ], + "next_action": "action_3200-4", + "topic_switch": { + "allowed_from": true, + "allowed_into": true, + "never_return": false + }, + "disambiguation_opt_out": false + }, + { + "type": "standard", + "steps": [ + { + "step": "step_931", + "output": { + "generic": [ + { + "values": [ + { + "text_expression": { + "concat": [ + { + "scalar": "What is your Prompt?" + } + ] + } + } + ], + "response_type": "text", + "selection_policy": "sequential" + } + ] + }, + "handlers": [], + "question": { + "free_text": true + }, + "resolver": { + "type": "continue" + }, + "variable": "step_931", + "next_step": "step_817" + }, + { + "step": "step_817", + "output": { + "generic": [] + }, + "context": { + "variables": [] + }, + "handlers": [], + "resolver": { + "type": "callout", + "callout": { + "path": "/ml/v1/deployments/{deployment-id}/text/generation", + "type": "integration_interaction", + "method": "POST", + "internal": { + "spec_hash_id": "08f952f1e1a902a59aea69ad2b9df9a2e2d31b83fd62d1aefa68caab41fb4f5e", + "match_scenario": 10, + "catalog_item_id": "1ed41f7c-8373-4a95-af6b-21498918cdf0" + }, + "request_mapping": { + "body": [ + { + "value": { + "expression": "{\"input\":\"${step_931}\"}" + }, + "parameter": "parameters.prompt_variables" + } + ], + "path": [ + { + "value": { + "scalar": "testing_prompt_deployment" + }, + "parameter": "deployment-id" + } + ], + "query": [ + { + "value": { + "skill_variable": "watsonx_api_version" + }, + "parameter": "version" + } + ] + }, + "result_variable": "step_817_result_2" + } + }, + "variable": "step_817", + "next_step": "step_606" + }, + { + "step": "step_606", + "output": { + "generic": [ + { + "values": [ + { + "text_expression": { + "concat": [ + { + "scalar": "" + }, + { + "skill_variable": "model_response" + } + ] + } + } + ], + "response_type": "text", + "selection_policy": "sequential" + } + ] + }, + "context": { + "variables": [ + { + "value": { + "expression": "${step_817_result_2.body.results}[0].generated_text" + }, + "skill_variable": "model_response" + } + ] + }, + "handlers": [], + "resolver": { + "type": "end_action" + }, + "variable": "step_606", + "condition": { + "and": [ + { + "eq": [ + { + "variable": "step_817_result_2", + "variable_path": "success" + }, + { + "scalar": true + } + ] + }, + { + "expression": "${step_817_result_2.body.results}.size() > 0" + } + ] + }, + "next_step": "step_212" + }, + { + "step": "step_212", + "output": { + "generic": [] + }, + "context": { + "variables": [ + { + "value": { + "expression": "null" + }, + "skill_variable": "model_response" + } + ] + }, + "handlers": [], + "resolver": { + "type": "end_action" + }, + "variable": "step_212" + } + ], + "title": "Invoke watsonx Deployed Prompt API", + "action": "action_3200-4", + "boosts": [], + "handlers": [], + "condition": { + "intent": "action_3200_intent_45093-4" + }, + "variables": [ + { + "title": "", + "variable": "step_212", + "data_type": "any" + }, + { + "title": "{variable}", + "variable": "step_606", + "data_type": "any" + }, + { + "title": "No response", + "privacy": { + "enabled": false + }, + "variable": "step_817", + "data_type": "any" + }, + { + "privacy": { + "enabled": false + }, + "variable": "step_817_result_2", + "data_type": "any" + }, + { + "title": "What is your Prompt?", + "privacy": { + "enabled": false + }, + "variable": "step_931", + "data_type": "any" + } + ], "next_action": "fallback", "topic_switch": { "allowed_from": true, @@ -1707,6 +1948,14 @@ "intent": "action_3200_intent_45093-3", "examples": [] }, + { + "intent": "action_3200_intent_45093-4", + "examples": [ + { + "text": "Invoke watsonx Deployed Prompt API" + } + ] + }, { "intent": "fallback_connect_to_agent", "examples": [ @@ -1783,7 +2032,7 @@ "metadata": { "api_version": { "major_version": "v2", - "minor_version": "2021-11-27" + "minor_version": "2018-11-08" } }, "variables": [ @@ -1983,9 +2232,9 @@ "learning_opt_out": true }, "description": "created for assistant 05c10d7d-336f-4d33-8cb3-5c53520d61ce", - "assistant_id": "577b3f36-98da-454c-becb-88970e3bec89", - "workspace_id": "fb7c641b-64b5-42cf-b57f-95f4b2d8c1d4", + "assistant_id": "0401c2c3-3bde-4465-8ac1-d77e093c000c", + "workspace_id": "c9ed31a7-e240-433d-bc69-74c42c2b6fd2", "dialog_settings": {}, "next_snapshot_version": "1", - "environment_id": "782f075c-8d40-4396-95ca-70fb6b11a544" + "environment_id": "7a0b7575-6b2c-42c7-83de-c7fd1cfa0be5" } \ No newline at end of file diff --git a/integrations/extensions/starter-kits/language-model-watsonx/watsonx-openapi.json b/integrations/extensions/starter-kits/language-model-watsonx/watsonx-openapi.json index da9d137f..747810c2 100644 --- a/integrations/extensions/starter-kits/language-model-watsonx/watsonx-openapi.json +++ b/integrations/extensions/starter-kits/language-model-watsonx/watsonx-openapi.json @@ -108,6 +108,107 @@ } } } + }, + "/ml/v1/deployments/{deployment-id}/text/generation": { + "post": { + "description": "Generation from a deployed prompt", + "parameters": [ + { + "name": "version", + "in": "query", + "description": "Release date of the version of the API you want to use. Specify dates in YYYY-MM-DD format.", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "deployment-id", + "in": "path", + "description": "Deployment ID of the prompt deployment you want to use.", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "parameters": { + "type": "object", + "properties": { + "prompt_variables": { + "type": "object", + "description": "The object containing key-value pairs that contain the prompt variables", + "additionalProperties": true, + "example": { + "input": "Who is the president of the United States?", + "name": "Nabil", + "company": "IBM" + } + } + } + } + } + } + } + } + }, + "responses": { + "200": { + "description": "Default Response", + "content": { + "application/json": { + "schema": { + "type": "object", + "properties": { + "model_id": { + "description": "The ID of the model to be used for this request", + "type": "string" + }, + "created_at": { + "description": "The date and time of the response", + "type": "string" + }, + "results": { + "type": "array", + "items": { + "type": "object", + "properties": { + "generated_text": { + "description": "The generated text", + "type": "string" + }, + "generated_token_count": { + "description": "The number of tokens in the output", + "type": "integer" + }, + "input_token_count": { + "description": "The number of tokens in the input", + "type": "integer" + }, + "stop_reason": { + "description": "The reason for stopping the generation. Can be NOT_FINISHED - Possibly more tokens to be streamed, MAX_TOKENS - Maximum requested tokens reached, EOS_TOKEN - End of sequence token encountered, CANCELLED - Request canceled by the client, TIME_LIMIT - Time limit reached, STOP_SEQUENCE - Stop sequence encountered, TOKEN_LIMIT - Token limit reached, ERROR - Error encountered", + "type": "string" + } + } + }, + "description": "Outputs of the generation" + } + } + } + } + } + }, + "default": { + "description": "Unexpected error" + } + } + } } }, "components": {