Metadata-Version: 2.5
Name: mykitt
Version: 0.1.0
Summary: Kitt's own library for Kitt Platform: Kitt 1 Mini, Kitt 1 and Kitt Auto from Python.
Project-URL: Homepage, https://platform.mykitt.id
Project-URL: Documentation, https://platform.mykitt.id/#docs
Project-URL: Source, https://github.com/Naratifs/My-Kitt/tree/main/sdk/python
Author-email: PT Aplikasi Naratifs Indonesia <corporate@naratifs.com>
License-Expression: MIT
License-File: LICENSE
Keywords: ai,chat completions,kitt,llm,mykitt,naratifs
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# mykitt

Kitt's own library for [Kitt Platform](https://platform.mykitt.id): Kitt 1 Mini, Kitt 1 and Kitt Auto from Python.
It uses only Python's own library (3.8+).

```sh
pip install mykitt
```

```python
from mykitt import Kitt

kitt = Kitt()  # reads KITT_API_KEY

answer = kitt.chat.completions.create(
    model="kitt-1-mini",
    messages=[{"role": "user", "content": "Halo, Kitt!"}],
)
print(answer.choices[0].message.content)
```

Make a key under API Keys at [platform.mykitt.id](https://platform.mykitt.id) and keep it on your server, never in a
web page or a phone app.

## Streaming

```python
stream = kitt.chat.completions.create(
    model="kitt-1-mini",
    messages=[{"role": "user", "content": "Tell me about Naratifs."}],
    stream=True,
)
for chunk in stream:
    if chunk.choices:
        print(chunk.choices[0].delta.get("content") or "", end="")
```

The last chunk carries the usage. `stream.close()` stops it.

## Models

```python
for model in kitt.models.list().data:
    print(model.id, model.name)
```

| Model       | ID            | What it is for                                                       |
| ----------- | ------------- | -------------------------------------------------------------------- |
| Kitt 1 Mini | `kitt-1-mini` | Does everything Kitt does, quickly and at the lowest price.          |
| Kitt 1      | `kitt-1`      | Reasons more for heavy work; an answer takes about 20 times the credits. |
| Kitt Auto   | `kitt-auto`   | Picks the model for each request; the answer names the one it ran on. |

Prices are listed by `models.list()` and on [platform.mykitt.id](https://platform.mykitt.id), taken from your Kitt credits.

## Errors

A failed call raises `KittError` with `status`, `code` (such as `invalid_api_key` or `insufficient_credits`) and
`request_id`, to quote when you write to us. A 429 or 5xx is tried again twice, waiting longer each time
(`max_retries`).

```python
from mykitt import Kitt, KittError

try:
    kitt.chat.completions.create(model="kitt-1-mini", messages=messages)
except KittError as e:
    print(e.status, e.code, e.request_id, e.message)
```

## Options

`Kitt(api_key=None, base_url=None, timeout=600, max_retries=2, headers=None)`. The base URL is
`https://api.mykitt.id/v1`. Answers read as attributes or as dicts (`answer.to_dict()`).

Already using another library that speaks Chat Completions? Point it at the same base URL with your Kitt key.

MIT licence, © PT Aplikasi Naratifs Indonesia.
