json-paws


Namejson-paws JSON
Version 0.1.9 PyPI version JSON
download
home_pagehttps://github.com/caspianmoon/jsonpaws
SummaryA library for generating structured JSON using GPT-4o.
upload_time2024-08-04 23:32:04
maintainerNone
docs_urlNone
authorKhazar Ayaz
requires_python>=3.6
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # jsonpaws

**jsonpaws** is an open-source Python library for generating structured and consistent JSON outputs using GPT-4o. It provides modes for **analysis**, **synthesis**, and **image analysis** to extract and generate structured JSON data from unstructured text or based on a given schema.

## Features
* Analysis Mode: Extract structured information from unstructured text. Perfect for data extraction and transformation tasks.
* Synthesis Mode: Generate realistic structured JSON data from a specified schema, ideal for creating synthetic datasets for simulations or testing.
* Image Analysis Mode: Analyze images to extract structured data and generate JSON outputs, making it suitable for computer vision applications.
* Customizable: Allows users to configure the OpenAI model and temperature settings for tailored data generation.
* Easy Integration: Seamlessly integrates into existing Python projects with a straightforward API and minimal setup.

## Installation

Install jsonpaws using pip:
```
pip install json_paws
```

## Getting Started
### Setting the API Key

To use jsonpaws, you'll need an OpenAI API key. You can set it as an environment variable or pass it directly to the library.

**Environment Variable**
```
export OPENAI_API_KEY=your_api_key
```

**Directly in Your Code**

```
import openai

openai.api_key = "your_api_key"
```

### Importing jsonpaws
Begin by importing the necessary components from the library:

```
from jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor
```

## Usage
### Analysis Mode
In **Analysis Mode**, jsonpaws extracts structured data from unstructured text using a predefined JSON schema.

**Example**
```
import json
from jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor

# Set your OpenAI API key here
api_key = "OPENAI-API-KEY"

# Define the JSON schema
json_schema = {
    "type": "object",
    "properties": {
        "report_date": {"type": "string"},
        "patients": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {"type": "string"},
                    "firstName": {"type": "string"},
                    "lastName": {"type": "string"},
                    "age": {"type": "number", "minimum": 0, "maximum": 120},
                    "gender": {"type": "string", "enum": ["male", "female"]},
                    "diagnosis": {"type": "string"},
                    "medications": {
                        "type": "array",
                        "items": {"type": "string"}
                    }
                }
            }
        }
    }
}

# Initialize the schema parser
schema_parser = JSONSchemaParser(json_schema)

# For analysis mode
instructions = """
Extract patient information from the text and populate the JSON schema accordingly.
The report dated August 4, 2024, details the patient records for the day.
Among the patients, there is John Doe, a 45-year-old male diagnosed with hypertension, who is currently prescribed lisinopril and atorvastatin.
Another patient, Jane Smith, a 30-year-old female, has been diagnosed with diabetes and is on metformin.
The list also includes Sam Brown, a 60-year-old male suffering from arthritis, for which he is taking ibuprofen and methotrexate.
"""
prompt_generator_analysis = PromptGenerator(mode='analysis')
content_generator_analysis = ContentGenerator(api_key=api_key, model='gpt-4o', mode='analysis', instructions=instructions)
analysis_processor = JSONProcessor(schema_parser, prompt_generator_analysis, content_generator_analysis, mode='analysis')

# Process the data
generated_json_analysis = analysis_processor.process(instructions=instructions, schema=json_schema)

# Print the extracted structured JSON
print("Generated JSON (Analysis):", json.dumps(generated_json_analysis, indent=4))
```

**Output**
```
Generated JSON (Analysis): {
    "report_date": "August 4, 2024",
    "patients": [
        {
            "id": "1",
            "firstName": "John",
            "lastName": "Doe",
            "age": 45,
            "gender": "male",
            "diagnosis": "hypertension",
            "medications": [
                "lisinopril",
                "atorvastatin"
            ]
        },
        {
            "id": "2",
            "firstName": "Jane",
            "lastName": "Smith",
            "age": 30,
            "gender": "female",
            "diagnosis": "diabetes",
            "medications": [
                "metformin"
            ]
        },
        {
            "id": "3",
            "firstName": "Sam",
            "lastName": "Brown",
            "age": 60,
            "gender": "male",
            "diagnosis": "arthritis",
            "medications": [
                "ibuprofen",
                "methotrexate"
            ]
        }
    ]
}
```

