Skip to main content

midi-structure

PyPI version License: MIT Downloads LinkedIn

midi-structure is a lightweight Python package that provides a simple, structured interface for processing MIDI‑related text queries. It leverages llmatch‑messages to enforce that LLM responses conform to a predefined regex pattern, ensuring consistent and machine‑readable output.

Note: The package ships with a default LLM implementation (ChatLLM7 from langchain_llm7). You can also supply any LangChain‑compatible LLM (e.g., OpenAI, Anthropic, Google Generative AI) if you prefer.


🚀 Overview

  • Structured MIDI queries – ask about instruments, file formats, protocol details, etc.
  • Pattern‑based validation – responses are checked against a regex (pattern) defined in prompts.py.
  • Pluggable LLM – use the built‑in ChatLLM7 or attach your own LangChain LLM.
  • Zero configuration – just pass a string and get a list of extracted data.

📦 Installation

pip install midi-structure

🛠️ Quick Start

from midi-structure import midi-structure

# Simple call using the default ChatLLM7 (reads API key from LLM7_API_KEY env var)
response = midi-structure(
    user_input="What are the most common MIDI message types?"
)

print(response)   # → a list of strings that match the defined pattern

Parameters

Name Type Description
user_input str The natural‑language query related to MIDI.
llm Optional[BaseChatModel] A LangChain LLM instance. If omitted, ChatLLM7 is used.
api_key Optional[str] API key for LLM7. If not supplied, the function looks for the LLM7_API_KEY environment variable.

🔄 Using a Custom LLM

You can pass any LangChain‑compatible chat model. Below are a few examples.

OpenAI

from langchain_openai import ChatOpenAI
from midi-structure import midi-structure

llm = ChatOpenAI()
response = midi-structure("Explain the MIDI file header format.", llm=llm)
print(response)

Anthropic

from langchain_anthropic import ChatAnthropic
from midi-structure import midi-structure

llm = ChatAnthropic()
response = midi-structure("List the standard General MIDI instruments.", llm=llm)
print(response)

Google Generative AI

from langchain_google_genai import ChatGoogleGenerativeAI
from midi-structure import midi-structure

llm = ChatGoogleGenerativeAI()
response = midi-structure("How does MIDI time stamping work?", llm=llm)
print(response)

🔑 API Keys & Rate Limits

  • LLM7 (default) offers a free tier that is sufficient for most typical usage.
  • To obtain a free LLM7 API key, register at: https://token.llm7.io/
  • You can provide the key in two ways:
    1. Set the environment variable LLM7_API_KEY.
    2. Pass it directly:
      response = midi-structure("...", api_key="your_api_key")
      

If you need higher rate limits, upgrade your LLM7 plan or switch to another LLM as shown above.


🧩 Project Structure

midi_structure/
│
├─ __init__.py               # Exposes midi-structure function
├─ core.py                   # Implementation (the function shown above)
├─ prompts.py                # Holds system/human prompts and regex pattern
└─ ...                       # Additional helper modules

The core function performs the following steps:

  1. Resolve the LLM (default = ChatLLM7).
  2. Build system and human messages from the supplied prompts.
  3. Compile the regex pattern.
  4. Call llmatch to get a response that matches the pattern.
  5. Return the extracted data as a list of strings.

🤝 Contributing

We welcome contributions! If you find a bug or have a feature request, please open an issue on GitHub:

Pull requests are encouraged. Please make sure tests pass and follow the existing code style.


📄 License

This project is licensed under the MIT License.


👤 Author

Eugene Evstafev


Happy coding with MIDI!

Metadata

Release files for midi-structure 2025.12.20185411

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for midi-structure 2025.12.20185411
File Size Uploaded
midi_structure-2025.12.20185411.tar.gz 5.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for midi-structure 2025.12.20185411
File Interpreter ABI Platform
midi_structure-2025.12.20185411-py3-none-any.whl Python 3 none any Details

Total release size: 10.7 kB

Release files / midi_structure-2025.12.20185411.tar.gz

Download URL midi_structure-2025.12.20185411.tar.gz
Size 5.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ac44c825da927f8e94a5e356ad4cbf81014cf2a17086a842478526506779b7ab
BLAKE2b-256 checksum
How to use checksums
0fec14697e48e2fd514ed4ec92fcf945b2014b6c320d9cddcab957de0b3bdc64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / midi_structure-2025.12.20185411-py3-none-any.whl

Download URL midi_structure-2025.12.20185411-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d79c8e3e1205ed69add8ff363b36a1f50904a82f3eb464729d3fc84f7a31570
BLAKE2b-256 checksum
How to use checksums
d6c9bb75c4ec2a83bb00cb42e1ddc6f585b5be5b5349b0c84cd2af3ce33fb6cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

2025.12.20185411 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page