Skip to content

Latest commit

 

History

History
173 lines (148 loc) · 4.25 KB

README.md

File metadata and controls

173 lines (148 loc) · 4.25 KB

License Python Versions

pollinations.ai: (https://pollinations.ai/)

Work with the best generative models from Pollinations using this Python SDK.

Installing

pip install -U pollinations
pip install -U pollinations.ai

# Linux/macOS
python3 -m pip install -U pollinations
python3 -m pip install -U pollinations.ai

# Windows
py -3 -m pip install -U pollinations
py -3 -m pip install -U pollinations.ai

Image Generation

import pollinations

image_model = pollinations.Image(
    model=pollinations.Image.flux(),
    seed="random",
    width=1024,
    height=1024,
    enhance=False,
    nologo=True,
    private=True,
    safe=False,
    referrer="pollinations.py"
)  # or pollinations.Image() to use defaults

image = image_model(
    prompt="A cat with flowers around it."
)

print(image.prompt, image.response)

image.save(
    file="pollinations-image.png"
)

print(pollinations.Image.models())
print(pollinations.Image.flux())
print(pollinations.Image.flux.info())

Async Image Generation

image_model = pollinations.Async.Image()  # Has ALL features and functionality of normal Image class

image = await image_model(
    prompt="A cat with flowers around it."
)

Text Generation

import pollinations

text_model = pollinations.Text(
    model=pollinations.Text.openai(),
    system="You are a helpful assistant.",
    contextual=True,
    messages=[  # or [] or None
        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="random",
    jsonMode=False,
    referrer="pollinations.py"
)

response = text_model(
    prompt="Hello.",
    display=True,  # Simulate typing,
    encode=True  # Use proper encoding
)

print(response.prompt, response.response)

print(pollinations.Text.models())
print(pollinations.Text.openai())
print(pollinations.Text.openai.info())

Async Text Generation

text_model = pollinations.Async.Text()  # Has ALL features and functionality of normal Text class

response = await text_model(
    prompt="Hello."
)

Image Request Building

import pollinations

image_request = pollinations.Image.Request(
    model=pollinations.Image.flux(),
    prompt="A cat with flowers around it.",
    seed="random",
    width=1024,
    height=1024,
    enhance=False,
    nologo=True,
    private=True,
    safe=False,
    referrer="pollinations.py"
)

image = image_request()

print(image.model, image.prompt, image.response)

Text Request Building

import pollinations

text_request = pollinations.Text.Request(
    model=pollinations.Text.openai(),
    prompt="Hello, how are you?",
    system="You are a helpful assistant.",
    contextual=True,
    messages=[  # or [] or None
        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="random",
    jsonMode=False,
    referrer="pollinations.py"
)

response = text_request(
    encode=True  # Use proper encoding
)
print(response)

Links