Metadata-Version: 2.4
Name: eai_answers_lib
Version: 0.1.2
Summary: Library to interact with Expert AI Answers engine
Author: Simone Martin
Requires-Python: >=3.12
Description-Content-Type: text/markdown
Requires-Dist: loguru>=0.7.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: requests>=2.0.0
Provides-Extra: dev
Requires-Dist: ruff>=0.9.0; extra == "dev"
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: responses>=0.25.0; extra == "dev"
Requires-Dist: sphinx>=8.0; extra == "dev"
Requires-Dist: sphinx-rtd-theme>=3.0; extra == "dev"

# Answers Lib

Library to interact with Expert AI Answers engine.

## Installation

```bash
pip install eai-answers-lib
```

Or install with dev dependencies for development:

```bash
pip install eai-answers-lib[dev]
```

## Quick Start

```python
from eai_answers_lib import Answers, QueryRequest

# Create Answers client
a = Answers(endpoint="https://your-api.example.com/api")

# Create query request using schema (recommended)
query = QueryRequest(question="What are the effects of dietary insect meal?")

# Execute query
result = a(query, pkg="my_knowledge_base", collection="my_collection")
```

## Usage with Dict (Auto-converted)

```python
from eai_answers_lib import Answers

a = Answers(endpoint="https://your-api.example.com/api")

# Pass as dict - automatically converted to QueryRequest
result = a(
    {"question": "Your question here"},
    pkg="my_knowledge_base",
    collection="my_collection"
)
```

## Query Request Options

The `QueryRequest` schema supports all API options:

```python
from eai_answers_lib import QueryRequest, QueryImage, QueryParams

query = QueryRequest(
    question="Your question",
    config_name="default",
    user="user@example.com",
    images=[
        QueryImage(name="image1", data="base64...", mime_type="image/png")
    ],
    params=QueryParams(
        filters=["tag:important"],
        top_k_docs=10,
        debug=True
    ),
    neural={"score_ranges": {...}},
    generative={"generative_answer": True, "stream": False}
)
```

## Authentication

```python
a = Answers(
    endpoint="https://your-api.example.com/api",
    enable_auth=True,
    client_id="your-client-id",
    client_secret="your-client-secret",
    auth_url="https://auth.example.com",
    auth_path="auth",
    realm="your-realm"
)
```

## Environment Variables

- `ANSWERS_ENDPOINT` - API endpoint URL (required)
- `ANSWERS_OWNER_ACCOUNT` - Default owner account (default: "default")
- `ANSWERS_CLIENT_ID` - Client ID for authentication
- `ANSWERS_CLIENT_SECRET` - Client secret for authentication

## Knowledge Base Operations

```python
from eai_answers_lib import Answers

a = Answers(endpoint="https://api.example.com", enable_auth=True)

# List user directories
dirs = a.get_user_dirs("user@example.com")

# List collections in a directory
collections = a.get_dir_collections("root_dir_id")

# Check if KB exists
exists = a.kb_exists("my_kb")

# Create a new KB
a.add_kb("my_new_kb", "user@example.com")

# Create collection
collection_id = a.create_collection("my_kb", "My Collection")
```

## Documentation

Build Sphinx documentation:

```bash
pip install sphinx sphinx-rtd-theme
sphinx-build -b html docs docs/_build
open docs/_build/index.html
```
