Skip to content

Commit

Permalink
feat(watsonx): add an optional params for min_new_tokens, repetition_…
Browse files Browse the repository at this point in the history
…penalty & stop_sequences (watson-developer-cloud#178)

* feat(watsonx): add an optional param for min_new_tokens

* fix: default values

* fix: session vars

* feat: add new param repetition_penalty

* feat: add another param Stopping Criteria

* fix: nmber validation and ask 3 times

* readme

* fix: update openAPI spec to 1.0.1 & action fixes

---------

Co-authored-by: Anirudha Bapat <[email protected]>
  • Loading branch information
anirudhaBapat and anibapat committed Jul 21, 2023
1 parent ae9b77e commit f95c1b7
Show file tree
Hide file tree
Showing 3 changed files with 246 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,19 @@ These are the session variables used in this example.

- `model_id`: The id of the watsonx model that you select for this action. Defaults to `google/flan-ul2`.
- `model_input`: The input to the model.
- `model_parameters_max_new_tokens` : The maximum number of new tokens to be generated. Defaults to 20.
- `model_parameters_temperature` : The value used to control the next token probabilities. The range is from 0.05 to 1.00; 0.05 makes it _mostly_ deterministic.
- `model_parameters_max_new_tokens` : The maximum number of new tokens to be generated. Defaults to 300.
- `model_parameters_min_new_tokens`: The minimum number of the new tokens to be generated. Defaults to 1.
- `model_parameters_temperature` : The value used to control the next token probabilities. The range is from 0.05 to 1.00; 0 makes it _mostly_ deterministic.
- `model_parameters_repetition_penalty`: Represents the penalty for penalizing tokens that have already been generated or belong to the context. The range is 1.0 to 2.0 and defaults to 1.1.
- `model_parameters_stop_sequences`: Stop sequences are one or more strings which will cause the text generation to stop if/when they are produced as part of the output. Stop sequences encountered prior to the minimum number of tokens being generated will be ignored. The list may contain up to 6 strings. Defaults to ["\n\n"]
- `model_response`: The text generated by the model in response to the user input.
- `watsonx_api_version` - watsonx api date version. It currently defaults to `2023-05-29`.
- `watsonx_project_id`: You **MUST** set this value to be [a project ID value from watsonx](https://dataplatform.cloud.ibm.com/docs/content/wsj/manage-data/manage-projects.html). By default, this is a [sandbox project id](https://dataplatform.cloud.ibm.com/docs/content/wsj/manage-data/sandbox.html) that is automatically created for you when you sign up for watsonx.ai.

Here is an example of how to use the `Test model` action:

<img src="./assets/sample.png" width="300"/>

### 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.
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"type": "action",
"valid": true,
"status": "Available",
"created": "2023-07-18T13:36:37.767Z",
"updated": "2023-07-18T21:22:48.224Z",
"created": "2023-07-21T23:27:18.637Z",
"updated": "2023-07-21T23:31:17.833Z",
"language": "en",
"skill_id": "9c3433c1-f60d-4f0a-9648-9b43a23100de",
"skill_id": "096d12a9-3b20-43ac-bc18-9d2e4c79ec1a",
"workspace": {
"actions": [
{
Expand Down Expand Up @@ -112,7 +112,8 @@
}
],
"response_type": "text",
"selection_policy": "sequential"
"selection_policy": "sequential",
"repeat_on_reprompt": true
}
]
},
Expand All @@ -128,10 +129,17 @@
{
"values": [
{
"text": "I didn't catch that. Enter a number."
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number between 1 to 1024"
}
]
}
}
],
"response_type": "text"
"response_type": "text",
"selection_policy": "incremental"
}
]
},
Expand All @@ -150,7 +158,7 @@
{
"name": "maximum",
"value": {
"scalar": 4000
"scalar": 1024
}
}
]
Expand All @@ -163,10 +171,17 @@
{
"values": [
{
"text": "I didn't catch that. Enter a number."
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number between 1 to 1024"
}
]
}
}
],
"response_type": "text"
"response_type": "text",
"selection_policy": "incremental"
}
]
},
Expand All @@ -193,6 +208,118 @@
"type": "continue"
},
"variable": "step_333",
"next_step": "step_577"
},
{
"step": "step_577",
"output": {
"generic": [
{
"values": [
{
"text_expression": {
"concat": [
{
"scalar": "How many minimum tokens do you want to generate?"
}
]
}
}
],
"response_type": "text",
"selection_policy": "sequential",
"repeat_on_reprompt": false
}
]
},
"handlers": [
{
"type": "input_validation",
"title": "input_validation_handler_1",
"output": {
"generic": [
{
"values": [
{
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number between 0 to 1024"
}
]
}
}
],
"response_type": "text",
"selection_policy": "incremental"
}
]
},
"handler": "input_validation_handler_1",
"resolver": {
"type": "prompt_again"
},
"next_handler": "validation_not_found_handler",
"input_constraints": [
{
"name": "maximum",
"value": {
"scalar": 1024
}
},
{
"name": "minimum",
"value": {
"scalar": 0
}
}
]
},
{
"type": "not_found",
"title": "validation_not_found_handler",
"output": {
"generic": [
{
"values": [
{
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number between 0 to 1024"
}
]
}
}
],
"response_type": "text",
"selection_policy": "incremental"
}
]
},
"handler": "validation_not_found_handler",
"resolver": {
"type": "prompt_again"
},
"next_handler": "validation_not_found_max_tries_handler"
},
{
"type": "not_found_max_tries",
"title": "validation_not_found_max_tries_handler",
"handler": "validation_not_found_max_tries_handler",
"resolver": {
"type": "fallback"
}
}
],
"question": {
"entity": "sys-number",
"max_tries": 3
},
"resolver": {
"type": "continue"
},
"variable": "step_577",
"next_step": "step_605"
},
{
Expand All @@ -212,7 +339,8 @@
}
],
"response_type": "text",
"selection_policy": "sequential"
"selection_policy": "sequential",
"repeat_on_reprompt": false
}
]
},
Expand All @@ -225,10 +353,17 @@
{
"values": [
{
"text": "I didn't catch that. Enter a number."
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number."
}
]
}
}
],
"response_type": "text"
"response_type": "text",
"selection_policy": "incremental"
}
]
},
Expand Down Expand Up @@ -260,10 +395,17 @@
{
"values": [
{
"text": "I didn't catch that. Enter a number."
"text_expression": {
"concat": [
{
"scalar": "I didn't catch that. Enter a number."
}
]
}
}
],
"response_type": "text"
"response_type": "text",
"selection_policy": "incremental"
}
]
},
Expand Down Expand Up @@ -346,6 +488,12 @@
},
"skill_variable": "model_parameters_max_new_tokens"
},
{
"value": {
"variable": "step_577"
},
"skill_variable": "model_parameters_min_new_tokens"
},
{
"value": {
"variable": "step_605"
Expand All @@ -365,6 +513,7 @@
"type": "invoke_another_action",
"invoke_action": {
"action": "action_3200-2",
"policy": "default",
"parameters": null,
"result_variable": "step_817_result_1"
}
Expand Down Expand Up @@ -429,6 +578,11 @@
"variable": "step_333",
"data_type": "number"
},
{
"title": "How many minimum tokens do you want to generate?",
"variable": "step_577",
"data_type": "number"
},
{
"title": "What temperature do you want to use?",
"variable": "step_605",
Expand Down Expand Up @@ -475,8 +629,8 @@
"type": "integration_interaction",
"method": "POST",
"internal": {
"spec_hash_id": "f22a973be9c24f524794f9f86d114b5fe9e4e1168ae47ea950e4d7889e972125",
"catalog_item_id": "3a1fabde-51ff-42cc-ad27-23b965370021"
"spec_hash_id": "efd13c68dff079388ffa62bfc3aff447e49efd7024450961cc74d6de89106cce",
"catalog_item_id": "f53a6acc-4505-45a5-a785-27fe357b96da"
},
"request_mapping": {
"body": [
Expand Down Expand Up @@ -509,6 +663,24 @@
"skill_variable": "model_parameters_max_new_tokens"
},
"parameter": "parameters.max_new_tokens"
},
{
"value": {
"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": [
Expand Down Expand Up @@ -678,6 +850,7 @@
"type": "invoke_another_action_and_end",
"invoke_action": {
"action": "fallback",
"policy": "default",
"parameters": null,
"result_variable": "step_002_result_1"
}
Expand Down Expand Up @@ -1241,7 +1414,34 @@
"data_type": "number",
"description": "The maximum number of new tokens to be generated.",
"initial_value": {
"scalar": 20
"scalar": 300
}
},
{
"title": "model_parameters_min_new_tokens",
"variable": "model_parameters_min_new_tokens",
"data_type": "number",
"description": "",
"initial_value": {
"scalar": 1
}
},
{
"title": "model_parameters_repetition_penalty",
"variable": "model_parameters_repetition_penalty",
"data_type": "number",
"description": "",
"initial_value": {
"scalar": 1.1
}
},
{
"title": "model_parameters_stop_sequences",
"variable": "model_parameters_stop_sequences",
"data_type": "any",
"description": "",
"initial_value": {
"expression": "[\"\\n\\n\"]"
}
},
{
Expand All @@ -1250,7 +1450,7 @@
"data_type": "number",
"description": "The value used to module the next token probabilities. The range is 0.05 to 1.00, a value set to 0.05 would make it mostly deterministic.",
"initial_value": {
"scalar": 0.05
"scalar": 0
}
},
{
Expand Down Expand Up @@ -1380,8 +1580,8 @@
"learning_opt_out": true
},
"description": "created for assistant 05c10d7d-336f-4d33-8cb3-5c53520d61ce",
"assistant_id": "3b229721-63a8-4e2e-8aa1-380654a5cdb0",
"workspace_id": "9c3433c1-f60d-4f0a-9648-9b43a23100de",
"assistant_id": "69f5847f-17c6-4cb0-bafe-e1c3e5f7cfd2",
"workspace_id": "096d12a9-3b20-43ac-bc18-9d2e4c79ec1a",
"dialog_settings": {},
"next_snapshot_version": "1"
}
Loading

0 comments on commit f95c1b7

Please sign in to comment.