Skip to main content

No project description provided

Project description

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

Project details


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

If you're not sure about the file name format, learn more about wheel file names.

lazyopenai-0.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file lazyopenai-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for lazyopenai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0a1bd32a75148a86e35b66e6a305be65ccfd7108e4d188d7cfb611421679ba7a
MD5 30edf550cbbe6c93908bc2160f5ff352
BLAKE2b-256 02919fb0cb7e43d95cd60efde60fcfb08673db02815f7b7e8421ce9a0267fd82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page