Name | keywordsai JSON |
Version |
0.1.5
JSON |
| download |
home_page | None |
Summary | Keywords AI SDK allows you to interact with the Keywords AI API smoothly |
upload_time | 2024-09-07 09:05:14 |
maintainer | None |
docs_url | None |
author | Keywords AI |
requires_python | <4.0,>=3.8 |
license | MIT |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# Keywords AI SDK
Keywords AI Python SDK allows you to easily interact with the Keywords AI API.
## Get started
Get started with Keywords AI in minutes
### Installation
#### Users
Poetry
```
poetry add keywordsai
```
Pip
```
pip install keywordsai
```
#### Developers and Contributers
You can install the current directory as a python package via this command
```
poetry install
```
or
```
pip install . -e
```
### Environment Variables
```
touch .env
```
Inside the .env file, you can configure the constants througout the library
```env
DEBUG # Default is "False", set to "True" to enable debug mode for more verbose output
KEYWORDSAI_BASE_URL # Default is "https://api.keywordsai.co/api/", the slash at the end is important
KEYWORDSAI_API_KEY # Your Keywords AI API Key
```
Change values during runtime (not recommended)
```python
import keywordsai.keywordsai_config as config
config.KEYWORDSAI_BASE_URL = "some_url"
```
### Usage
#### Proxy
With Keywords AI as a proxy, observability comes out of box.
```python
from openai import OpenAI
import os
client = OpenAI(
api_key=os.getenv("KEYWORDSAI_API_KEY"),
base_url=os.getenv("KEYWORDSAI_BASE_URL")
)
# Use the client to make requests as you would with the OpenAI SDK
```
#### Wrapper (Beta)
Wrap around the OpenAI completion function to automatically log the request and response
Synchronous:
```python
from keywordsai import KeywordsAI
from openai import OpenAI
client = OpenAI()
def test_generation():
kai = KeywordsAI()
try:
wrapped_creation = kai.logging_wrapper(client.chat.completions.create)
response = wrapped_creation(
model=test_model,
messages=test_messages,
stream=False,
extra_body={"mock_response": test_mock_response},
)
assert isinstance(response, ChatCompletion)
except Exception as e:
assert False, e
if __name__ == "__main__":
generator = test_generation()
```
Asynchronous:
```
from tests.test_env import *
from keywordsai.core import KeywordsAI, AsyncGenerator
from openai import AsyncOpenAI
from openai.types.chat.chat_completion import ChatCompletion
client = AsyncOpenAI()
async def test_stream_generation():
kai = KeywordsAI()
try:
wrapped_creation = kai.async_logging_wrapper(client.chat.completions.create)
# wrapped_creation = oai_client.chat.completions.create
response = await wrapped_creation(
model=test_model,
messages=test_messages,
stream=True,
)
assert isinstance(response, AsyncGenerator)
return response
except Exception as e:
print(e)
async def test_generation():
kai = KeywordsAI()
try:
wrapped_creation = kai.async_logging_wrapper(client.chat.completions.create, keywordsai_params={
"customer_identifier": "sdk_customer",
})
response = await wrapped_creation(
model=test_model,
messages=test_messages,
stream=False,
)
assert isinstance(response, ChatCompletion)
return response
except Exception as e:
assert False, e
import asyncio
async def run_stream():
response = await test_stream_generation()
async for chunk in response:
content = chunk.choices[0].delta.content
if content:
print(content, end="")
pass
if __name__ == "__main__":
# non streaming
asyncio.run(test_generation())
# streaming
asyncio.run(run_stream())
KeywordsAI.flush()
```
Raw data
{
"_id": null,
"home_page": null,
"name": "keywordsai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Keywords AI",
"author_email": "team@keywordsai.co",
"download_url": "https://files.pythonhosted.org/packages/1c/27/56270b123ac59bb40cd0617dbcb6735e6b0d1c1aa851ca455144ef600654/keywordsai-0.1.5.tar.gz",
"platform": null,
"description": "# Keywords AI SDK\nKeywords AI Python SDK allows you to easily interact with the Keywords AI API.\n\n## Get started\nGet started with Keywords AI in minutes\n### Installation\n#### Users\n\nPoetry\n```\npoetry add keywordsai\n```\nPip\n```\npip install keywordsai\n```\n#### Developers and Contributers\nYou can install the current directory as a python package via this command\n```\npoetry install\n```\nor\n```\npip install . -e\n```\n### Environment Variables\n```\ntouch .env\n```\nInside the .env file, you can configure the constants througout the library\n```env\nDEBUG # Default is \"False\", set to \"True\" to enable debug mode for more verbose output\nKEYWORDSAI_BASE_URL # Default is \"https://api.keywordsai.co/api/\", the slash at the end is important\nKEYWORDSAI_API_KEY # Your Keywords AI API Key\n```\nChange values during runtime (not recommended)\n```python\nimport keywordsai.keywordsai_config as config\nconfig.KEYWORDSAI_BASE_URL = \"some_url\"\n```\n\n### Usage\n\n#### Proxy\nWith Keywords AI as a proxy, observability comes out of box.\n```python\nfrom openai import OpenAI\nimport os\nclient = OpenAI(\n api_key=os.getenv(\"KEYWORDSAI_API_KEY\"),\n base_url=os.getenv(\"KEYWORDSAI_BASE_URL\")\n)\n\n# Use the client to make requests as you would with the OpenAI SDK\n```\n\n#### Wrapper (Beta)\nWrap around the OpenAI completion function to automatically log the request and response\n\nSynchronous:\n```python\nfrom keywordsai import KeywordsAI\nfrom openai import OpenAI\nclient = OpenAI()\ndef test_generation():\n kai = KeywordsAI()\n try:\n wrapped_creation = kai.logging_wrapper(client.chat.completions.create)\n response = wrapped_creation(\n model=test_model,\n messages=test_messages,\n stream=False,\n extra_body={\"mock_response\": test_mock_response},\n )\n assert isinstance(response, ChatCompletion)\n except Exception as e:\n assert False, e\n\n\nif __name__ == \"__main__\":\n generator = test_generation()\n``` \n\nAsynchronous:\n```\nfrom tests.test_env import *\nfrom keywordsai.core import KeywordsAI, AsyncGenerator\nfrom openai import AsyncOpenAI\nfrom openai.types.chat.chat_completion import ChatCompletion\n\nclient = AsyncOpenAI()\n\nasync def test_stream_generation():\n kai = KeywordsAI()\n try:\n wrapped_creation = kai.async_logging_wrapper(client.chat.completions.create)\n # wrapped_creation = oai_client.chat.completions.create\n response = await wrapped_creation(\n model=test_model,\n messages=test_messages,\n stream=True,\n )\n assert isinstance(response, AsyncGenerator)\n return response\n except Exception as e:\n print(e)\n\nasync def test_generation():\n kai = KeywordsAI()\n try:\n wrapped_creation = kai.async_logging_wrapper(client.chat.completions.create, keywordsai_params={\n \"customer_identifier\": \"sdk_customer\",\n })\n response = await wrapped_creation(\n model=test_model,\n messages=test_messages,\n stream=False,\n\n )\n assert isinstance(response, ChatCompletion)\n return response\n except Exception as e:\n assert False, e\n\nimport asyncio\n\nasync def run_stream():\n response = await test_stream_generation()\n async for chunk in response:\n content = chunk.choices[0].delta.content\n if content:\n print(content, end=\"\")\n pass\n\nif __name__ == \"__main__\":\n # non streaming\n asyncio.run(test_generation())\n\n # streaming\n asyncio.run(run_stream())\n KeywordsAI.flush()\n\n\n```",
"bugtrack_url": null,
"license": "MIT",
"summary": "Keywords AI SDK allows you to interact with the Keywords AI API smoothly",
"version": "0.1.5",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "eb47a0916a2a84e54e243ddbff1aeea9a819122db72d2f1778b03ab665eec727",
"md5": "7f826abbc9ee6bc18ec150404a3d4d3e",
"sha256": "23109966165ee1292c3e2ed770ce907fb0868333248e8f5422fb103de37136e5"
},
"downloads": -1,
"filename": "keywordsai-0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "7f826abbc9ee6bc18ec150404a3d4d3e",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 17032,
"upload_time": "2024-09-07T09:05:13",
"upload_time_iso_8601": "2024-09-07T09:05:13.383270Z",
"url": "https://files.pythonhosted.org/packages/eb/47/a0916a2a84e54e243ddbff1aeea9a819122db72d2f1778b03ab665eec727/keywordsai-0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "1c2756270b123ac59bb40cd0617dbcb6735e6b0d1c1aa851ca455144ef600654",
"md5": "426bfc9e77770cc14365c99f78b358e6",
"sha256": "46c56f755e391ac6aa97cdb8c80dde92677bdc96ff4fa40013cc63ffa7d2bdac"
},
"downloads": -1,
"filename": "keywordsai-0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "426bfc9e77770cc14365c99f78b358e6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 38834,
"upload_time": "2024-09-07T09:05:14",
"upload_time_iso_8601": "2024-09-07T09:05:14.431476Z",
"url": "https://files.pythonhosted.org/packages/1c/27/56270b123ac59bb40cd0617dbcb6735e6b0d1c1aa851ca455144ef600654/keywordsai-0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-07 09:05:14",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "keywordsai"
}