Skip to content

Latest commit

 

History

History
315 lines (277 loc) · 6.18 KB

CHANGELOG.md

File metadata and controls

315 lines (277 loc) · 6.18 KB

License Python Versions

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

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

FIX 2.3.11

+ Fixed small jsonMode issue

UPDATE 2.3.10

+ Option to add referrer in requests (Text, Text.Request, Image, Image.Request)

Example

request = Text(
    ...,
    referrer="my_app"
)

FIX 2.3.9

+ Fixed __repr__ issues

FIX 2.3.8

+ Fixed Async.Text.Request.images issue

FIX 2.3.7

+ Major contextual fix in Aysnc.Text
+ Fixed jsonMode 

FIX 2.3.6

+ Fixed Text.Request encoding issues
+ Fixed Async.Text.Request encoding issues
+ Added `deepseek` Text model

FIX 2.3.5

+ Fixed encoding error in Text.Request.__call__

FIX 2.3.4

+ Fixed Async.Text.Message.__call__ issue

FIX 2.3.3

+ Updated license & badge markdown

UPDATE 2.3.2

+ Async class
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())

FIX 2.3.1

+ Updated classifiers
+ Updated keywords
+ Docstrings

UPDATE 2.3

+ 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)

Links