Skip to main content

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)])

Another example - extracting the most import elements in a photo:

Image

photo = "https://upload.wikimedia.org/wikipedia/commons/thumb/3/32/Hohenloher_Freilandmuseum_-_Baugruppe_Hohenloher_Dorf_-_Bauerngarten_-_Ansicht_von_Osten_im_Juni.jpg/640px-Hohenloher_Freilandmuseum_-_Baugruppe_Hohenloher_Dorf_-_Bauerngarten_-_Ansicht_von_Osten_im_Juni.jpg"

model.extract(list[str],
              ("Extract up to five of the most important elements in this photo.",
              photo))

Returns a list with the five strings:

['House with red roof and beige walls',
 'Large tree with green leaves',
 'Garden with various plants and flowers',
 'Clear blue sky',
 'Wooden fence']

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 -U 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.

Metadata

Release files for sibila 0.4.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sibila 0.4.5
File Size Uploaded
sibila-0.4.5.tar.gz 169.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sibila 0.4.5
File Interpreter ABI Platform
sibila-0.4.5-py3-none-any.whl Python 3 none any Details

Total release size: 266.4 kB

Release files / sibila-0.4.5.tar.gz

Download URL sibila-0.4.5.tar.gz
Size 169.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9c1d1cb78f64ddc48797040cc912fc575344851936c1ca501b66ef76d7d1f823
BLAKE2b-256 checksum
How to use checksums
b202a25c788e08f926a9d4a441c2a1c605316581314f4f53d958f95a1b6c3001
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release files / sibila-0.4.5-py3-none-any.whl

Download URL sibila-0.4.5-py3-none-any.whl
Size 97.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9072f74ce7d07a0c4fe67a9ee1e41c96b2417c3ec5b34b6196ddaf4ba16f0363
BLAKE2b-256 checksum
How to use checksums
389678b1d2e4b72faeb5fed34acd3beaa113cf7f214598d8d940dce934e38d25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.6

Release history Release notifications | RSS feed

This release

0.4.5 This release

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page