### Synthesis Mode
In **Synthesis Mode**, jsonpaws generates realistic structured JSON data from a specified schema.

**Example**
```
import json
from jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor

# Set your OpenAI API key here
api_key = "OPENAI-API-KEY"

# Define the JSON schema
json_schema = {
    "type": "object",
    "properties": {
        "report_date": {"type": "string"},
        "patients": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {"type": "string"},
                    "firstName": {"type": "string"},
                    "lastName": {"type": "string"},
                    "age": {"type": "number", "minimum": 0, "maximum": 120},
                    "gender": {"type": "string", "enum": ["male", "female"]},
                    "diagnosis": {"type": "string"},
                    "medications": {
                        "type": "array",
                        "items": {"type": "string"}
                    }
                }
            }
        }
    }
}

# Initialize the schema parser
schema_parser = JSONSchemaParser(json_schema)

# Instructions for synthesis mode
instructions = """
Generate a JSON with a report date and a list of patients, where each patient has fields like id, firstName, lastName, age, gender, diagnosis, and medications.
"""

# For synthesis mode
prompt_generator_synthesis = PromptGenerator(mode='synthesis')
content_generator_synthesis = ContentGenerator(api_key=api_key, model='gpt-4o', mode='synthesis', instructions=instructions)
synthesis_processor = JSONProcessor(schema_parser, prompt_generator_synthesis, content_generator_synthesis, mode='synthesis')

# Generate the synthetic JSON data
generated_json_synthesis = synthesis_processor.process(instructions=instructions, schema=json_schema)

# Print the generated synthetic JSON
print("Generated JSON (Synthesis):", json.dumps(generated_json_synthesis, indent=4))

```
**Output**

```
Generated JSON (Synthesis): {
    "report_date": {
        "report_date": "2023-10-18",
        "patients": [
            {
                "id": "P001",
                "firstName": "John",
                "lastName": "Doe",
                "age": 45,
                "gender": "male",
                "diagnosis": "Hypertension",
                "medications": [
                    "Lisinopril",
                    "Amlodipine"
                ]
            },
            {
                "id": "P002",
                "firstName": "Jane",
                "lastName": "Smith",
                "age": 30,
                "gender": "female",
                "diagnosis": "Diabetes Type 2",
                "medications": [
                    "Metformin",
                    "Glyburide"
                ]
            },
            {
                "id": "P003",
                "firstName": "Emily",
                "lastName": "Johnson",
                "age": 60,
                "gender": "female",
                "diagnosis": "Osteoarthritis",
                "medications": [
                    "Ibuprofen",
                    "Glucosamine"
                ]
            },
            {
                "id": "P004",
                "firstName": "Michael",
                "lastName": "Brown",
                "age": 72,
                "gender": "male",
                "diagnosis": "Congestive Heart Failure",
                "medications": [
                    "Furosemide",
                    "Digoxin"
                ]
            }
        ]
    },
    "patients": {
        "report_date": "2023-10-15",
        "patients": [
            {
                "id": "P001",
                "firstName": "John",
                "lastName": "Doe",
                "age": 45,
                "gender": "male",
                "diagnosis": "Hypertension",
                "medications": [
                    "Lisinopril",
                    "Amlodipine"
                ]
            },
            {
                "id": "P002",
                "firstName": "Jane",
                "lastName": "Smith",
                "age": 34,
                "gender": "female",
                "diagnosis": "Type 2 Diabetes",
                "medications": [
                    "Metformin",
                    "Glipizide"
                ]
            },
            {
                "id": "P003",
                "firstName": "Emily",
                "lastName": "Johnson",
                "age": 28,
                "gender": "female",
                "diagnosis": "Anxiety Disorder",
                "medications": [
                    "Sertraline"
                ]
            },
            {
                "id": "P004",
                "firstName": "Michael",
                "lastName": "Williams",
                "age": 62,
                "gender": "male",
                "diagnosis": "Chronic Obstructive Pulmonary Disease",
                "medications": [
                    "Tiotropium",
                    "Albuterol"
                ]
            },
            {
                "id": "P005",
                "firstName": "David",
                "lastName": "Brown",
                "age": 50,
                "gender": "male",
                "diagnosis": "Hyperlipidemia",
                "medications": [
                    "Atorvastatin"
                ]
            },
            {
                "id": "P006",
                "firstName": "Sophia",
                "lastName": "Davis",
                "age": 40,
                "gender": "female",
                "diagnosis": "Asthma",
                "medications": [
                    "Fluticasone",
                    "Salbutamol"
                ]
            },
            {
                "id": "P007",
                "firstName": "Daniel",
                "lastName": "Miller",
                "age": 75,
                "gender": "male",
                "diagnosis": "Heart Failure",
                "medications": [
                    "Furosemide",
                    "Carvedilol"
                ]
            },
            {
                "id": "P008",
                "firstName": "Olivia",
                "lastName": "Garcia",
                "age": 22,
                "gender": "female",
                "diagnosis": "Major Depressive Disorder",
                "medications": [
                    "Citalopram"
                ]
            },
            {
                "id": "P009",
                "firstName": "James",
                "lastName": "Martinez",
                "age": 30,
                "gender": "male",
                "diagnosis": "Bipolar Disorder",
                "medications": [
                    "Lithium",
                    "Lamotrigine"
                ]
            },
            {
                "id": "P010",
                "firstName": "Ava",
                "lastName": "Hernandez",
                "age": 55,
                "gender": "female",
                "diagnosis": "Osteoarthritis",
                "medications": [
                    "Ibuprofen",
                    "Glucosamine"
                ]
            }
        ]
    }
}          
```
### Image Analysis Mode

