Skip to main content

Structured output with different LLM providers

Project description

litestruct

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

# 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:

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

or from pypi

$ pip install litestruct

Documentation

Documentation can be found hosted on this GitHub repository’s pages. Additionally you can find package manager specific guidelines on conda and pypi respectively.

How to use

from litestruct import *
from pydantic import BaseModel
model="azure/gpt-4o-2024-08-06" # e.g. openai/gpt-4o-2024-08-06 would use the standard OpenAI
system_prompt = "Extract the event information."

class CalendarEvent(BaseModel):
    name: str
    date: str
    participants: list[str]
user_prompt = "Alice and Bob are going to Carmen's birthday party on 22nd March 2025"
r = structured_output(model=model,
                      system_prompt=system_prompt,
                      response_format=CalendarEvent, #Note this is the class name (without the `()`)
                      user_prompt=user_prompt,
                 )

r.model_dump()
{'name': "Carmen's Birthday Party",
 'date': '2025-03-22',
 'participants': ['Alice', 'Bob']}

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

litestruct-0.0.3.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

litestruct-0.0.3-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file litestruct-0.0.3.tar.gz.

File metadata

  • Download URL: litestruct-0.0.3.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for litestruct-0.0.3.tar.gz
Algorithm Hash digest
SHA256 382e8411aa4ce87397c6eff79d4a33505b07026acc35db0b20cafe570366d6d9
MD5 dc4d97f6377e9da665f7c698a5ac6451
BLAKE2b-256 0e15d23e2424a23d8ddd7f307eda4994e853d4e87abd52b2f5228a2ae93afc7f

See more details on using hashes here.

File details

Details for the file litestruct-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: litestruct-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for litestruct-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2b5c3f42d88d311ce8beb74a21f7dc4b49ce74f0a96057bd3507817130199d2e
MD5 a13460fb5c4ea10fe50a84ac3ee41af8
BLAKE2b-256 c2368e73b1dd885b75c695c62a56bdc976c7a3ba412b5032e0575b5070c1b98e

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