pdstools.pega_io.API

Module Contents

Functions

_readClientCredentialFile(credentialFile)

get_URL(credentialFile)

Returns the URL of the Infinity instance in the credential file

get_token(credentialFile[, verify])

Get API credentials to a Pega Platform instance.

setupAzureOpenAI(api_base, api_version, ...)

Convenience function to automagically setup Azure AD-based authentication

_readClientCredentialFile(credentialFile)
get_URL(credentialFile: str)

Returns the URL of the Infinity instance in the credential file

Parameters:

credentialFile (str)

get_token(credentialFile: str, verify: bool = True, **kwargs)

Get API credentials to a Pega Platform instance.

After setting up OAuth2 authentication in Dev Studio, you should be able to download a credential file. Simply point this method to that file, and it’ll read the relevant properties and give you your access token.

Parameters:
  • credentialFile (str) – The credential file downloaded after setting up OAuth in a Pega system

  • verify (bool, default = True) – Whether to only allow safe SSL requests. In case you’re connecting to an unsecured API endpoint, you need to explicitly set verify to False, otherwise Python will yell at you.

Keyword Arguments:

url (str) – An optional override of the URL to connect to. This is also extracted out of the credential file, but you may want to customize this (to a different port, etc).

setupAzureOpenAI(api_base: str = 'https://aze-openai-01.openai.azure.com/', api_version: Literal[2022-12-01, 2023-03-15-preview, 2023-05-15, 2023-06-01-preview, 2023-07-01-preview, 2023-09-15-preview, 2023-10-01-preview, 2023-12-01-preview] = '2023-12-01-preview')

Convenience function to automagically setup Azure AD-based authentication for the Azure OpenAI service. Mostly meant as an internal tool within Pega, but can of course also be used beyond.

Prerequisites (you should only need to do this once!): - Download Azure CLI (https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) - Once installed, run ‘az login’ in your terminal - Additional dependencies: (pip install) azure-identity and (pip install) openai

Running this function automatically sets, among others: - openai.api_key - os.environ[“OPENAI_API_KEY”]

This should ensure that you don’t need to pass tokens and/or api_keys around. The key that’s set has a lifetime, typically of one hour. Therefore, if you get an error message like ‘invalid token’, you may need to run this method again to refresh the token for another hour.

Parameters:
  • api_base (str) – The url of the Azure service name you’d like to connect to If you have access to the Azure OpenAI playground (https://oai.azure.com/portal), you can easily find this url by clicking ‘view code’ in one of the playgrounds. If you have access to the Azure portal directly (https://portal.azure.com), this will be found under ‘endpoint’. Else, ask your system administrator for the correct url.

  • api_version (str) – The version of the api to use

  • Usage

  • -----

  • setupAzureOpenAI (>>> from pdstools import)

  • setupAzureOpenAI() (>>>)