Skip to main content

Structured queries from local or online LLM models

Project description

Sibila

Extract structured data from remote or local LLM models. Predictable output is important for serious use of LLMs.

  • Query structured data into Pydantic objects, dataclasses or simple types.
  • Access remote models from OpenAI, Anthropic, Mistral AI and other providers.
  • Use vision models like GPT-4o, to extract structured data from images.
  • Run local models like Llama-3, Phi-3, OpenChat or any other GGUF file model.
  • Sibila is also a general purpose model access library, to generate plain text or free JSON results, with the same API for local and remote models.

No matter how well you craft a prompt begging a model for the format you need, it can always respond something else. Extracting structured data can be a big step into getting predictable behavior from your models.

See What can you do with Sibila?

Structured data

To extract structured data, using a local model:

from sibila import Models
from pydantic import BaseModel

class Info(BaseModel):
    event_year: int
    first_name: str
    last_name: str
    age_at_the_time: int
    nationality: str

model = Models.create("llamacpp:openchat")

model.extract(Info, "Who was the first man in the moon?")

Returns an instance of class Info, created from the model's output:

Info(event_year=1969,
     first_name='Neil',
     last_name='Armstrong',
     age_at_the_time=38,
     nationality='American')

Or to use a remote model like OpenAI's GPT-4, we would simply replace the model's name:

model = Models.create("openai:gpt-4")

model.extract(Info, "Who was the first man in the moon?")

If Pydantic BaseModel objects are too much for your project, Sibila supports similar functionality with Python dataclasses. Also includes asynchronous access to remote models.

Vision models

Sibila supports image input, alongside text prompts. For example, to extract the fields from a receipt in a photo:

Image

from pydantic import Field

model = Models.create("openai:gpt-4o")

class ReceiptLine(BaseModel):
    """Receipt line data"""
    description: str
    cost: float

class Receipt(BaseModel):
    """Receipt information"""
    total: float = Field(description="Total value")
    lines: list[ReceiptLine] = Field(description="List of lines of paid items")

info = model.extract(Receipt,
                     ("Extract receipt information.", 
                      "https://upload.wikimedia.org/wikipedia/commons/6/6a/Receipts_in_Italy_13.jpg"))
info

Returns receipt fields structured in a Pydantic object:

Receipt(total=5.88, 
        lines=[ReceiptLine(description='BIS BORSE TERM.S', cost=3.9), 
               ReceiptLine(description='GHIACCIO 2X400 G', cost=0.99),
               ReceiptLine(description='GHIACCIO 2X400 G', cost=0.99)])

Local vision models based on llama.cpp/llava can also be used.

⭐ Like our work? Give us a star!

Docs

The docs explain the main concepts, include examples and an API reference.

Installation

Sibila can be installed from PyPI by doing:

pip install --upgrade sibila

See Getting started for more information.

Examples

The Examples show what you can do with local or remote models in Sibila: structured data extraction, classification, summarization, etc.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Sibila wouldn't be be possible without the help of great software and people:

Thank you!

Sibila?

Sibila is the Portuguese word for Sibyl. The Sibyls were wise oracular women in ancient Greece. Their mysterious words puzzled people throughout the centuries, providing insight or prophetic predictions, "uttering things not to be laughed at".

Michelangelo's Delphic Sibyl, Sistine Chapel ceiling

Michelangelo's Delphic Sibyl, in the Sistine Chapel ceiling.

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

sibila-0.4.4.tar.gz (168.6 kB view details)

Uploaded Source

Built Distribution

sibila-0.4.4-py3-none-any.whl (97.0 kB view details)

Uploaded Python 3

File details

Details for the file sibila-0.4.4.tar.gz.

File metadata

  • Download URL: sibila-0.4.4.tar.gz
  • Upload date:
  • Size: 168.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for sibila-0.4.4.tar.gz
Algorithm Hash digest
SHA256 057f4a54b0284a78416fe71ad0a06264117764942be13d294fed062334243ffa
MD5 049c87097a42ca7f4a4016a6841593e0
BLAKE2b-256 3fd90fcf85b9c55ab087ab95739cfbc7a1b317d5a69160c822ae342ca42bca59

See more details on using hashes here.

File details

Details for the file sibila-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: sibila-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 97.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for sibila-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5d982ff8817031fc57cc10e461b14cb71c96cba062011eae6afb9534fb5a71f4
MD5 c39b254ff534fb54b175f0ec5081ecd8
BLAKE2b-256 30b39cc19fe82a8b26958d74b552ec91fa7a7a5c650abec30b17403f540a24a7

See more details on using hashes here.

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