Skip to main content

Effortlessly generate LLM APIs by simply defining input and output schemas.

Project description

llmgen

PyPI

Effortlessly generate LLM APIs by simply defining input and output schemas (by pydantic).

Quick Start

Example:

from pydantic import BaseModel, Field
from llmgen import OpenAiApiFactory

# describe your input
class _JokeRequest(BaseModel):
    """Request for a joke"""

    theme: str = Field(description="The theme of the joke")


# describe your output
class _JokeResponse(BaseModel):
    """A joke response"""

    setup: str = Field(description="The setup of the joke")
    punchline: str = Field(description="The punchline of the joke (the funny part)")
    description: str = Field(description="Description of why the joke is funny")
    level: int = Field(description="Funny level of the joke (1-5)", le=5, ge=1)



factory = OpenAiApiFactory(
    api_key="your api key here",
)

# Create an API
api = factory.make_api(_JokeRequest, _JokeResponse)

# Call the API
res = api.call(_JokeRequest(theme="cat"))

print(res.model_dump())
"""
A joke response like:
{
'setup': 'Why was the cat sitting on the computer?', 
'punchline': 'Because it wanted to keep an eye on the mouse!', 
'description': "This joke is funny because it plays on the double meaning of 'mouse'—the computer accessory and the animal that cats typically chase. The image of a cat being so tech-savvy is also amusing.", 
'level': 4
}
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llmgen-0.1.2.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

llmgen-0.1.2-py3-none-any.whl (3.8 kB view hashes)

Uploaded Python 3

Supported by

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