oneai


Nameoneai JSON
Version 0.9.89 PyPI version JSON
download
home_pagehttps://github.com/power-of-language/oneai-sdk-python
SummaryNLP as a Service
upload_time2023-08-13 10:54:02
maintainer
docs_urlNone
authorMichael Gur
requires_python>=3.7
license
keywords
VCS
bugtrack_url
requirements aiohttp validators typing_extensions dataclasses requests python-dateutil
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="left">
  <a href="https://oneai.com?utm_source=open_source&utm_medium=python_sdk_readme">
    <img src="./oneai_logo_light_cropped.svg" height="60">
  </a>
</p>

# Natural Language Processing API
[![API Key](https://img.shields.io/badge/%20-Get%20Your%20API%20Key%20for%20Free-%231d1c29?logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMTEyIiBoZWlnaHQ9Ijg4IiB2aWV3Qm94PSIwIDAgMTEyIDg4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTY5LjI5MTMgMzcuNTU4NkwzNi4xMTQzIDg3Ljc1MTZIMTAyLjQ2OEw2OS4yOTEzIDM3LjU1ODZaIiBmaWxsPSIjMDBGRkZGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNODkuMzAwOCA1MC4yOTIxSDExMS4xNjRWMEg4OS4zMDA4VjUwLjI5MjFaIiBmaWxsPSIjRjIzREU5Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjUuOTEwOCAxMS42NDc5QzExLjYwMDcgMTEuNjQ3OSAwIDIzLjI0ODYgMCAzNy41NTg3QzAgNTEuODY4OCAxMS42MDA3IDYzLjQ3MDEgMjUuOTEwOCA2My40NzAxQzQwLjIyMDkgNjMuNDcwMSA1MS44MjE2IDUxLjg2ODggNTEuODIxNiAzNy41NTg3QzUxLjgyMTYgMjMuMjQ4NiA0MC4yMjA5IDExLjY0NzkgMjUuOTEwOCAxMS42NDc5IiBmaWxsPSIjNEQ0REZGIi8+Cjwvc3ZnPgo=)](https://studio.oneai.com/settings/api-keys)
![Build](https://github.com/oneai-nlp/oneai-python/actions/workflows/main.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/oneai-nlp/oneai-python/badge.svg?branch=main)](https://coveralls.io/github/oneai-nlp/oneai-python?branch=main)
[![Version](https://img.shields.io/pypi/v/oneai)](https://pypi.org/project/oneai/)
[![Downloads](https://img.shields.io/pypi/dm/oneai)](https://pypistats.org/packages/oneai)
[![Discord](https://img.shields.io/discord/941458663493746698?logo=Discord)](https://discord.gg/ArpMha9n8H)

One AI is a NLP as a service platform. Our API enables language comprehension in context, transforming texts from any source into structured data to use in code.

This SDK provides safe and convenient access to One AI's API from a Python environment.

## Documentation
See the [documentation](https://studio.oneai.com/docs?utm_source=open_source&utm_medium=python_sdk_readme)

## Getting started

### Requirements
Python 3.7+ (PyPy supported)

### Installation
`pip install oneai`

### Authentication
You will need a valid API key for all requests. Register and create a key for your project [in the Studio](https://studio.oneai.com/?utm_source=open_source&utm_medium=python_sdk_readme).

#### Example
```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Names(),
    oneai.skills.Summarize(min_length=20),
    oneai.skills.Keywords()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```

## Pipeline API
### Language Skills
A Language Skill is a package of trained NLP models, available via API. Skills accept text as an input in various formats, and respond with processed texts and extracted metadata.

### Pipelines
Language AI pipelines allow invoking and chaining multiple Language Skills to process your input text with a single call. Pipelines are defined by listing the desired Skills.

### Language Studio
The [Language Studio](https://studio.oneai.com/?utm_source=open_source&utm_medium=python_sdk_readme) provides a visual interface to experiment with our APIs and generate calls to use in code. In the Studio you can craft a pipeline and paste the generated code back into your repository. 

### Basic Example

Let's say you're interested in extracting keywords from the text.
```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```

### Multi Skills request

Let's say you're interested in extracting keywords *and* sentiments from the text.
```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```

### Analyzer Skills vs Generator Skills

Skills can do either text analysis, and then their output are labels and spans (labels location in the analyzed text), or they can be generator skills, in which case they transform the input text into an output text.

Here's an example for a pipeline that combines both type of skills. It will extract keywords and sentiments from the text, and then summarize it.

```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Keywords(),
    oneai.skills.Sentiments(),
    oneai.skills.Summarize()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```

### Order is Important

When the pipeline is invoked, it is invoked with an original text you submit. If a generator skill is ran, then all following skills will use its generated text rather then the original text. In this example, for instance, we change the order of the pipeline from the previous example, and the results will be different. Instead of extracting keywords and sentiments from the original text, keywords and sentiments will be extracted from the generated summary.

```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Summarize(),
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```


### Configuring Skills
Many skills are configurable as you can find out in the [docs](https://studio.oneai.com/docs?utm_source=open_source&utm_medium=python_sdk_readme). Let's use the exact same example, this time however, we'll limit the summary length to 50 words.
```python
import oneai

oneai.api_key = '<YOUR-API-KEY>'
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Summarize(max_length=50),
    oneai.skills.Keywords(),
    oneai.skills.Sentiments()
])

my_text = 'analyze this text.'
output = pipeline.run(my_text)
print(output)
```

### Output
The structure of the output is dynamic, and corresponds to the Skills used and their order in the pipeline. Each output object contains the input text (which can be the original input or text produced by generator Skills), and a list of labels detected by analyzer Skills, that contain the extracted data. For example:
```python
pipeline = oneai.Pipeline(steps=[
    oneai.skills.Sentiments(),
    oneai.skills.Summarize(max_length=50),
    oneai.skills.Keywords(),
])

my_text = '''Could a voice control microwave be the new norm? The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Secondly, despite the very low price, if you don't want to use the voice control, you can still use it as a regular microwave.'''
output = pipeline.run(my_text)
```
will generate the following:
```python
oneai.Output(
    text="Could a voice control microwave be the ...",
    sentiments=[ # list of detected sentiments
        oneai.Label(
            type='sentiment',
            output_spans=[ # where the sentiment appears in the text
                Span(
                    start=49,
                    end=97,
                    section=0,
                    text='The price is unbeatable for a name brand product'
                )
            ],
            value='POS' # a positive sentiment
        ),
        ...
    ],
    summary=oneai.Output(
        text='The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Despite the very low price, you can still use it as a regular microwave.',
        keywords=[ # keyword labels
            oneai.Label(type='keyword', name='price', output_spans=[Span(start=4, end=9, section=0, text='price')], value=0.253), ...
        ]
    )
)
```

### File Uploads
Our API supports the following file extensions:
* `.txt`- text content
* `.json`- conversations in the One AI conversation format
* `.srt`- analyze captions as conversations
* `.wav`- audio files to be transcribed & analyzed
* `.jpg`- detect text in pictures via OCR
Upload a file by passing the the FileIO object to the pipeline
```python
with open('./example.txt', 'r') as inputf:
    pipeline = oneai.Pipeline(steps=[...])
    output = pipeline.run(inputf)
```
For large audio files, use the asyncronous `Pipeline.run_async`
```python
with open('./example.mp3', 'rb') as inputf:
    pipeline = oneai.Pipeline(steps=[oneai.skills.Transcribe(), ...])
    output = await pipeline.run(inputf)
```

### Support

Feel free to submit issues in this repo, contact us at [devrel@oneai.com](mailto:devrel@oneai.com), or chat with us on [Discord](https://discord.gg/ArpMha9n8H)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/power-of-language/oneai-sdk-python",
    "name": "oneai",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "",
    "author": "Michael Gur",
    "author_email": "devrel@oneai.com",
    "download_url": "https://files.pythonhosted.org/packages/48/ee/bc1e2376526ac25a4c18a7968e5bad8a1deae9ea6bc9e7305b938437425d/oneai-0.9.89.tar.gz",
    "platform": null,
    "description": "<p align=\"left\">\n  <a href=\"https://oneai.com?utm_source=open_source&utm_medium=python_sdk_readme\">\n    <img src=\"./oneai_logo_light_cropped.svg\" height=\"60\">\n  </a>\n</p>\n\n# Natural Language Processing API\n[![API Key](https://img.shields.io/badge/%20-Get%20Your%20API%20Key%20for%20Free-%231d1c29?logo=data:image/svg%2bxml;base64,PHN2ZyB3aWR0aD0iMTEyIiBoZWlnaHQ9Ijg4IiB2aWV3Qm94PSIwIDAgMTEyIDg4IiBmaWxsPSJub25lIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPgo8cGF0aCBmaWxsLXJ1bGU9ImV2ZW5vZGQiIGNsaXAtcnVsZT0iZXZlbm9kZCIgZD0iTTY5LjI5MTMgMzcuNTU4NkwzNi4xMTQzIDg3Ljc1MTZIMTAyLjQ2OEw2OS4yOTEzIDM3LjU1ODZaIiBmaWxsPSIjMDBGRkZGIi8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNODkuMzAwOCA1MC4yOTIxSDExMS4xNjRWMEg4OS4zMDA4VjUwLjI5MjFaIiBmaWxsPSIjRjIzREU5Ii8+CjxwYXRoIGZpbGwtcnVsZT0iZXZlbm9kZCIgY2xpcC1ydWxlPSJldmVub2RkIiBkPSJNMjUuOTEwOCAxMS42NDc5QzExLjYwMDcgMTEuNjQ3OSAwIDIzLjI0ODYgMCAzNy41NTg3QzAgNTEuODY4OCAxMS42MDA3IDYzLjQ3MDEgMjUuOTEwOCA2My40NzAxQzQwLjIyMDkgNjMuNDcwMSA1MS44MjE2IDUxLjg2ODggNTEuODIxNiAzNy41NTg3QzUxLjgyMTYgMjMuMjQ4NiA0MC4yMjA5IDExLjY0NzkgMjUuOTEwOCAxMS42NDc5IiBmaWxsPSIjNEQ0REZGIi8+Cjwvc3ZnPgo=)](https://studio.oneai.com/settings/api-keys)\n![Build](https://github.com/oneai-nlp/oneai-python/actions/workflows/main.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/oneai-nlp/oneai-python/badge.svg?branch=main)](https://coveralls.io/github/oneai-nlp/oneai-python?branch=main)\n[![Version](https://img.shields.io/pypi/v/oneai)](https://pypi.org/project/oneai/)\n[![Downloads](https://img.shields.io/pypi/dm/oneai)](https://pypistats.org/packages/oneai)\n[![Discord](https://img.shields.io/discord/941458663493746698?logo=Discord)](https://discord.gg/ArpMha9n8H)\n\nOne AI is a NLP as a service platform. Our API enables language comprehension in context, transforming texts from any source into structured data to use in code.\n\nThis SDK provides safe and convenient access to One AI's API from a Python environment.\n\n## Documentation\nSee the [documentation](https://studio.oneai.com/docs?utm_source=open_source&utm_medium=python_sdk_readme)\n\n## Getting started\n\n### Requirements\nPython 3.7+ (PyPy supported)\n\n### Installation\n`pip install oneai`\n\n### Authentication\nYou will need a valid API key for all requests. Register and create a key for your project [in the Studio](https://studio.oneai.com/?utm_source=open_source&utm_medium=python_sdk_readme).\n\n#### Example\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Names(),\n    oneai.skills.Summarize(min_length=20),\n    oneai.skills.Keywords()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n## Pipeline API\n### Language Skills\nA Language Skill is a package of trained NLP models, available via API. Skills accept text as an input in various formats, and respond with processed texts and extracted metadata.\n\n### Pipelines\nLanguage AI pipelines allow invoking and chaining multiple Language Skills to process your input text with a single call. Pipelines are defined by listing the desired Skills.\n\n### Language Studio\nThe [Language Studio](https://studio.oneai.com/?utm_source=open_source&utm_medium=python_sdk_readme) provides a visual interface to experiment with our APIs and generate calls to use in code. In the Studio you can craft a pipeline and paste the generated code back into your repository. \n\n### Basic Example\n\nLet's say you're interested in extracting keywords from the text.\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Keywords()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n### Multi Skills request\n\nLet's say you're interested in extracting keywords *and* sentiments from the text.\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Keywords(),\n    oneai.skills.Sentiments()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n### Analyzer Skills vs Generator Skills\n\nSkills can do either text analysis, and then their output are labels and spans (labels location in the analyzed text), or they can be generator skills, in which case they transform the input text into an output text.\n\nHere's an example for a pipeline that combines both type of skills. It will extract keywords and sentiments from the text, and then summarize it.\n\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Keywords(),\n    oneai.skills.Sentiments(),\n    oneai.skills.Summarize()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n### Order is Important\n\nWhen the pipeline is invoked, it is invoked with an original text you submit. If a generator skill is ran, then all following skills will use its generated text rather then the original text. In this example, for instance, we change the order of the pipeline from the previous example, and the results will be different. Instead of extracting keywords and sentiments from the original text, keywords and sentiments will be extracted from the generated summary.\n\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Summarize(),\n    oneai.skills.Keywords(),\n    oneai.skills.Sentiments()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n\n### Configuring Skills\nMany skills are configurable as you can find out in the [docs](https://studio.oneai.com/docs?utm_source=open_source&utm_medium=python_sdk_readme). Let's use the exact same example, this time however, we'll limit the summary length to 50 words.\n```python\nimport oneai\n\noneai.api_key = '<YOUR-API-KEY>'\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Summarize(max_length=50),\n    oneai.skills.Keywords(),\n    oneai.skills.Sentiments()\n])\n\nmy_text = 'analyze this text.'\noutput = pipeline.run(my_text)\nprint(output)\n```\n\n### Output\nThe structure of the output is dynamic, and corresponds to the Skills used and their order in the pipeline. Each output object contains the input text (which can be the original input or text produced by generator Skills), and a list of labels detected by analyzer Skills, that contain the extracted data. For example:\n```python\npipeline = oneai.Pipeline(steps=[\n    oneai.skills.Sentiments(),\n    oneai.skills.Summarize(max_length=50),\n    oneai.skills.Keywords(),\n])\n\nmy_text = '''Could a voice control microwave be the new norm? The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Secondly, despite the very low price, if you don't want to use the voice control, you can still use it as a regular microwave.'''\noutput = pipeline.run(my_text)\n```\nwill generate the following:\n```python\noneai.Output(\n    text=\"Could a voice control microwave be the ...\",\n    sentiments=[ # list of detected sentiments\n        oneai.Label(\n            type='sentiment',\n            output_spans=[ # where the sentiment appears in the text\n                Span(\n                    start=49,\n                    end=97,\n                    section=0,\n                    text='The price is unbeatable for a name brand product'\n                )\n            ],\n            value='POS' # a positive sentiment\n        ),\n        ...\n    ],\n    summary=oneai.Output(\n        text='The price is unbeatable for a name brand product, an official Amazon brand, so you can trust it at least. Despite the very low price, you can still use it as a regular microwave.',\n        keywords=[ # keyword labels\n            oneai.Label(type='keyword', name='price', output_spans=[Span(start=4, end=9, section=0, text='price')], value=0.253), ...\n        ]\n    )\n)\n```\n\n### File Uploads\nOur API supports the following file extensions:\n* `.txt`- text content\n* `.json`- conversations in the One AI conversation format\n* `.srt`- analyze captions as conversations\n* `.wav`- audio files to be transcribed & analyzed\n* `.jpg`- detect text in pictures via OCR\nUpload a file by passing the the FileIO object to the pipeline\n```python\nwith open('./example.txt', 'r') as inputf:\n    pipeline = oneai.Pipeline(steps=[...])\n    output = pipeline.run(inputf)\n```\nFor large audio files, use the asyncronous `Pipeline.run_async`\n```python\nwith open('./example.mp3', 'rb') as inputf:\n    pipeline = oneai.Pipeline(steps=[oneai.skills.Transcribe(), ...])\n    output = await pipeline.run(inputf)\n```\n\n### Support\n\nFeel free to submit issues in this repo, contact us at [devrel@oneai.com](mailto:devrel@oneai.com), or chat with us on [Discord](https://discord.gg/ArpMha9n8H)\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "NLP as a Service",
    "version": "0.9.89",
    "project_urls": {
        "Bug Tracker": "https://github.com/power-of-language/oneai-sdk-python/issues",
        "Homepage": "https://github.com/power-of-language/oneai-sdk-python"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f18ddef35019434d6cbcff7a73e7708f510ccd2e9602a667b12cf7597285e12",
                "md5": "b9ca6c42c2b5d908a89138cd4e6dde75",
                "sha256": "761035b5f8159a92352b0c9b831dac7bf537b2004ce922cc1e733198fd29e463"
            },
            "downloads": -1,
            "filename": "oneai-0.9.89-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b9ca6c42c2b5d908a89138cd4e6dde75",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 32111,
            "upload_time": "2023-08-13T10:54:00",
            "upload_time_iso_8601": "2023-08-13T10:54:00.253125Z",
            "url": "https://files.pythonhosted.org/packages/3f/18/ddef35019434d6cbcff7a73e7708f510ccd2e9602a667b12cf7597285e12/oneai-0.9.89-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "48eebc1e2376526ac25a4c18a7968e5bad8a1deae9ea6bc9e7305b938437425d",
                "md5": "2959b5bc4d47450ba41321dce69b6640",
                "sha256": "7dc4b7d003b01dbf1b4e981b311a71686c244cfa0c0950ec2da8003ea542addd"
            },
            "downloads": -1,
            "filename": "oneai-0.9.89.tar.gz",
            "has_sig": false,
            "md5_digest": "2959b5bc4d47450ba41321dce69b6640",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 33700,
            "upload_time": "2023-08-13T10:54:02",
            "upload_time_iso_8601": "2023-08-13T10:54:02.266544Z",
            "url": "https://files.pythonhosted.org/packages/48/ee/bc1e2376526ac25a4c18a7968e5bad8a1deae9ea6bc9e7305b938437425d/oneai-0.9.89.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-13 10:54:02",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "power-of-language",
    "github_project": "oneai-sdk-python",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "aiohttp",
            "specs": [
                [
                    "==",
                    "3.8.3"
                ]
            ]
        },
        {
            "name": "validators",
            "specs": [
                [
                    "==",
                    "0.20.0"
                ]
            ]
        },
        {
            "name": "typing_extensions",
            "specs": [
                [
                    "==",
                    "4.3.0"
                ]
            ]
        },
        {
            "name": "dataclasses",
            "specs": [
                [
                    "==",
                    "0.8"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.27.1"
                ]
            ]
        },
        {
            "name": "python-dateutil",
            "specs": [
                [
                    "==",
                    "2.8.2"
                ]
            ]
        }
    ],
    "lcname": "oneai"
}
        
Elapsed time: 0.14725s