Skip to content
 
 

Repository files navigation

n a m e n o t f o u n d . a i

T H E
F U T U R E
O F
A I
I S
O N - D E V I C E

ImpproveLLMStructure — An intelligent correct system for LLM's


ImproveLLMStructure

Identifies the incoming prompt and the LLM response than aligns and converts, improves system stability and allows for working with less capable models. For instance if you send a prompt request in python or json or plaintext it will try to reason the expected format and convert the LLM responses to whatever you want to recieve back.

Improved LLM Structure

A powerful open-source framework for building agentic AI systems that enables seamless communication between specialized language models through format transformation.

Overview

Improved LLM Structure is a crucial component in building agentic AI systems, particularly when working with multiple specialized language models. It solves a fundamental challenge in AI infrastructure: enabling different models to communicate effectively by transforming their outputs into various formats.

Overview:

https://www.loom.com/share/f19ac59a21ad4fd4b422552e958b3385?sid=1e26e48d-2643-4003-9288-1e65eb02de0f

Key Features

  • Format Transformation: Convert between different data formats (JSON, Markdown, Python, plain text)
  • Local Model Integration: Works with quantized 8-bit models for efficient local processing
  • Error Correction: Built-in validation and error correction system
  • Learning System: Improves over time through interaction data
  • Flexible API: RESTful interface for easy integration
  • Multi-Format Support: Handle various input and output formats seamlessly

Why Use Improved LLM Structure?

When building agentic AI systems with multiple specialized models, each model might excel at different tasks and output formats. This tool acts as a "universal translator" between these models, allowing them to communicate effectively without:

  • Consuming large context windows with format-specific tokens
  • Compromising model performance by forcing specific output formats
  • Requiring larger, more resource-intensive models for format transformation

Prerequisites

  • Python 3.10 or newer
  • Conda environment (recommended)
  • Hugging Face model (8-bit quantized model recommended)
  • Basic understanding of API communication

Complete Setup Tutorial

https://www.loom.com/share/51b53e0a7200458a97923b21a0cc2d69?sid=df63c202-f36f-4db4-a800-635027cf25a2

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/improved-llm-structure.git
cd improved-llm-structure
  1. Set up the Conda environment (recommended to use the same environment as the A-agent project):
git clone https://github.com/namenotfound-ai/a_agent

Follow the setup requirements here:

https://www.loom.com/share/f19ac59a21ad4fd4b422552e958b3385?sid=1e26e48d-2643-4003-9288-1e65eb02de0f

  1. Install git-lfs (required for downloading the model):
# For macOS using Homebrew
brew install git-lfs

# Initialize git-lfs
git lfs install
  1. Download the phi-4-8bit model:
# Create a local_models directory
mkdir local_models
cd local_models

# Clone the model repository
# Note: This will download approximately 15GB of model files and may take several minutes
git clone https://huggingface.co/mlx-community/phi-4-8bit --progress

# If you want to clone without large files - just their pointers
# GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/mlx-community/phi-4-8bit
  1. Install the required Python packages:
pip install mlx-lm
  1. Copy the local_model.py file to the model directory:
# From the project root directory
cp local_model.py local_models/phi-4-8bit/
  1. Download a Hugging Face model (8-bit quantized model recommended) and place it in the project directory.

Usage

  1. Start the local model server:
# Navigate to the model directory
cd local_models/phi-4-8bit

# Start the server
python local_model.py

This will start the server on port 5015 by default.

  1. Start the main application:
python app.py

This will start the server on port 5025 by default.

  1. Make requests to the API using curl or any HTTP client:
curl -X POST http://localhost:5015/ask \
  -H "Content-Type: application/json" \
  -d '{
    "question": "Your input text here",
    "requested_format": "json"
  }'

Example:

curl -X POST \
  http://localhost:5015/ask \
  -H "Content-Type: application/json" \
  -d '{
    "question": "Convert this text to json: Name: John Smith, Age: 35, Occupation: Software Engineer, Skills: Python, JavaScript, SQL",
    "output_format": "json"
  }'

Configuration

You can modify the following settings in config.py:

  • Local model endpoint
  • Port numbers
  • Default output format
  • Other configuration parameters

Architecture

The system consists of several key components:

  • app.py: Main application server
  • local_model.py: Local MLX model interface
  • prompt_handler.py: Request and prompt processing
  • llm_manager.py: LLM communication
  • output_parser.py: Output processing
  • format_transformer.py: Format transformation
  • validator.py: Output validation
  • error_corrector.py: Error handling
  • learner.py: Learning system

Contributing

We welcome contributions! Please feel free to submit pull requests, open issues, or suggest improvements.

License

This project is open source and available under the MIT License.

Next Steps

  1. Download and set up the project
  2. Configure your environment
  3. Start the required servers
  4. Begin making API requests
  5. Reach out with any questions or feedback

Contact

For questions, feedback, or collaboration opportunities, please reach out to us through GitHub issues or our contact channels.


Remember: The future of AI isn't about making one model do everything. It's about making specialized models work together seamlessly.

About

Identifies the incoming prompt and the LLM response than aligns and converts, improves system stability and allows for working with less capable models

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages