Metadata-Version: 2.1
Name: python-jsonllm
Version: 0.0.3.1
Summary: LLM please cast to JSON
Home-page: https://github.com/ivanbelenky/jsonllm
Author: Ivan Belenky
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: retry ==0.9.2
Requires-Dist: vertexai ==1.43.0
Requires-Dist: openai ==1.14.2
Requires-Dist: google-cloud-aiplatform ==1.44.0
Requires-Dist: tiktoken ==0.6.0
Requires-Dist: anthropic ==0.21.3
Requires-Dist: python-dotenv ==1.0.1

## `jsonllm` 
-----------------------

![image](https://github.com/ivanbelenky/jsonllm/assets/49297252/d0526122-0199-4434-ad3c-19d11a3a9fd4)

## Installation
---------------

### From PyPI

```bash
pip install python-jsonllm
```


### From source

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

## Documentation
----------------

### Schema type

```python
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

```python
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',
        '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'
}

```
