Metadata-Version: 2.4
Name: dialogmind-sdk
Version: 1.1.0
Summary: Python SDK для интеграции с DialogMind API: FAQ/RAG, аналитика, оператор и внешние боты со своей LLM.
Author-email: DialogMind <support@dialog-mind.ru>
License: MIT
Project-URL: Documentation, https://dialog-mind.ru
Project-URL: Source, https://github.com/dialogmind/dialogmind-sdk
Keywords: dialogmind,sdk,chatbot,faq,rag,analytics,telegram
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Communications :: Chat
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.28.0

# Быстрый старт DialogMind SDK

## Установка

### Вариант 1: Из локальной папки (для разработки)

```bash
cd dialogmind_sdk
pip install -e .
```

### Вариант 2: Прямое использование (без установки)

```python
import sys
sys.path.insert(0, '/path/to/dialogmind_sdk')

from dialogmind_sdk import DialogMindClient
```

## Минимальный пример

```python
from dialogmind_sdk import DialogMindClient

# Инициализация
client = DialogMindClient(
    api_key="ваш_api_ключ",
    bot_id="ваш_bot_id"
)

# Получить ответ от AI
response = client.get_ai_response(
    chat_id="123456789",
    message="Привет!"
)

print(response)
```

## Интеграция с Telegram ботом

```python
from dialogmind_sdk import DialogMindClient
from telegram import Update
from telegram.ext import Application, MessageHandler, filters

client = DialogMindClient(
    api_key="ваш_api_ключ",
    bot_id="ваш_bot_id"
)

def handle_message(update: Update, context):
    response = client.process_message_with_faq(
        chat_id=str(update.effective_chat.id),
        user_message=update.message.text,
        username=update.effective_user.username
    )
    update.message.reply_text(response)

app = Application.builder().token("YOUR_TOKEN").build()
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message))
app.run_polling()
```

## Где получить API ключ?

1. Зайдите на https://dialog-mind.ru
2. Перейдите в "Интеграция"
3. Выберите бота
4. Нажмите "Сгенерировать API ключ"
5. Скопируйте API ключ и Bot ID

## Основные методы

- `handle_external_message(chat_id, user_message, llm_callback, ...)` —
  **рекомендуется для внешних ботов со своей LLM**. SDK сам проверяет FAQ/RAG
  в DialogMind, и вызывает вашу LLM только если в базе ничего не найдено.
- `process_message_with_faq(chat_id, user_message, ...)` — полный цикл,
  если LLM на стороне DialogMind (внутренний бот).
- `get_ai_response(chat_id, message)` — получить ответ от AI на платформе.
- `search_faq(query)` / `get_faq_answer(query)` — низкоуровневый поиск в FAQ.

## Внешний бот со своей LLM (рекомендованный сценарий)

Установите SDK и подключите свою LLM функцией `llm_callback`. SDK сам:
1) сохранит входящее сообщение в DialogMind для аналитики,
2) проверит FAQ/RAG в DialogMind,
3) вернёт готовый ответ из FAQ (вашу LLM не вызовет),
4) при miss — вызовет вашу `llm_callback(user_message, rag_context)`,
5) сохранит ответ бота в DialogMind для аналитики.

```python
from dialogmind_sdk import DialogMindClient

client = DialogMindClient(
    api_key="ваш_api_ключ",
    bot_id="UUID бота из карточки бота в DialogMind",
)

def my_llm(user_message, rag_context=None):
    # Здесь вызывайте свою LLM (OpenAI/YandexGPT/локальную).
    # rag_context — None или список чанков из RAG DialogMind.
    return "Ответ от моей LLM на: " + user_message

reply = client.handle_external_message(
    chat_id="123456789",
    user_message="Как оплатить?",
    llm_callback=my_llm,
)
print(reply)
```

Подробнее в DEVELOPER_GUIDE.md

