Metadata-Version: 2.4
Name: litestruct
Version: 0.0.2
Summary: Structured output with different LLM providers
Home-page: https://github.com/gautam-e/litestruct
Author: Gautam Ethiraj
Author-email: gautam.e@gmail.com
License: Apache Software License 2.0
Keywords: nbdev jupyter notebook python
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: litellm
Requires-Dist: pydantic
Provides-Extra: dev
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: provides-extra
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# litestruct


<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

This file will become your README and also the index of your
documentation.

## Developer Guide

If you are new to using `nbdev` here are some useful pointers to get you
started.

### Install litestruct in Development mode

``` sh
# make sure litestruct package is installed in development mode
$ pip install -e .

# make changes under nbs/ directory
# ...

# compile to have changes apply to litestruct
$ nbdev_prepare
```

## Usage

### Installation

Install latest from the GitHub
[repository](https://github.com/gautam-e/litestruct):

``` sh
$ pip install git+https://github.com/gautam-e/litestruct.git
```

or from [pypi](https://pypi.org/project/litestruct/)

``` sh
$ pip install litestruct
```

### Documentation

Documentation can be found hosted on this GitHub
[repository](https://github.com/gautam-e/litestruct)’s
[pages](https://gautam-e.github.io/litestruct/). Additionally you can
find package manager specific guidelines on
[conda](https://anaconda.org/gautam-e/litestruct) and
[pypi](https://pypi.org/project/litestruct/) respectively.

## How to use

``` python
from litestruct import *
from pydantic import BaseModel
```

``` python
model="azure/gpt-4o-2024-08-06"
system_prompt = "Extract the event information."
```

``` python
# This defines the output response format that we want
class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: list[str]
```

``` python
user_prompt = "Alice and Bob are going to Carmen's Birtday party on 22nd March 2025"
```

``` python
r = structured_output(model=model,
                      system_prompt=system_prompt,
                      user_prompt=user_prompt,
                      response_format=CalendarEvent, #Note this is the class name (without the `()`)
                 )

r.model_dump()
```

    {'name': "Carmen's Birthday Party",
     'date': '22nd March 2025',
     'participants': ['Alice', 'Bob']}
