Skip to main content

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

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!

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

midi_structure-2025.12.20185411.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

midi_structure-2025.12.20185411-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file midi_structure-2025.12.20185411.tar.gz.

File metadata

File hashes

Hashes for midi_structure-2025.12.20185411.tar.gz
Algorithm Hash digest
SHA256 ac44c825da927f8e94a5e356ad4cbf81014cf2a17086a842478526506779b7ab
MD5 4352ddba6d0e6aee5e2ddfa6ad82e393
BLAKE2b-256 0fec14697e48e2fd514ed4ec92fcf945b2014b6c320d9cddcab957de0b3bdc64

See more details on using hashes here.

File details

Details for the file midi_structure-2025.12.20185411-py3-none-any.whl.

File metadata

File hashes

Hashes for midi_structure-2025.12.20185411-py3-none-any.whl
Algorithm Hash digest
SHA256 3d79c8e3e1205ed69add8ff363b36a1f50904a82f3eb464729d3fc84f7a31570
MD5 0e677109c2f156ca0dd3b6e079a6393a
BLAKE2b-256 d6c9bb75c4ec2a83bb00cb42e1ddc6f585b5be5b5349b0c84cd2af3ce33fb6cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page