In **Image Analysis Mode**, jsonpaws analyzes images to extract structured JSON data.

**Example**
```
import json
from jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor


# Set your OpenAI API key here
api_key = 'OPENAI-API-KEY'

# Define the JSON schema
json_schema = {
    "type": "object",
    "properties": {
        "logos_in_image": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "scene": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "demographics": {
            "type": "object",
            "properties": {
                "age_group": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "Under 5 years", "5 to 9 years", "10 to 14 years",
                            "15 to 19 years", "20 to 24 years", "25 to 29 years",
                            "30 to 34 years", "35 to 39 years", "40 to 44 years",
                            "45 to 49 years", "50 to 54 years", "55 to 59 years",
                            "60 to 64 years", "65 to 69 years", "70 to 74 years",
                            "75 to 79 years", "80 to 84 years", "85 years and over"
                        ]
                    }
                },
                "races": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": [
                            "White", "African American", "American Indian", "Asian", "Other"
                        ]
                    }
                },
                "gender": {
                    "type": "array",
                    "items": {
                        "type": "string",
                        "enum": ["Male", "Female", "Non-binary", "Other"]
                    }
                }
            }
        },
        "objects": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "activity": {
            "type": "array",
            "items": {
                "type": "string"
            }
        }
    }
}


# Instructions for image analysis
instructions = '''
Analyze the following image and provide the results in JSON
'''
image_url = "https://cdn1.picuki.com/hosted-by-instagram/q/0exhNuNYnjBGZDHIdN5WmL9I2PwkAQ9OKftSQ7e71yJjMBhsLH6QvJA0mpCl6yRxIwVgFDeSYztj4oouUFlQAz17NEfWT7yKRTxV7q2RVean0Fph9JBikLc0LnIbZ3ap8MQvU2bABCxWFOkXULjh7uZDu7%7C%7CzNnZSyWaRMdsCmWYK4dv1CPol9YIosuzX2A3a5YcOLCkX+2UyMEgvsNzX5DwDWeKiYIMm66d5R%7C%7CkKiMQB5aHgnjH+LmMpRG1%7C%7CA23O6tqHoOAAuizgd2ge8VGoXo0fNk4G2WTsvDgntakgpIajOctq0Ppl4qLWFGQEDWpp9005xJG7liKaazL43hdQxjLXkOfmI6dgo5H9eNKtau24nAThT5D%7C%7CNf1PXnhSV7GDFVDUfaXmOOlgt61KCuhegEql+yeRQLnGxCxdIwNYuT+CIsNmcunN5vyiwiLcii+ChQs%7C%7CqP39dLYBngh%7C%7Cppyuz1Y9RnLFOttGP2mEgAl7EIY=.jpeg"

# Initialize components for image analysis
schema_parser = JSONSchemaParser(json_schema)
prompt_generator = PromptGenerator(mode='image')
content_generator = ContentGenerator(api_key=api_key, mode='image', instructions=instructions, temperature=0)

json_processor = JSONProcessor(
    schema_parser=schema_parser,
    prompt_generator=prompt_generator,
    content_generator=content_generator,
    mode='image'
)

result = json_processor.process(instructions=instructions, schema=json_schema, image_url=image_url)
print("Generated JSON (Image Analysis):", json.dumps(result, indent=4))

```

