Легкая 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
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pollinations_simple-1.0.0-py3-none-any.whl.
File metadata
- Download URL: pollinations_simple-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63412da50ad1275709779afce9a5b0fecfe9c945f677bb843e10da4d1c6c064d
|
|
| MD5 |
60f2fbf706726436f518f15cf3a5da6b
|
|
| BLAKE2b-256 |
ebdc553a8daa6bae5203a4fa9ef7cbc716cea8c5e5502424216133628580cf57
|