A new package designed to facilitate structured interactions with MIDI (Musical Instrument Digital Interface) data. This package leverages the capabilities of llmatch-messages to process text inputs r
Project description
midi-structure
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 (
ChatLLM7fromlangchain_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 inprompts.py. - Pluggable LLM – use the built‑in
ChatLLM7or 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:
- Set the environment variable
LLM7_API_KEY. - Pass it directly:
response = midi-structure("...", api_key="your_api_key")
- Set the environment variable
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:
- Resolve the LLM (default =
ChatLLM7). - Build system and human messages from the supplied prompts.
- Compile the regex pattern.
- Call
llmatchto get a response that matches the pattern. - 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
- Email: hi@euegne.plus
- GitHub: chigwell
- LinkedIn: Eugene Evstafev
Happy coding with MIDI!
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file midi_structure-2025.12.20185411.tar.gz.
File metadata
- Download URL: midi_structure-2025.12.20185411.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac44c825da927f8e94a5e356ad4cbf81014cf2a17086a842478526506779b7ab
|
|
| MD5 |
4352ddba6d0e6aee5e2ddfa6ad82e393
|
|
| BLAKE2b-256 |
0fec14697e48e2fd514ed4ec92fcf945b2014b6c320d9cddcab957de0b3bdc64
|
File details
Details for the file midi_structure-2025.12.20185411-py3-none-any.whl.
File metadata
- Download URL: midi_structure-2025.12.20185411-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d79c8e3e1205ed69add8ff363b36a1f50904a82f3eb464729d3fc84f7a31570
|
|
| MD5 |
0e677109c2f156ca0dd3b6e079a6393a
|
|
| BLAKE2b-256 |
d6c9bb75c4ec2a83bb00cb42e1ddc6f585b5be5b5349b0c84cd2af3ce33fb6cf
|