**Output**
```
Generated JSON (Image Analysis): {
    "logos_in_image": [
        "Adidas"
    ],
    "scene": [
        "indoor",
        "cafe",
        "relaxing area"
    ],
    "demographics": {
        "age_group": [
            "20 to 24 years"
        ],
        "races": [
            "Other"
        ],
        "gender": [
            "Female"
        ]
    },
    "objects": [
        "green smoothie",
        "couch",
        "plants",
        "sunglasses"
    ],
    "activity": [
        "sitting",
        "drinking"
    ]
}
```
### Customization
**jsonpaws** allows users to customize the OpenAI model and temperature settings:

* **Model**: Specify the model to use (e.g., gpt-4o, gpt-4o-mini).
* **Temperature**: Control the randomness of the output. A higher temperature results in more random output.
**Example**
```
# Customize the content generator
content_generator_custom = ContentGenerator(
    api_key=api_key,
    model='gpt-4o',
    mode='synthesis',
    temperature=0.8  # Higher temperature for more randomness
)

# Use the custom content generator in your processor
synthesis_processor_custom = JSONProcessor(schema_parser, prompt_generator_synthesis, content_generator_custom, mode='synthesis')

# Generate the synthetic JSON data
generated_json_custom = synthesis_processor_custom.process(data={}, schema=json_schema)
print("Generated JSON (Custom):", json.dumps(generated_json_custom, indent=4))
```

## Contributing
Contributions are welcome! Please submit a pull request or open an issue to discuss potential improvements or features.

