LLM please cast to JSON
Project description
jsonllm
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
import openai
# vertexai.init(project_id='jsonllm-rocks?', location='us-central1') |
# openai.api_key = 'sk-...'
os.environ['ANTHROPIC_API_KEY'] = '...' # or load env
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'
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-jsonllm-0.0.2.tar.gz
(7.7 kB
view details)
Built Distribution
File details
Details for the file python-jsonllm-0.0.2.tar.gz
.
File metadata
- Download URL: python-jsonllm-0.0.2.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d1c20ba6bdcaa024102990641b9b37186c902882ea3414b572096167a04b6a8c |
|
MD5 | 145bec4257b42986db508e9a8bbbd26b |
|
BLAKE2b-256 | 8dd012a3bc9901e8a71b5b963c5abe79f6832f0a4b33eeebd33f09532668d935 |
File details
Details for the file python_jsonllm-0.0.2-py3-none-any.whl
.
File metadata
- Download URL: python_jsonllm-0.0.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.8.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f661669702f8f51b0778e319f251aac888501f527ceee1e2b5b34ebbf7451424 |
|
MD5 | 475aaec8e29a914b44e8cec5894452d1 |
|
BLAKE2b-256 | af34d42625cefdefa6f9dd08808df06df91a6f20dcf1d8012361444cbeedb866 |