vania-janet/multiturn-rag-retrieval-data huggingface dataset:
Accessing REST API calls with pacclient.py 

IBM Spectrum LSF Application Center provides standard RESTful web services for application submission, data management, job information query, job actions, and more. The LSF Applicationn Center web service API can be integrated with many languages and methods. This example shows how to access the LSF Application Center REST API calls by using [pacclient.py](https://www.ibm.com/docs/en/slac/10.2.0?topic=services-pacclientpy), which is a Python 3-based client.

This example assumes that the LSF Application Center is configured to use the REST APIs through http. For more information, see [LSF Application Center Web Services](https://www.ibm.com/docs/en/slac/10.2.0?topic=lsf-application-center-web-services).



 Before you begin 

Before you can connect to the LSF Application Center with http, you need to complete the following steps:



1. To access the LSF Application Center REST APIs from your device, you need to set up an SSH connection. You can connect to an LSF management node through a new command-line terminal from your local device. The Schematics log output contains the LSF Application Center information that you need.

ssh -L 8080:localhost:8080 -J root@{FLOATING_IP_ADDRESS} lsfadmin@{MANAGEMENT_NODE_IP_ADDRESS}

where MANAGEMENT_NODE_IP_ADDRESS needs to be replaced with the management node IP address that is associated with <cluster_prefix>-management-host-0, and FLOATING_IP_ADDRESS needs to be replaced with the login node floating IP address. To find the management and login node IPs, see the instructions for [Gathering IP addresses](https://cloud.ibm.com/docs/ibm-spectrum-lsf?topic=ibm-spectrum-lsf-accessing-lsf-guigathering-ip-addresses).
2. Open a second terminal and download and install Python 3.6 or newer. The following examples are for Linux and MAC systems.
[The synchronous HTTP interface](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-http) provides the simplest way to make a recognition request. You use the POST /v1/recognize method to make a request to the service. You pass the audio and all parameters with the single request. The following curl example shows a basic HTTP recognition request:

IBM Cloud

curl -X POST -u "apikey:{apikey}" --header "Content-Type: audio/flac" --data-binary @audio-file.flac "{url}/v1/recognize"

IBM Cloud Pak for Data

curl -X POST --header "Authorization: Bearer {token}" --header "Content-Type: audio/flac" --data-binary @audio-file.flac "{url}/v1/recognize"





 Using the asynchronous HTTP interface 

[The asynchronous HTTP interface](https://cloud.ibm.com/docs/speech-to-text?topic=speech-to-text-async) provides a non-blocking interface for transcribing audio. You can use the interface with or without first registering a callback URL with the service. With a callback URL, the service sends callback notifications with job status and recognition results. The interface uses HMAC-SHA1 signatures based on a user-specified secret to provide authentication and data integrity for its notifications. Without a callback URL, you must poll the service for job status and results. With either approach, you use the POST /v1/recognitions method to make a recognition request.

The following curl example shows a simple asynchronous HTTP recognition request. The request does not include a callback URL, so you must poll the service to get the job status and the resulting transcript.

IBM Cloud

curl -X POST -u "apikey:{apikey}" --header "Content-Type: audio/flac" --data-binary @audio-file.flac "{url}/v1/recognitions"

IBM Cloud Pak for Data
The following sample shows how a simple request body is formatted.

{
"event": {
"name": "message_processed"
},
"options": {},
"payload": {
"output": {
"intents": [
{
"intent": "General_Greetings",
"confidence": 1
}
],
"entities": [],
"generic": [
{
"response_type": "text",
"text": "Hello. Good evening"
}
]
},
"user_id": "test user",
"context": {
"global": {
"system": {
"user_id": "test user",
"turn_count": 11
},
"session_id": "sxxx"
},
"skills": {
"main skill": {
"user_defined": {
"var": "anthony"
},
"system": {
"state": "nnn"
}
}
}
}
}
Show more





 Example 1 

This example shows you how to add y'all to the end of each response from the assistant.

In the postmessage webhook configuration page, the following values are specified:



* URL: https://us-south.functions.appdomain.cloud/api/v1/web/e97d2516-5ce4-4fd9-9d05-acc3dd8ennn/southernize/add_southern_charm
* Secret: none
* Header name: Content-Type
* Header value: application/json



The postmessage webhook calls an IBM Cloud Functions web action name add_southern_charm.

The node.js code in the add_southern_charm web action looks as follows:

function main(params) {
console.log(JSON.stringify(params))
const response = await axios(options);
const responseData = response.data;
console.log("nGenerated an IAM token..");
return responseData.access_token;
}

// Get a public key to verify notifications
async function getPublicKey() {
const accessToken = await getIAMToken();

const options = {
method: 'GET',
url: '<event_notifications_endpoint_url>/destinations/<destination_id>/public_key',
headers: {
'authorization': 'Bearer ' + accessToken
}
};

const response = await axios(options);
const responseData = response.data;
console.log('nRetrieved a public key from Event Notifications..');
return responseData.public_key;
}

function getDate(timestamp) {
return new Date(timestamp).toDateString();
}

// Build a GitHub issue description according to the event type
function createIssueBody(decodedNotification) {
if (decodedNotification.event_type === "test_event") // Remove this option later if you don't want to create issues for test events
return This is a test notification from ${decodedNotification.source_service}.;
if (decodedNotification.event_type === "secret_about_to_expire")
return The following certificate(s) expire on ${getDate(decodedNotification.secrets_expiration_date)}:
${decodedNotification.secrets.reduce((accumulator, currentValue) => {
return accumulator + 
> Domain(s): ${currentValue.domains}
Secret ID: ${currentValue.secret_id}
Secret name: ${currentValue.secret_name}
;
}, "")};
The Adapter can be used in collaboration with the OAuth 2.0 [JWT Bearer flow](https://datatracker.ietf.org/doc/html/rfc6750) to protect service APIs by validating JWT Bearer tokens. The Bearer authorization flow expects a request to contain an Authorization header with a valid access token and an optional identity token. The expected header structure is Authorization=Bearer {access_token} [{id_token}]. Unauthenticated clients are returned an HTTP 401 response status with a list of the scopes that are needed to obtain authorization. If the tokens are invalid or expired, the API strategy returns an HTTP 401 response with an optional error component that says Www-Authenticate=Bearer scope="{scope}" error="{error}".

For more information about tokens and how they're used, see [understanding tokens](https://cloud.ibm.com/docs/appid?topic=appid-tokens).







 Before you begin 

Before you get started, be sure that you installed the following prerequisites.



* A paid [Kubernetes Cluster](https://kubernetes.io/)
* [Helm](https://helm.sh/)
* [Istio v1.1+](https://istio.io/latest/docs/setup/install/)

Currently, [IBM Cloud Kubernetes Service Managed Istio](https://cloud.ibm.com/docs/containers?topic=containers-istio) does not support policy enforcement. To use the Adapter, you must use manually installed Istio.







 Installing the Adapter 

To install the chart, initialize Helm in your cluster, define the options that you want to use, and then run the installation command.



1. If you're working with IBM Cloud Kubernetes Service, be sure to log in and set the context for your cluster.
2. Verify that you enabled [Istio policy enforcement](https://istio.io/v1.4/docs/tasks/policy-enforcement/enabling-policy/).
Only changed parameters are overwritten; any other configuration parameters are unchanged.<br> * merge_once: Merges the new configuration with the existing configuration only for the next turn of the conversation. Subsequently, the previous configuration is used.<br><br><br> no replace 



The parameters that you can set for synthesize reflect the parameters that are made available by the Text to Speech WebSocket interface. The WebSocket API sends two types of parameters: query parameters, which are sent when phone integration connects to the service, and message parameters, which are sent as part of the JSON data in the request body. For a full list of parameters, see the [Text to Speech API documentation](https://cloud.ibm.com/apidocs/text-to-speech).





 command_info.type : disable_barge_in 

Disables speech barge-in so that playback isn't interrupted when the caller speaks while audio is being played back.

No parameters.





 command_info.type : enable_barge_in 

Enables speech barge-in so that callers can interrupt playback by speaking.

No parameters.





 Changing the assistant's voice 

You can change the voice of your assistant when it covers certain topics in the conversation that warrant it. For example, you might want to use a voice with a British accent for a branch of the conversation that applies only to customers in the UK.

This example shows how to specify a voice during the conversation:

{
"output": {
"generic": [
{
"response_type": "text_to_speech",
"command_info": {
"type": "configure",
"parameters": {
"synthesize": {
"voice": "en-GB_KateV3Voice"
}
}
}
}
]
}
}

Show more

In the voice parameter, specify the voice model that you want to use.
For more information, see [Private network endpoints](https://cloud.ibm.com/docs/assistant?topic=assistant-securitysecurity-private-endpoints).



 Defining the webhook 

You can define one webhook URL to use for logging every incoming message or CDR event.

The programmatic call to the external service must meet these requirements:



* The call must be a POST HTTP request.



To add the webhook details, complete the following steps:



1. From your assistant, click the ![Overflow menu](https://cloud.ibm.com/docs-content/v1/content/417db917d18067d9dcc4cf2612564a9a87c3ddc8/assistant/images/kebab.png) icon, and then choose Settings.
2. Click Webhooks > Log webhook.
3. Set the Log webhook switch to Enabled.

If you cannot enable the webhook, you might need to upgrade your service plan.
4. In the URL field, add the URL for the external application to which you want to send HTTP POST request callouts.

For example, to write the message to the

https://www.mycompany.com/my_log_service

You must specify a URL that uses the SSL protocol, so specify a URL that begins with https.
5. In the Secret field, add a token to pass with the request that can be used to authenticate with the external service.

The secret must be specified as a text string, such as purple unicorn. Maximum length is 1,024 characters. You cannot specify a context variable.

It is the responsibility of the external service to check for and verify the secret. If the external service does not require a secret, you can leave this field empty.

It is the responsibility of the external service to check for and verify the secret. If the external service does not require a token, specify any string you want. You cannot leave this field empty.
It can also be used to monitor service throughput. The Dashboard is simply an API client - anything that can be achieved with the dashboard can be scripted by you using the HTTP API.

That's the end of this part. The next part is called HTTP API Basics.







 HTTP API Basics video 

Learn how to use the command line to make HTTP requests and to add, edit, and delete documents.



* HTTP API Basics video script

Welcome to the Introduction to IBM Cloudant course, an 17-part video series that gives you an overview of the IBM Cloudant database-as-a-service.

This video is part 7 - HTTP API Basics.

In the previous part, we saw the IBM Cloudant Dashboard, which is a web app that is making HTTP calls to IBM Cloudant's API. In this step, we use the command line to make HTTP requests and to try to add, edit, and delete some documents from there.

It's worth understanding the HTTP API from first principles even if you intend to use the higher-level client libraries.

The advantage of a database that has an HTTP API is that any device on the internet can read and write data if you want it to. No special software is required. No drivers that speak a custom protocol. Just a standard HTTP library. For example, everything speaks HTTP:



* Web browser
* Any programming language
* Tools that you can use to write scripts from the command line like curl
* Mobile devices



We're going to learn the API by using curl, a free, open source command-line tool that can dispatch HTTP requests. Curl comes preinstalled on most Macs and Unix-like operating systems. If it's not present on your computer, Google curl and follow the installation instructions.

Let's first use curl to fetch a web page - Google's home page.



1. In a command-line terminal, type curl https://www.google.com.

You get a pageful of HTML in reply.
If this method works, then curl is installed, and you can proceed with the next tasks.
curl ’https://<region>.monitoring.cloud.ibm.com/api/notificationChannels' --header ‘Authorization: Bearer <token>’ | jq

In the output, note the id of the notification channel where the options.url field matches the URL that you previously created.

{
"id": 123,
"version": 6,
...
"options": {
"notifyOnOk": true,
"url": "https://mh-<id>.private.us-south.messagehub.appdomain.cloud",
"notifyOnResolve": true
}
},
12. Curl the Monitoring API to add the authentication header to the webhook notification channel.



* Replace <region> with the region of your Monitoring instance, such as us-east.
* Replace <id> with the ID of the notification channel that you previously retrieved.
* Replace <token> with the IAM token that you previously retrieved.



curl -X PUT ’https://<region>.monitoring.cloud.ibm.com/api/notificationChannels/<id>' 
--header ‘Content-Type: application/json’
--header ‘Authorization: Bearer <token>’ -d @/tmp/notification.json
13. Curl the Monitoring API again to confirm that the notification channel is updated with the authentication header.



* Replace <region> with the region of your Monitoring instance, such as us-east.
* Replace <token> with the IAM token that you previously retrieved.



curl ’https://<region>.monitoring.cloud.ibm.com/api/notificationChannels' --header ‘Authorization: Bearer <token>’ | jq

In the output, note the additionalHeaders.X-Auth-Token field is added to the notification channel.

{
"notificationChannel":
{
"id": 123,
....
"options": {
"notifyOnOk": true,
}
const token = jwt.sign(payload, process.env.YOUR_PRIVATE_RSA_KEY, { algorithm: 'RS256', expiresIn: '10000ms' });
return token;
}

Show more
3. The encrypted user payload is decrypted and then saved to the context.integrations.chat.private.user_payload object. For information about how to access the payload data from the dialog, see [Web chat: Accessing sensitive data](https://cloud.ibm.com/docs/assistant-data?topic=assistant-data-dialog-integrationsdialog-integrations-chat-private). You might want to access the payload, for example, to get the customer importance information or single sign-on credentials that you can subsequently use to authenticate a webhook.







 Authenticating users 

To authenticate and specify a unique ID for each customer, add the user ID information to the token.



1. From the web chat configuration page, copy the public key from the IBM provided public key field. You will specify this value as the PUBLIC_IBM_RSA_KEY later.
2. From your website, write a function that signs a JSON Web Token.

The function must accept a UserID parameter and set the userID as the sub claim value.

For example, the following NodeJS code snippet set the user's ID to L12345.

// Sample NodeJS code on your server.
const jwt = require('jsonwebtoken');
const RSA = require('node-rsa');

const rsaKey = new RSA(process.env.PUBLIC_IBM_RSA_KEY);

/
* Returns a signed JWT. Optionally, adds an encrypted user payload in stringified JSON.
/
function mockLogin() {
const payload = {
sub: 'L12345', // Required
iss: 'www.example.com' // Required
};
The webhook must be set up for each provisioned transient virtual server. However, the URI and the secret do not need to be unique.

Both parameters are required. If the URI or secret must be changed, call the method again with the new information.

The transient virtual server webhook can be set up through the SLDN API by using the following method:

SoftLayer_Virtual_Guest::setWebhook(uri, secret)

For more information, see the SLDN API method documentation for [webhook set-up](http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/setTransientWebhook/).



 Canceling reclaim-scheduled notifications 

To cancel the reclaim-scheduled notifications, call the following SLDN API method:

SoftLayer_Virtual_Guest::deleteWebhook()

For more information, see the SLDN API method documentation for [canceling notifications](http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/deleteTransientWebhook/).







 Verifying the webhook requests 

To verify reclaim-scheduled notifications, review the following items:



1. The timestamp of the request

Check the time that the request was received against the timestamp in the request headers. If it is off by more than 30 seconds or so, do not accept the request. This action can help prevent replay attacks.
2. The nonce found in the request's "X-IBM-Nonce" header

This value is a string that is randomly generated when the request is sent. You can choose to store previously received nonces to compare against the nonce included in the request. If the nonce in the request was used before, do not accept the request. This action can help prevent replay attacks.
3. Hash Message Authentication Code (HMAC) located in the request's "Authorization" header

This value is a string that is hashed by using the HMAC-SHA256 algorithm that uses the provided secret string as the key, and then encoded into Base64.
Getting started with subscriptions 

Oftentimes in distributed environments you want your applications or jobs to react to messages (events) that are generated from other components, which are usually called event producers. With Code Engine, your applications or jobs can receive events of interest by subscribing to event producers. Event information is received as POST HTTP requests for applications and as environment variables for jobs.

Code Engine supports the following types of event producers.

Cron
: The cron event producer is based on cron and generates an event at regular intervals. Use a cron event producer when an action needs to be taken at well-defined intervals or at specific times.

IBM Cloud Object Storage
: The Object Storage event producer generates events as changes are made to the objects in your object storage buckets. For example, as objects are added to a bucket, an application can receive an event and then perform an action based on that change, perhaps consuming that new object.

Kafka
: The Kafka event producer watches for new messages to appear in a Kafka instance. When you create a Code Engine Kafka subscription for a set of topics, your app or job receives a separate event for each new message that appears in one of the topics.

You can also use GitHub webhooks to send events from a GitHub repository to your Code Engine workload. The event is sent as a POST request in one of the [supported content types](https://docs.github.com/en/webhooks-and-events/webhooks/creating-webhookscontent-type). You must use an application with a public endpoint to receive the GitHub event; jobs are not supported. For more information, see [Sending GitHub events to an application](https://cloud.ibm.com/docs/codeengine?topic=codeengine-github-event-webhooks).

For more information about subscription APIs, see [Code Engine API reference - Subscription CRD methods](https://cloud.ibm.com/docs/codeengine?topic=codeengine-apiapi-crd-subscription).



 Subscriptions for apps and app scaling
<-- </section "id="section-show-waf-package-examples" "> --><-- </section "id="section-show-waf-package" "> --><-- <section "id="section-update-waf-owasp-package" "> --> ibmcloud cis waf-package-set Update OWASP Package setting. ibmcloud cis waf-package-set DNS_DOMAIN_ID OWASP_PACKAGE_ID --sensitivity SENSITIVITY] --action-mode ACTION_MODE] -i, --instance INSTANCE] --output FORMAT] ! ! ! ! ! !
<-- <section "id="section-update-waf-owasp-package-options" "> --> Command options DNS_DOMAIN_ID: The ID of DNS domain. Required.OWASP_PACKAGE_ID: The ID of WAF package. Required.--sensitivity: The sensitivity of the firewall package. Valid values: high, medium, low, off.--action-mode: The default action that will be taken for rules under the firewall package. Valid values: simulate, block, challenge.-i, --instance: Instance name or ID. If not set, the context instance specified by ibmcloud cis instance-set INSTANCE is used.--output: Specify output format, only JSON is supported.<-- </section "id="section-update-waf-owasp-package-options" "> --><-- <section "id="section-update-waf-owasp-package-examples" "> --> Examples Update OWASP setting for package a25a9a7e9c00afc1fb2e0245519d725b. ibmcloud cis waf-package-set 31984fea73a15b45779fa0df4ef62f9b a25a9a7e9c00afc1fb2e0245519d725b --sensitivity medium --action-mode simulate -i "cis-demo"
API reference for IBM Cloud Virtual Router Appliance 

The SoftLayer Application Programming Interface (SLAPI) is the development interface that gives developers and system administrators direct interaction with the IBM Cloud® backend system, and is used by the IBM Cloud® Virtual Router Appliance.

The SLAPI powers many of the features in the IBM Cloud console, which typically means if an interaction is possible in the console, it can also be run in the API. Because you can programmatically interact with all portions of the IBM Cloud console within the API, you can use the API to automate tasks.

The SLAPI is a Remote Procedure Call (RPC) system. Each call involves sending data towards an API endpoint and receiving structured data in return. The format used to send and receive data with the SLAPI depends on which implementation of the API you choose. The SLAPI currently uses SOAP, XML-RPC or REST for data transmission.

For more information about the SLAPI as they refer to the Virtual Router Appliance APIs, see the following resources in the SoftLayer Development Network (SLDN):



* [SoftLayer_Network_Gateway API](https://sldn.softlayer.com/reference/services/SoftLayer_Network_Gateway)
* [SoftLayer_Network_Gateway_Member API](https://sldn.softlayer.com/reference/services/SoftLayer_Network_Gateway_Member)
* [SoftLayer_Network_Gateway_Vlan API](https://sldn.softlayer.com/reference/services/SoftLayer_Network_Gateway_Vlan)
* [SoftLayer_Network_Gateway_Status API](https://sldn.softlayer.com/reference/services/SoftLayer_Network_Gateway_Status)
* [SoftLayer API Python Client](http://softlayer-api-python-client.readthedocs.io/en/latest/api/client/)
* [More SoftLayer API Examples with different languages](https://softlayer.github.io/python/)





 Example - Ordering a gateway appliance 

import SoftLayer
from pprint import pprint

def main():