## License
This project is licensed under the MIT License.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/caspianmoon/jsonpaws",
    "name": "json-paws",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": null,
    "author": "Khazar Ayaz",
    "author_email": "khazar.ayaz@personnoai.com",
    "download_url": "https://files.pythonhosted.org/packages/9b/99/d719257164bd0a460cbae73d7f9b9aa6b91a6a908790d830ff7116644499/json_paws-0.1.9.tar.gz",
    "platform": null,
    "description": "# jsonpaws\n\n**jsonpaws** is an open-source Python library for generating structured and consistent JSON outputs using GPT-4o. It provides modes for **analysis**, **synthesis**, and **image analysis** to extract and generate structured JSON data from unstructured text or based on a given schema.\n\n## Features\n* Analysis Mode: Extract structured information from unstructured text. Perfect for data extraction and transformation tasks.\n* Synthesis Mode: Generate realistic structured JSON data from a specified schema, ideal for creating synthetic datasets for simulations or testing.\n* Image Analysis Mode: Analyze images to extract structured data and generate JSON outputs, making it suitable for computer vision applications.\n* Customizable: Allows users to configure the OpenAI model and temperature settings for tailored data generation.\n* Easy Integration: Seamlessly integrates into existing Python projects with a straightforward API and minimal setup.\n\n## Installation\n\nInstall jsonpaws using pip:\n```\npip install json_paws\n```\n\n## Getting Started\n### Setting the API Key\n\nTo use jsonpaws, you'll need an OpenAI API key. You can set it as an environment variable or pass it directly to the library.\n\n**Environment Variable**\n```\nexport OPENAI_API_KEY=your_api_key\n```\n\n**Directly in Your Code**\n\n```\nimport openai\n\nopenai.api_key = \"your_api_key\"\n```\n\n### Importing jsonpaws\nBegin by importing the necessary components from the library:\n\n```\nfrom jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor\n```\n\n## Usage\n### Analysis Mode\nIn **Analysis Mode**, jsonpaws extracts structured data from unstructured text using a predefined JSON schema.\n\n**Example**\n```\nimport json\nfrom jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor\n\n# Set your OpenAI API key here\napi_key = \"OPENAI-API-KEY\"\n\n# Define the JSON schema\njson_schema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"report_date\": {\"type\": \"string\"},\n        \"patients\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"id\": {\"type\": \"string\"},\n                    \"firstName\": {\"type\": \"string\"},\n                    \"lastName\": {\"type\": \"string\"},\n                    \"age\": {\"type\": \"number\", \"minimum\": 0, \"maximum\": 120},\n                    \"gender\": {\"type\": \"string\", \"enum\": [\"male\", \"female\"]},\n                    \"diagnosis\": {\"type\": \"string\"},\n                    \"medications\": {\n                        \"type\": \"array\",\n                        \"items\": {\"type\": \"string\"}\n                    }\n                }\n            }\n        }\n    }\n}\n\n# Initialize the schema parser\nschema_parser = JSONSchemaParser(json_schema)\n\n# For analysis mode\ninstructions = \"\"\"\nExtract patient information from the text and populate the JSON schema accordingly.\nThe report dated August 4, 2024, details the patient records for the day.\nAmong the patients, there is John Doe, a 45-year-old male diagnosed with hypertension, who is currently prescribed lisinopril and atorvastatin.\nAnother patient, Jane Smith, a 30-year-old female, has been diagnosed with diabetes and is on metformin.\nThe list also includes Sam Brown, a 60-year-old male suffering from arthritis, for which he is taking ibuprofen and methotrexate.\n\"\"\"\nprompt_generator_analysis = PromptGenerator(mode='analysis')\ncontent_generator_analysis = ContentGenerator(api_key=api_key, model='gpt-4o', mode='analysis', instructions=instructions)\nanalysis_processor = JSONProcessor(schema_parser, prompt_generator_analysis, content_generator_analysis, mode='analysis')\n\n# Process the data\ngenerated_json_analysis = analysis_processor.process(instructions=instructions, schema=json_schema)\n\n# Print the extracted structured JSON\nprint(\"Generated JSON (Analysis):\", json.dumps(generated_json_analysis, indent=4))\n```\n\n**Output**\n```\nGenerated JSON (Analysis): {\n    \"report_date\": \"August 4, 2024\",\n    \"patients\": [\n        {\n            \"id\": \"1\",\n            \"firstName\": \"John\",\n            \"lastName\": \"Doe\",\n            \"age\": 45,\n            \"gender\": \"male\",\n            \"diagnosis\": \"hypertension\",\n            \"medications\": [\n                \"lisinopril\",\n                \"atorvastatin\"\n            ]\n        },\n        {\n            \"id\": \"2\",\n            \"firstName\": \"Jane\",\n            \"lastName\": \"Smith\",\n            \"age\": 30,\n            \"gender\": \"female\",\n            \"diagnosis\": \"diabetes\",\n            \"medications\": [\n                \"metformin\"\n            ]\n        },\n        {\n            \"id\": \"3\",\n            \"firstName\": \"Sam\",\n            \"lastName\": \"Brown\",\n            \"age\": 60,\n            \"gender\": \"male\",\n            \"diagnosis\": \"arthritis\",\n            \"medications\": [\n                \"ibuprofen\",\n                \"methotrexate\"\n            ]\n        }\n    ]\n}\n```\n\n### Synthesis Mode\nIn **Synthesis Mode**, jsonpaws generates realistic structured JSON data from a specified schema.\n\n**Example**\n```\nimport json\nfrom jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor\n\n# Set your OpenAI API key here\napi_key = \"OPENAI-API-KEY\"\n\n# Define the JSON schema\njson_schema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"report_date\": {\"type\": \"string\"},\n        \"patients\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"object\",\n                \"properties\": {\n                    \"id\": {\"type\": \"string\"},\n                    \"firstName\": {\"type\": \"string\"},\n                    \"lastName\": {\"type\": \"string\"},\n                    \"age\": {\"type\": \"number\", \"minimum\": 0, \"maximum\": 120},\n                    \"gender\": {\"type\": \"string\", \"enum\": [\"male\", \"female\"]},\n                    \"diagnosis\": {\"type\": \"string\"},\n                    \"medications\": {\n                        \"type\": \"array\",\n                        \"items\": {\"type\": \"string\"}\n                    }\n                }\n            }\n        }\n    }\n}\n\n# Initialize the schema parser\nschema_parser = JSONSchemaParser(json_schema)\n\n# Instructions for synthesis mode\ninstructions = \"\"\"\nGenerate a JSON with a report date and a list of patients, where each patient has fields like id, firstName, lastName, age, gender, diagnosis, and medications.\n\"\"\"\n\n# For synthesis mode\nprompt_generator_synthesis = PromptGenerator(mode='synthesis')\ncontent_generator_synthesis = ContentGenerator(api_key=api_key, model='gpt-4o', mode='synthesis', instructions=instructions)\nsynthesis_processor = JSONProcessor(schema_parser, prompt_generator_synthesis, content_generator_synthesis, mode='synthesis')\n\n# Generate the synthetic JSON data\ngenerated_json_synthesis = synthesis_processor.process(instructions=instructions, schema=json_schema)\n\n# Print the generated synthetic JSON\nprint(\"Generated JSON (Synthesis):\", json.dumps(generated_json_synthesis, indent=4))\n\n```\n**Output**\n\n```\nGenerated JSON (Synthesis): {\n    \"report_date\": {\n        \"report_date\": \"2023-10-18\",\n        \"patients\": [\n            {\n                \"id\": \"P001\",\n                \"firstName\": \"John\",\n                \"lastName\": \"Doe\",\n                \"age\": 45,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Hypertension\",\n                \"medications\": [\n                    \"Lisinopril\",\n                    \"Amlodipine\"\n                ]\n            },\n            {\n                \"id\": \"P002\",\n                \"firstName\": \"Jane\",\n                \"lastName\": \"Smith\",\n                \"age\": 30,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Diabetes Type 2\",\n                \"medications\": [\n                    \"Metformin\",\n                    \"Glyburide\"\n                ]\n            },\n            {\n                \"id\": \"P003\",\n                \"firstName\": \"Emily\",\n                \"lastName\": \"Johnson\",\n                \"age\": 60,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Osteoarthritis\",\n                \"medications\": [\n                    \"Ibuprofen\",\n                    \"Glucosamine\"\n                ]\n            },\n            {\n                \"id\": \"P004\",\n                \"firstName\": \"Michael\",\n                \"lastName\": \"Brown\",\n                \"age\": 72,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Congestive Heart Failure\",\n                \"medications\": [\n                    \"Furosemide\",\n                    \"Digoxin\"\n                ]\n            }\n        ]\n    },\n    \"patients\": {\n        \"report_date\": \"2023-10-15\",\n        \"patients\": [\n            {\n                \"id\": \"P001\",\n                \"firstName\": \"John\",\n                \"lastName\": \"Doe\",\n                \"age\": 45,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Hypertension\",\n                \"medications\": [\n                    \"Lisinopril\",\n                    \"Amlodipine\"\n                ]\n            },\n            {\n                \"id\": \"P002\",\n                \"firstName\": \"Jane\",\n                \"lastName\": \"Smith\",\n                \"age\": 34,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Type 2 Diabetes\",\n                \"medications\": [\n                    \"Metformin\",\n                    \"Glipizide\"\n                ]\n            },\n            {\n                \"id\": \"P003\",\n                \"firstName\": \"Emily\",\n                \"lastName\": \"Johnson\",\n                \"age\": 28,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Anxiety Disorder\",\n                \"medications\": [\n                    \"Sertraline\"\n                ]\n            },\n            {\n                \"id\": \"P004\",\n                \"firstName\": \"Michael\",\n                \"lastName\": \"Williams\",\n                \"age\": 62,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Chronic Obstructive Pulmonary Disease\",\n                \"medications\": [\n                    \"Tiotropium\",\n                    \"Albuterol\"\n                ]\n            },\n            {\n                \"id\": \"P005\",\n                \"firstName\": \"David\",\n                \"lastName\": \"Brown\",\n                \"age\": 50,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Hyperlipidemia\",\n                \"medications\": [\n                    \"Atorvastatin\"\n                ]\n            },\n            {\n                \"id\": \"P006\",\n                \"firstName\": \"Sophia\",\n                \"lastName\": \"Davis\",\n                \"age\": 40,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Asthma\",\n                \"medications\": [\n                    \"Fluticasone\",\n                    \"Salbutamol\"\n                ]\n            },\n            {\n                \"id\": \"P007\",\n                \"firstName\": \"Daniel\",\n                \"lastName\": \"Miller\",\n                \"age\": 75,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Heart Failure\",\n                \"medications\": [\n                    \"Furosemide\",\n                    \"Carvedilol\"\n                ]\n            },\n            {\n                \"id\": \"P008\",\n                \"firstName\": \"Olivia\",\n                \"lastName\": \"Garcia\",\n                \"age\": 22,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Major Depressive Disorder\",\n                \"medications\": [\n                    \"Citalopram\"\n                ]\n            },\n            {\n                \"id\": \"P009\",\n                \"firstName\": \"James\",\n                \"lastName\": \"Martinez\",\n                \"age\": 30,\n                \"gender\": \"male\",\n                \"diagnosis\": \"Bipolar Disorder\",\n                \"medications\": [\n                    \"Lithium\",\n                    \"Lamotrigine\"\n                ]\n            },\n            {\n                \"id\": \"P010\",\n                \"firstName\": \"Ava\",\n                \"lastName\": \"Hernandez\",\n                \"age\": 55,\n                \"gender\": \"female\",\n                \"diagnosis\": \"Osteoarthritis\",\n                \"medications\": [\n                    \"Ibuprofen\",\n                    \"Glucosamine\"\n                ]\n            }\n        ]\n    }\n}          \n```\n### Image Analysis Mode\n\nIn **Image Analysis Mode**, jsonpaws analyzes images to extract structured JSON data.\n\n**Example**\n```\nimport json\nfrom jsonpaws import JSONSchemaParser, PromptGenerator, ContentGenerator, JSONProcessor\n\n\n# Set your OpenAI API key here\napi_key = 'OPENAI-API-KEY'\n\n# Define the JSON schema\njson_schema = {\n    \"type\": \"object\",\n    \"properties\": {\n        \"logos_in_image\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"string\"\n            }\n        },\n        \"scene\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"string\"\n            }\n        },\n        \"demographics\": {\n            \"type\": \"object\",\n            \"properties\": {\n                \"age_group\": {\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"type\": \"string\",\n                        \"enum\": [\n                            \"Under 5 years\", \"5 to 9 years\", \"10 to 14 years\",\n                            \"15 to 19 years\", \"20 to 24 years\", \"25 to 29 years\",\n                            \"30 to 34 years\", \"35 to 39 years\", \"40 to 44 years\",\n                            \"45 to 49 years\", \"50 to 54 years\", \"55 to 59 years\",\n                            \"60 to 64 years\", \"65 to 69 years\", \"70 to 74 years\",\n                            \"75 to 79 years\", \"80 to 84 years\", \"85 years and over\"\n                        ]\n                    }\n                },\n                \"races\": {\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"type\": \"string\",\n                        \"enum\": [\n                            \"White\", \"African American\", \"American Indian\", \"Asian\", \"Other\"\n                        ]\n                    }\n                },\n                \"gender\": {\n                    \"type\": \"array\",\n                    \"items\": {\n                        \"type\": \"string\",\n                        \"enum\": [\"Male\", \"Female\", \"Non-binary\", \"Other\"]\n                    }\n                }\n            }\n        },\n        \"objects\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"string\"\n            }\n        },\n        \"activity\": {\n            \"type\": \"array\",\n            \"items\": {\n                \"type\": \"string\"\n            }\n        }\n    }\n}\n\n\n# Instructions for image analysis\ninstructions = '''\nAnalyze the following image and provide the results in JSON\n'''\nimage_url = \"https://cdn1.picuki.com/hosted-by-instagram/q/0exhNuNYnjBGZDHIdN5WmL9I2PwkAQ9OKftSQ7e71yJjMBhsLH6QvJA0mpCl6yRxIwVgFDeSYztj4oouUFlQAz17NEfWT7yKRTxV7q2RVean0Fph9JBikLc0LnIbZ3ap8MQvU2bABCxWFOkXULjh7uZDu7%7C%7CzNnZSyWaRMdsCmWYK4dv1CPol9YIosuzX2A3a5YcOLCkX+2UyMEgvsNzX5DwDWeKiYIMm66d5R%7C%7CkKiMQB5aHgnjH+LmMpRG1%7C%7CA23O6tqHoOAAuizgd2ge8VGoXo0fNk4G2WTsvDgntakgpIajOctq0Ppl4qLWFGQEDWpp9005xJG7liKaazL43hdQxjLXkOfmI6dgo5H9eNKtau24nAThT5D%7C%7CNf1PXnhSV7GDFVDUfaXmOOlgt61KCuhegEql+yeRQLnGxCxdIwNYuT+CIsNmcunN5vyiwiLcii+ChQs%7C%7CqP39dLYBngh%7C%7Cppyuz1Y9RnLFOttGP2mEgAl7EIY=.jpeg\"\n\n# Initialize components for image analysis\nschema_parser = JSONSchemaParser(json_schema)\nprompt_generator = PromptGenerator(mode='image')\ncontent_generator = ContentGenerator(api_key=api_key, mode='image', instructions=instructions, temperature=0)\n\njson_processor = JSONProcessor(\n    schema_parser=schema_parser,\n    prompt_generator=prompt_generator,\n    content_generator=content_generator,\n    mode='image'\n)\n\nresult = json_processor.process(instructions=instructions, schema=json_schema, image_url=image_url)\nprint(\"Generated JSON (Image Analysis):\", json.dumps(result, indent=4))\n\n```\n\n**Output**\n```\nGenerated JSON (Image Analysis): {\n    \"logos_in_image\": [\n        \"Adidas\"\n    ],\n    \"scene\": [\n        \"indoor\",\n        \"cafe\",\n        \"relaxing area\"\n    ],\n    \"demographics\": {\n        \"age_group\": [\n            \"20 to 24 years\"\n        ],\n        \"races\": [\n            \"Other\"\n        ],\n        \"gender\": [\n            \"Female\"\n        ]\n    },\n    \"objects\": [\n        \"green smoothie\",\n        \"couch\",\n        \"plants\",\n        \"sunglasses\"\n    ],\n    \"activity\": [\n        \"sitting\",\n        \"drinking\"\n    ]\n}\n```\n### Customization\n**jsonpaws** allows users to customize the OpenAI model and temperature settings:\n\n* **Model**: Specify the model to use (e.g., gpt-4o, gpt-4o-mini).\n* **Temperature**: Control the randomness of the output. A higher temperature results in more random output.\n**Example**\n```\n# Customize the content generator\ncontent_generator_custom = ContentGenerator(\n    api_key=api_key,\n    model='gpt-4o',\n    mode='synthesis',\n    temperature=0.8  # Higher temperature for more randomness\n)\n\n# Use the custom content generator in your processor\nsynthesis_processor_custom = JSONProcessor(schema_parser, prompt_generator_synthesis, content_generator_custom, mode='synthesis')\n\n# Generate the synthetic JSON data\ngenerated_json_custom = synthesis_processor_custom.process(data={}, schema=json_schema)\nprint(\"Generated JSON (Custom):\", json.dumps(generated_json_custom, indent=4))\n```\n\n## Contributing\nContributions are welcome! Please submit a pull request or open an issue to discuss potential improvements or features.\n\n## License\nThis project is licensed under the MIT License.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for generating structured JSON using GPT-4o.",
    "version": "0.1.9",
    "project_urls": {
        "Homepage": "https://github.com/caspianmoon/jsonpaws"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8aec46994dcd1cd528df5bfa3b3b35e037a7975ee3c87c10e6f74fe18ac3e8e0",
                "md5": "97a317be281cda9a2a7dde78fa261048",
                "sha256": "df035c05ec666435c58a110a9afb575ec4f6d24eec0f0c9df4777724a0b5a23e"
            },
            "downloads": -1,
            "filename": "json_paws-0.1.9-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "97a317be281cda9a2a7dde78fa261048",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 12032,
            "upload_time": "2024-08-04T23:32:02",
            "upload_time_iso_8601": "2024-08-04T23:32:02.716291Z",
            "url": "https://files.pythonhosted.org/packages/8a/ec/46994dcd1cd528df5bfa3b3b35e037a7975ee3c87c10e6f74fe18ac3e8e0/json_paws-0.1.9-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b99d719257164bd0a460cbae73d7f9b9aa6b91a6a908790d830ff7116644499",
                "md5": "cfc5701e42b476a24416285d30bf55c7",
                "sha256": "b11a7610fa6de209e943ea67f4bd9ed37930f44b6ff180227c646a13dcbf8100"
            },
            "downloads": -1,
            "filename": "json_paws-0.1.9.tar.gz",
            "has_sig": false,
            "md5_digest": "cfc5701e42b476a24416285d30bf55c7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 10913,
            "upload_time": "2024-08-04T23:32:04",
            "upload_time_iso_8601": "2024-08-04T23:32:04.070009Z",
            "url": "https://files.pythonhosted.org/packages/9b/99/d719257164bd0a460cbae73d7f9b9aa6b91a6a908790d830ff7116644499/json_paws-0.1.9.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-04 23:32:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "caspianmoon",
    "github_project": "jsonpaws",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "json-paws"
}
        
Elapsed time: 0.66933s