pollinations.ai: (https://pollinations.ai/)
Work with the best generative models from Pollinations using this Python SDK.
+ Fixed small jsonMode issue
+ Option to add referrer in requests (Text, Text.Request, Image, Image.Request)
request = Text(
...,
referrer="my_app"
)
+ Fixed Async.Text.Request.images issue
+ Major contextual fix in Aysnc.Text
+ Fixed jsonMode
+ Fixed Text.Request encoding issues
+ Fixed Async.Text.Request encoding issues
+ Added `deepseek` Text model
+ Fixed encoding error in Text.Request.__call__
+ Fixed Async.Text.Message.__call__ issue
+ Updated license & badge markdown
import asyncio
import pollinations
async def async_test():
text_model = pollinations.Async.Text() # Has ALL features and functionality as normal Text class
await text_model(
prompt="Hello"
)
print(text_model.response)
image_model = pollinations.Async.Image() # Has ALL features and functionality as normal Image class
await image_model(
prompt="A black cat."
)
await image_model.save(
file="pollinations-image.png"
)
asyncio.run(async_test())
+ Updated classifiers
+ Updated keywords
+ Docstrings
+ Updated Text class
+ Updated Image class
"""
class Text(
model: str = "openai",
system: str = "",
contextual: bool = False,
messages: list = [],
seed: int = "random",
jsonMode: bool = False,
...
)
"""
model = pollinations.Text(
model=pollinations.Text.openai(),
system="You are a helpful assistant...",
contextual=True,
messages=[
pollinations.Text.Message(
role="user",
content="What is the capital of France?"
),
pollinations.Text.Message(
role="assistant",
content="The capital of France is Paris."
)
],
seed=42,
jsonMode=True
)
"""
(method) def info(...) -> dict
"""
print(pollinations.Text.openai.info())
"""
(method) def image(
file: str | list,
...
) -> Text
"""
model.image("my_file.png")
print("\n", model(
prompt="What do you see in this image?"
).response)
"""
(method) def __call__(
prompt: str = None,
display: bool = False,
...,
encode: bool = False
) -> Text
"""
response = model(encode=True) # use proper encoding
print("\n", response.response, response.time, response.request) # The capital of France is Paris., ..., Text.Request(...)
print("\n", model(
prompt="Hello.",
display=True, # simulate typing
encode=False
).response)
# ---------------------------------------------- #
"""
class Request(
model: str,
prompt: str,
...,
system: str = "",
contextual: bool = False,
messages: List[dict] = None,
seed: str | int = "random",
jsonMode: bool = False
)
"""
"""
class Message(
role: str,
content: str,
images: dict | list = None
)
(method) def image(
file: str,
...
) -> dict
"""
request = pollinations.Text.Request(
model=pollinations.Text.openai(),
prompt="Hello. Whats in this image?",
system="You are a helpful assistant...",
contextual=True,
messages=[
pollinations.Text.Message(
role="user",
content="What is the capital of France?"
),
pollinations.Text.Message(
role="assistant",
content="The capital of France is Paris."
)
],
images=[
pollinations.Text.Message.image("my_file.png"),
pollinations.Text.Message.image("my_file2.png")
],
seed=42,
jsonMode=True
)
print("\n", request(
encode=True
))
"""
class Image(
model: str = "flux",
seed: str | int = "random",
width: int = 1024,
height: int = 1024,
enhance: bool = False,
nologo: bool = False,
private: bool = False,
safe: bool = False
)
"""
model = pollinations.Image(
model=pollinations.Image.flux(),
seed="random",
width=1024,
height=1024,
enhance=False,
nologo=False,
private=False,
safe=False
)
"""
(method) def info(...) -> dict
"""
print(pollinations.Image.flux.info())
"""
(method) def __call__(
prompt: str,
*args: Any
) -> Image
"""
image = model(
prompt="A cat with flowers around it."
)
print(image.prompt, image.file)
"""
(method) def save(file: str = "pollinations-image.png") -> Image
"""
image.save(
file="pollinations-image.png"
)
# ---------------------------------------------- #
"""
class Request(
model: str = "flux",
prompt: str = "",
seed: str | int = "random",
width: int = 1024,
height: int = 1024,
enhance: bool = False,
nologo: bool = False,
private: bool = False,
safe: bool = False
)
"""
request = pollinations.Image.Request(
model=pollinations.Image.flux(),
prompt="A cat with flowers around it.",
seed="random",
width=1024,
height=1024,
enhance=False,
nologo=False,
private=False,
safe=False
)
print(request)
request()
print(request.prompt, request.response)