Skip to main content

Легкая Python библиотека для работы с Pollinations AI

Project description

🌸 Pollinations AI - Python библиотека

Простая и удобная библиотека для работы с текстовыми моделями Pollinations AI.

✨ Возможности

  • 🚀 Простой запрос одной функцией ask()
  • 💬 Чат с историей сообщений
  • 🔄 Стриминг ответов в реальном времени
  • 🎯 Поддержка разных моделей (Gemini, Mistral, OpenAI)
  • 📝 JSON режим для структурированных ответов
  • 🆓 Бесплатно без API ключа

📦 Установка

# Зависимость только requests
pip install requests

Скопируйте папку pollinations/ в ваш проект.

🚀 Быстрый старт

Самый простой способ

from pollinations import ask

answer = ask("Что такое Python?")
print(answer)

Использование клиента

from pollinations import PollinationsClient

client = PollinationsClient(
    model="gemini",  # модель по умолчанию
    system_prompt="Отвечай кратко"
)

response = client.ask("Объясни рекурсию")
print(response)

Чат с историей

from pollinations import PollinationsClient, Message

client = PollinationsClient()

messages = [
    Message("system", "Ты полезный ассистент"),
    Message("user", "Меня зовут Никита"),
    Message("assistant", "Привет, Никита!"),
    Message("user", "Как меня зовут?"),
]

response = client.chat(messages)
print(response.content)  # "Тебя зовут Никита"

Стриминг

from pollinations import PollinationsClient

client = PollinationsClient()

for chunk in client.stream("Напиши историю"):
    print(chunk, end="", flush=True)

JSON режим

from pollinations import ask

data = ask(
    "Верни JSON с полями: name, age, city",
    json_mode=True
)
print(data)  # {"name": "...", "age": 25, "city": "..."}

🔧 API

PollinationsClient

client = PollinationsClient(
    api_key=None,          # Опционально, для повышенных лимитов
    model="openai",        # Модель по умолчанию
    system_prompt=None,    # Системный промпт по умолчанию
    timeout=60,            # Таймаут в секундах
)

Методы

Метод Описание
ask(prompt) Простой запрос → строка
chat(messages) Чат с историей → ChatResponse
stream(prompt) Стриминг → итератор
quick(prompt) Быстрый GET запрос → строка
get_models() Список моделей → List[Model]

Message

from pollinations import Message

msg = Message(
    role="user",     # "user", "assistant", "system"
    content="Текст"
)

Также можно использовать обычные словари:

messages = [
    {"role": "system", "content": "..."},
    {"role": "user", "content": "..."}
]

ChatResponse

response = client.chat(messages)

response.content       # Текст ответа
response.text          # Алиас для content
response.model         # Использованная модель
response.finish_reason # Причина завершения
response.usage         # Статистика токенов
response.raw_response  # Полный ответ API

🤖 Доступные модели

Модель Описание Особенности
openai GPT-OSS 20B Reasoning
gemini Gemini 2.5 Flash Vision
mistral Mistral 3.2 24B Tools

Получить актуальный список:

client = PollinationsClient()
for model in client.get_models():
    print(f"{model.name}: {model.description}")

📝 Примеры

Смотрите файл examples.py для полных примеров.

📄 Лицензия

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pollinations_simple-1.0.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file pollinations_simple-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pollinations_simple-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63412da50ad1275709779afce9a5b0fecfe9c945f677bb843e10da4d1c6c064d
MD5 60f2fbf706726436f518f15cf3a5da6b
BLAKE2b-256 ebdc553a8daa6bae5203a4fa9ef7cbc716cea8c5e5502424216133628580cf57

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page