Skip to main content

SDK for using KBRaiN tools

Project description

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.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kbrainsdk-0.7.3.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kbrainsdk-0.7.3-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file kbrainsdk-0.7.3.tar.gz.

File metadata

  • Download URL: kbrainsdk-0.7.3.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for kbrainsdk-0.7.3.tar.gz
Algorithm Hash digest
SHA256 be87c708e33a4babc94b125f576aa8e6eef5276b20e0372f00fe9b758081d269
MD5 7ec635f834f8d80d492fd38fbd4aae3c
BLAKE2b-256 7fcb7afc9bffa1a54d91ce76b32b8c5cff94bfea69f406cfc66cf1e279611d70

See more details on using hashes here.

File details

Details for the file kbrainsdk-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: kbrainsdk-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.11.6 Linux/5.15.146.1-microsoft-standard-WSL2

File hashes

Hashes for kbrainsdk-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ac8bb90b784648ba55a324e464161a7311ef4191c91de2834026960ec39d4828
MD5 bf8d8e51ca4db5c3b99b6ae9c8d26060
BLAKE2b-256 3ecdd88ef9c86b451ebd9ffc127bd37e960717e5bd6e5620382ecccb92de349b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page