Skip to content

ivanbelenky/jsonllm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

c6eeb82 · Oct 12, 2024

History

39 Commits
Jul 7, 2023
Oct 12, 2024
Jul 10, 2023
Jul 3, 2023
Jul 10, 2023
Oct 8, 2024
Mar 24, 2024

Repository files navigation

jsonllm


image

Installation


From PyPI

pip install python-jsonllm

From source

git clone https://github.com/ivanbelenky/jsonllm.git
cd jsonllm
python3 -m pip install -e .

Documentation


Schema type

class SchemaKey(TypedDict):
    name: Optional[str]
    type: Optional[type]
    default: JSONCompatible
    required: Optional[bool]
    instructions: Optional[str]
    valid: Optional[Caster] 
    caster: Optional[Validator]

class Schema(TypedDict):
    __key__: Union[SchemaKey, 'Schema'] # nested schemas

Example

import os

import jsonllm

#assert os.environ.get('ANTHROPIC_API_KEY') != None
#assert os.environ.get('OPENAI_API_KEY') != None

person = {
    'first_name': {
        'type': str,
        'required': True,
        'instructions': 'Find the first name, if not found input John'        
    },
    'last_name': {
        'type': str,
        'required': True,
        'instructions': 'Find the last name, if not found input Doe'
    },
    'date_of_birth': {
        'name': 'dob', # this exists for cases where the name of the desired schema key is not self explanatory
        'type': str,
        'instructions': 'Find the date of birth and cast it to isoformat'
    }
}

message = 'My name is John Connor, I think I was born 0 of Unix time.'
response = jsonllm.loads(message, person, model='claude-3-opus-20240229')
print(response.response)

{
    'first_name': 'John',
    'last_name': 'Connor',
    'dob': '1970-01-01'
}

About

jsonllm loader

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages