Skip to main content

Utilities for managing multi-shot conversations and structured data handling in LLM applications

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

mdi-llmkit

Utilities for managing LLM chat conversations and structured JSON responses with OpenAI's Responses API.

Installation

pip install mdi-llmkit

Quick Start

Preferred subpackage imports:

from mdi_llmkit.gpt_api import GptConversation
from mdi_llmkit.json_surgery import json_surgery

gpt_submit

from openai import OpenAI
from mdi_llmkit.gpt_api import gpt_submit

client = OpenAI()

reply = gpt_submit(
    messages=[{"role": "user", "content": "Say hello."}],
    openai_client=client,
)
print(reply)

GptConversation

from openai import OpenAI
from mdi_llmkit.gpt_api import GptConversation

client = OpenAI()
conversation = GptConversation(openai_client=client)

reply = conversation.submit_user_message("Give me three project name ideas.")
print(reply)

JSON Response Mode

from openai import OpenAI
from mdi_llmkit.gpt_api import gpt_submit

client = OpenAI()

result = gpt_submit(
    messages=[{"role": "user", "content": "Return JSON with keys a and b."}],
    openai_client=client,
    json_response=True,
)

print(type(result))  # dict or list
print(result)

JSON Surgery

from openai import OpenAI
from mdi_llmkit.json_surgery import json_surgery

client = OpenAI()

obj = {"status": "pending", "tags": ["alpha"]}
result = json_surgery(
    client,
    obj,
    'Set status to "approved" and append "done" to tags.',
)

print(result)

Placemark helpers are available in mdi_llmkit.json_surgery.placemarked_json:

  • placemarked_json_stringify(obj, indent=2, skipped_keys=None)
  • navigate_to_json_path(obj, json_path)

Semantic List Comparison (compare_item_lists)

Use compare_item_lists when you need to compare a before list and an after list and classify items as removed, added, renamed, or unchanged. This uses AI to resolve semantic renames that would otherwise appear as unrelated remove/add pairs in strict string comparison.

from openai import OpenAI
from mdi_llmkit.semanticMatch import compare_item_lists

client = OpenAI()

result = compare_item_lists(
    client,
    ["Legacy Plan", "Shared Item"],
    ["Modern Plan", "shared item"],
    (
        "Legacy Plan was renamed to Modern Plan. "
        "Shared Item is unchanged."
    ),
)

print(result)
# {
#   "removed": [],
#   "added": [],
#   "renamed": {"Legacy Plan": "Modern Plan"},
#   "unchanged": ["Shared Item"],
# }

Accepted input item formats:

  • String item name: "Item Name"
  • Object with optional context: {"name": "Item Name", "description": "..."}

Notes:

  • Name matching is case-insensitive for exact unchanged detection.
  • Names should be unique within each input list (case-insensitive).
  • Optional description is context-only and does not define identity.

Local Dev (Windows venv)

From packages/python-mdi-llmkit, activate the project venv and run tests:

.\venv\Scripts\Activate.ps1
python -c "import sys; print(sys.executable)"
python -m unittest tests/test_placemarked_json.py tests/test_json_surgery_unit.py

Live json_surgery integration tests (real API) require OPENAI_API_KEY:

python -m unittest tests/test_json_surgery.py

Notes

  • Package name for pip install is mdi-llmkit.
  • Python import package is mdi_llmkit.
  • gpt_submit supports optional warning reporting via warning_callback.

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

mdi_llmkit-1.1.1.tar.gz (42.5 kB view details)

Uploaded Source

Built Distribution

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

mdi_llmkit-1.1.1-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file mdi_llmkit-1.1.1.tar.gz.

File metadata

  • Download URL: mdi_llmkit-1.1.1.tar.gz
  • Upload date:
  • Size: 42.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for mdi_llmkit-1.1.1.tar.gz
Algorithm Hash digest
SHA256 896220ab6d760532d71003918cfe4cfff6b9cd3dc1c185e13b8defea0ffed574
MD5 aea1a80e6bc9aebe477f173e38d4af9f
BLAKE2b-256 930e724c6f1285a564e4c915f144eac4133b7eee4d8b76edbba2c61a778b9415

See more details on using hashes here.

File details

Details for the file mdi_llmkit-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: mdi_llmkit-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for mdi_llmkit-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb9f2aa1f0d7ab402de2881ccc66e77187f8fa224303e2ca4ee974c76219858
MD5 5f8dd76c6e1958c400bb1dd54309ba7a
BLAKE2b-256 ec7689728fdf004b08729d6b5ce2dd1f667104a34c869d7375c1f2e1300cf455

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