Skip to main content

KBRaiN SDK API

The KBRaiN SDK API is a Python library that provides a simple interface to interact with the KBRaiN services. It includes methods for account creation, key generation, and interacting with the OpenAI chat service.

Installation

To install the KBRaiN SDK API, use pip:

pip install kbrainsdk

Usage

See the kbrainsdk/examples/example.ipynb Jupyter notebook for more examples.

Here are a few:

First, import the library and create an instance of the API client:

from kbrainsdk.api import KBRaiNAPI

kbrain = KBRaiNAPI(account_id='your_account_id', api_key='your_api_key', base_url="kbrain_base_url")

We recommend using environment variables or a tool like Azure Key Vault to inject your api key, do not commit your api key to any source control for security reasons.

You can also skip passing in values to the constructor and KBRaiN will reference your environment variables if they are defined with the following names:

KBRAIN_BASE_URL
KBRAIN_ACCOUNT_ID
KBRAIN_API_KEY

OpenAI Chat

To interact with the OpenAI chat API, use the openai_chat method. This method takes the same arguments as the OpenAI API as of version 1.3.3. You can see the API documentation at OpenAI for details.

Here is an example:

messages = [{
    'role': 'system',
    'content': 'You are a helpful assistant.'
}, {
    'role': 'user',
    'content': 'What is the air speed velocity of an unladen swallow?'
}]

model_name = 'gpt-3.5-turbo'  # Replace with the model name in the targeted Azure OpenAI Resource. This should be chat for gpt-3x and chat-4 for gpt4. 
model_type = 'openai'  # Replace with your model type
deployment_id = 'chat'

response = kbrain.llms.openai_chat(messages, model_name, model_type, deployment_id)

print(response["response"])
print(response["tokens"])

OpenAI Completion

To interact with the OpenAI completions API, use the openai_completion method. This method takes the same arguments as the OpenAI API as of version 1.3.3. You can see the API documentation at OpenAI for details.

Here is an example:

prompt = "Translate this into Spanish: Hello World!"
model_name = 'gpt-3.5-instruct'  # Replace with the model name in the targeted Azure OpenAI Resource. This should be chat for gpt-3x and chat-4 for gpt4. 
model_type = 'openai'  # Replace with your model type
deployment_id = 'instruct'

response = kbrain.llms.openai_completion(prompt, model_name, model_type, deployment_id)

print(response["response"])
print(response["tokens"])

Dataset Features

To interact with the Dataset features, follow the example below:

email = "<your users email>"
token = "<your users authentication token into your app>"
client_id = "<your apps client_id>"
oauth_secret = "<your apps oauth secret>"
tenant_id = "<your apps tenant id>"
response = kbrain.datasets.list_datasets(email, token, client_id, oauth_secret, tenant_id)

License

Copyright 2023, KBR Inc.

Metadata

Release files for kbrainsdk 0.23.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kbrainsdk 0.23.4
File Size Uploaded Provenance
kbrainsdk-0.23.4.tar.gz 13.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for kbrainsdk 0.23.4
File Interpreter ABI Platform
kbrainsdk-0.23.4-py3-none-any.whl Python 3 none any Details

Total release size: 32.2 kB

Release files / kbrainsdk-0.23.4.tar.gz

Download URL kbrainsdk-0.23.4.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8c8ff96a71583bcc5c942b33e4591dd244c75e45ddbf0bebb7c7493421b12683
BLAKE2b-256 checksum
How to use checksums
9b1c58f9ceb6505f70d97dc79a8ef295bbfe24c9e936fa1b565ab05d42c46bfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/5.15.153.1-microsoft-standard-WSL2

Release files / kbrainsdk-0.23.4-py3-none-any.whl

Download URL kbrainsdk-0.23.4-py3-none-any.whl
Size 19.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06c5f3b17a8ace62e0bfb716c468b9473dd4a5be222d794bbd3e2348347b80f6
BLAKE2b-256 checksum
How to use checksums
42598280d96875423a286f66d8370c44acb6408d368ee4d88fc7f951df6335af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Linux/5.15.153.1-microsoft-standard-WSL2

Security for kbrainsdk 0.23.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.23.4 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page