Name | kbrainsdk JSON |
Version |
0.23.4
JSON |
| download |
home_page | None |
Summary | SDK for using KBRaiN tools |
upload_time | 2024-10-12 16:07:42 |
maintainer | None |
docs_url | None |
author | Daniel E Fredriksen |
requires_python | <4.0.0,>=3.8.1 |
license | unlicensed |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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:
```bash
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:
```python
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:
```bash
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](https://platform.openai.com/docs/api-reference/chat) for details.
Here is an example:
```python
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](https://platform.openai.com/docs/api-reference/chat) for details.
Here is an example:
```python
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:
```python
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.
Raw data
{
"_id": null,
"home_page": null,
"name": "kbrainsdk",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0.0,>=3.8.1",
"maintainer_email": null,
"keywords": null,
"author": "Daniel E Fredriksen",
"author_email": "daniel.fredriksen@us.kbr.com",
"download_url": "https://files.pythonhosted.org/packages/9b/1c/58f9ceb6505f70d97dc79a8ef295bbfe24c9e936fa1b565ab05d42c46bfb/kbrainsdk-0.23.4.tar.gz",
"platform": null,
"description": "# KBRaiN SDK API\n\nThe 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.\n\n## Installation\n\nTo install the KBRaiN SDK API, use pip:\n\n```bash\npip install kbrainsdk\n```\n\n## Usage\n\nSee the `kbrainsdk/examples/example.ipynb` Jupyter notebook for more examples.\n\nHere are a few:\n\nFirst, import the library and create an instance of the API client:\n\n```python\nfrom kbrainsdk.api import KBRaiNAPI\n\nkbrain = KBRaiNAPI(account_id='your_account_id', api_key='your_api_key', base_url=\"kbrain_base_url\")\n```\n\nWe 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.\n\nYou can also skip passing in values to the constructor and KBRaiN will reference your environment variables if they are defined with the following names:\n\n```bash\nKBRAIN_BASE_URL\nKBRAIN_ACCOUNT_ID\nKBRAIN_API_KEY\n```\n\n## OpenAI Chat\nTo 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](https://platform.openai.com/docs/api-reference/chat) for details.\n\nHere is an example:\n\n```python\nmessages = [{\n 'role': 'system',\n 'content': 'You are a helpful assistant.'\n}, {\n 'role': 'user',\n 'content': 'What is the air speed velocity of an unladen swallow?'\n}]\n\nmodel_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. \nmodel_type = 'openai' # Replace with your model type\ndeployment_id = 'chat'\n\nresponse = kbrain.llms.openai_chat(messages, model_name, model_type, deployment_id)\n\nprint(response[\"response\"])\nprint(response[\"tokens\"])\n```\n\n## OpenAI Completion\nTo 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](https://platform.openai.com/docs/api-reference/chat) for details.\n\nHere is an example:\n\n```python\n\nprompt = \"Translate this into Spanish: Hello World!\"\nmodel_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. \nmodel_type = 'openai' # Replace with your model type\ndeployment_id = 'instruct'\n\nresponse = kbrain.llms.openai_completion(prompt, model_name, model_type, deployment_id)\n\nprint(response[\"response\"])\nprint(response[\"tokens\"])\n```\n\n## Dataset Features\n\nTo interact with the Dataset features, follow the example below:\n\n\n\n```python\nemail = \"<your users email>\"\ntoken = \"<your users authentication token into your app>\"\nclient_id = \"<your apps client_id>\"\noauth_secret = \"<your apps oauth secret>\"\ntenant_id = \"<your apps tenant id>\"\nresponse = kbrain.datasets.list_datasets(email, token, client_id, oauth_secret, tenant_id)\n```\n\n\n## License\nCopyright 2023, KBR Inc.",
"bugtrack_url": null,
"license": "unlicensed",
"summary": "SDK for using KBRaiN tools",
"version": "0.23.4",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "42598280d96875423a286f66d8370c44acb6408d368ee4d88fc7f951df6335af",
"md5": "c84bbfac3bed265d22798e96266486ed",
"sha256": "06c5f3b17a8ace62e0bfb716c468b9473dd4a5be222d794bbd3e2348347b80f6"
},
"downloads": -1,
"filename": "kbrainsdk-0.23.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c84bbfac3bed265d22798e96266486ed",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0.0,>=3.8.1",
"size": 19042,
"upload_time": "2024-10-12T16:07:40",
"upload_time_iso_8601": "2024-10-12T16:07:40.884705Z",
"url": "https://files.pythonhosted.org/packages/42/59/8280d96875423a286f66d8370c44acb6408d368ee4d88fc7f951df6335af/kbrainsdk-0.23.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9b1c58f9ceb6505f70d97dc79a8ef295bbfe24c9e936fa1b565ab05d42c46bfb",
"md5": "5d6dfae11c314bf75ee0bb1c1439b694",
"sha256": "8c8ff96a71583bcc5c942b33e4591dd244c75e45ddbf0bebb7c7493421b12683"
},
"downloads": -1,
"filename": "kbrainsdk-0.23.4.tar.gz",
"has_sig": false,
"md5_digest": "5d6dfae11c314bf75ee0bb1c1439b694",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0.0,>=3.8.1",
"size": 13150,
"upload_time": "2024-10-12T16:07:42",
"upload_time_iso_8601": "2024-10-12T16:07:42.420647Z",
"url": "https://files.pythonhosted.org/packages/9b/1c/58f9ceb6505f70d97dc79a8ef295bbfe24c9e936fa1b565ab05d42c46bfb/kbrainsdk-0.23.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-12 16:07:42",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "kbrainsdk"
}