Skip to content

Repository files navigation

kosu

Asynchronous API wrapper for the Perspective API.

Installation

pip install git+https://github.com/hypergonial/kosu.git

Quick Start

import asyncio
import kosu

attribs = [
    kosu.Attribute(kosu.AttributeName.TOXICITY),
    kosu.Attribute(kosu.AttributeName.SEVERE_TOXICITY),
    kosu.Attribute(kosu.AttributeName.INSULT),
]


async def main() -> None:
    client = kosu.Client("API_KEY")
    resp: kosu.AnalysisResponse = await client.analyze(
        "Shut up, you're an idiot!", attribs, languages=["en"]
    )

    for score in resp.attribute_scores:
        print(score)

    await client.close()


asyncio.run(main())

Outputs:

AttributeScore(name=<AttributeName.INSULT: 'INSULT'>, summary=SummaryScore(value=0.9263389, type='PROBABILITY'), span=[SpanScore(value=0.9263389, type='PROBABILITY', begin=0, end=25)])

AttributeScore(name=<AttributeName.TOXICITY: 'TOXICITY'>, summary=SummaryScore(value=0.944597, type='PROBABILITY'), span=[SpanScore(value=0.944597, type='PROBABILITY', begin=0, end=25)])

AttributeScore(name=<AttributeName.SEVERE_TOXICITY: 'SEVERE_TOXICITY'>, summary=SummaryScore(value=0.25624833, type='PROBABILITY'), span=[SpanScore(value=0.25624833, type='PROBABILITY', begin=0, end=25)])

About

Asynchronous API wrapper for the Perspective API.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages