A package for generating, validating, and utilizing Draft-7 JSON schemas with LangChain
Project description
Lang2Logic Python Package
Introduction
Lang2Logic: Generating python objects with natural language.
Overview
Lang2Logic is an innovative Python package designed for developers who need to translate natural language prompts into structured Python outputs. Utilizing advanced language processing algorithms, Lang2Logic simplifies generating Python code from verbal or written descriptions.
Key Features
- Natural Language to Python Conversion: Converts natural language instructions into Python code, facilitating easier programming and automation.
- Dynamic Schema Generation: Automatically generates schema from natural language inputs, providing structured outputs like lists, dictionaries, etc.
- Flexible API Integration: User-friendly API for seamless integration with existing Python projects.
Installation and Usage
import os
from Lang2Logic.generator import Generator
# Initialize with API key
self.test_gen = Generator(os.environ.get("YOUR_API_KEY"))
# Generate schema from natural language
schema = self.test_gen.generate_schema("return a list of strings")
# The 'schema' here is an instance of the ResponseSchema class
Using the ResponseSchema Class
The ResponseSchema
class is designed to handle and manipulate JSON schemas. It can accept a JSON string, a dictionary, or another instance of itself to create or modify a schema.
Creating an Instance
from Lang2Logic.response_schema import ResponseSchema
# Create a ResponseSchema instance from a dictionary
schema_dict = {"type": "object", "properties": {"name": {"type": "string"}}}
schema = ResponseSchema(schema_dict)
# Or from another ResponseSchema instance
another_schema = ResponseSchema(schema)
Getting Dictionary or JSON Representation
# Get the schema as a dictionary
schema_dict = schema.to_dict()
# Convert the schema to a JSON string
schema_json = schema.to_json()
Saving Schema to a File
# Save the schema to a JSON file
schema.save_to_json(key="mySchema", filepath="path/to/file.json")
Automatic Schema Generation
self.test_gen.generate("return a list of strings with 5 colors")
# The output is an instance of ResponseSchema
# Output: ["color1", "color2", "color3", "color4", "color5"]
Example Usage
Classifying Decisions and Preferences
schema = self.test_gen.generate_schema("return a dictionary with keys 'rational' and 'decision' (boolean)")
potential_buyers = []
for user in users_data_json["bios"]:
decision = self.test_gen.generate(f"return true if this user might be interested in products related to rock climbing.\nUser Bio:\n{user['bio']}", schema)
if decision["decision"]:
potential_buyers.append(user)
Roadmap
- Function Generation
- Optimized Logic for Increased Accuracy
- Code Parsing and LLM integration tools
- Python Agents
Bug Reporting and Contributions
Found a bug or have a suggestion? Please contact dylanpwilson2005@gmail.com.
License
Lang2Logic is available under a Creative Commons license and may not be used for commercial purposes without explicit consent from the author.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Lang2Logic-0.1.4.tar.gz
.
File metadata
- Download URL: Lang2Logic-0.1.4.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bc3130269dd9ddf482766943f56a973a80b1304d19744dab6a149a0d3ca6d2a |
|
MD5 | 70f8ff67210110411a4134365f646044 |
|
BLAKE2b-256 | 929477a9434117dfe03a7457d6564759d60e046fc8756f8d557f91fa9add12f1 |
File details
Details for the file Lang2Logic-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: Lang2Logic-0.1.4-py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8c936c100cb713cef4953f2522f72e3525ed1fb7a74dc82bf88c19e55ed8c264 |
|
MD5 | 5f80fd1d6ce38513a586aac6009b9086 |
|
BLAKE2b-256 | 9c75daea62f24310a8d36bc7258289926b6797f7a8a61b2868ccdc1ddd33b934 |