Skip to main content

Lazy OpenAI

Lazy OpenAI is a Python library that simplifies interaction with OpenAI's API. It provides easy-to-use functions to generate text and structured outputs using Pydantic models.

Installation

To install Lazy OpenAI, run the following command:

pip install lazyopenai

Usage

from lazyopenai import generate

print(generate("Hi"))

Structured Outputs

from pydantic import BaseModel
from rich import print

from lazyopenai import generate


class Step(BaseModel):
    explanation: str
    output: str


class MathReasoning(BaseModel):
    steps: list[Step]
    final_answer: str


# https://platform.openai.com/docs/guides/structured-outputs?context=ex1#chain-of-thought
resp = generate("how can I solve 8x + 7 = -23", response_format=MathReasoning)
print(resp)

Function Calling

from pydantic import Field

from lazyopenai import generate
from lazyopenai.types import BaseTool


class AddNumbers(BaseTool):
    a: float = Field(..., description="First number to add")
    b: float = Field(..., description="Second number to add")

    def __call__(self) -> float:
        print("function called")
        return self.a + self.b


resp = generate(
    "100 + 10 = ?",
    tools=[AddNumbers],
)
print(resp)

TODO

  • Function calling
  • Memory
  • Async

Metadata

Release files for lazyopenai 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for lazyopenai 0.5.0
File Interpreter ABI Platform
lazyopenai-0.5.0-py3-none-any.whl Python 3 none any Details

Release files / lazyopenai-0.5.0-py3-none-any.whl

Download URL lazyopenai-0.5.0-py3-none-any.whl
Size 9.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3ae585719321f3b9305ab83cee342866c19d7ee943887ec5ecb9500007010d0
BLAKE2b-256 checksum
How to use checksums
3bf82045b2ba19eeb7bc115cb611055620e11994b7d28ba789f91ef7069d734e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.7

Release history Release notifications | RSS feed

This release

0.5.0 This release

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page