Installation
+Install GIMKit using pip:
+pip install gimkit
+ For vLLM support, install with the optional dependency:
+pip install gimkit[vllm]
+ Quick Start
+Here's a simple example using the OpenAI backend:
+from openai import OpenAI
+from gimkit import from_openai, guide as g
+
+# Initialize the client and model
+client = OpenAI() # Uses OPENAI_API_KEY environment variable
+model = from_openai(client, model_name="gpt-4")
+
+# Create a query with masked tags
+result = model(f"Hello, {g(desc='a single word')}!", use_gim_prompt=True)
+print(result) # Output: Hello, world!
+ Usage
+ +Creating Masked Tags
+Use the guide helper (imported as g) to create masked tags:
from gimkit import guide as g
+
+# Basic tag with description
+tag = g(name="greeting", desc="A friendly greeting")
+
+# Specialized tags
+name_tag = g.person_name(name="user_name")
+email_tag = g.e_mail(name="email")
+phone_tag = g.phone_number(name="phone")
+word_tag = g.single_word(name="word")
+
+# Selection from choices
+choice_tag = g.select(name="color", choices=["red", "green", "blue"])
+
+# Tag with regex constraint
+custom_tag = g(name="code", desc="A 4-digit code", regex=r"\d{4}")
+
+ Building Queries
+Combine masked tags with text to build queries:
+from gimkit import from_openai, guide as g
+from openai import OpenAI
+
+client = OpenAI()
+model = from_openai(client, model_name="gpt-4")
+
+query = f"""
+Name: {g.person_name(name="name")}
+Email: {g.e_mail(name="email")}
+Favorite color: {g.select(name="color", choices=["red", "green", "blue"])}
+"""
+
+result = model(query, use_gim_prompt=True)
+print(result)
+
+ Accessing Results
+Access filled tags from the result:
+result = model(query, use_gim_prompt=True)
+
+# Iterate over all tags
+for tag in result.tags:
+ print(f"{tag.name}: {tag.content}")
+
+# Access by name
+print(result.tags["name"].content)
+
+# Modify tag content
+result.tags["email"].content = "REDACTED"
+ API Reference
+ +guide — Tag Builder
+ A singleton instance of Guide for creating masked tags. Import it as g by convention.
| Method | +Description | +
|---|---|
g(name, desc, regex, content) |
+ Create a generic masked tag with optional attributes. | +
g.single_word(name) |
+ A single word without spaces (\S+). |
+
g.select(name, choices) |
+ Choose one value from the given list of options. | +
g.datetime(name, require_date, require_time) |
+ A date and/or time string (e.g., 2023-10-05 14:30:00). |
+
g.person_name(name) |
+ A person's name (e.g., John Doe, 张三). | +
g.phone_number(name) |
+ A phone number (e.g., +1-123-456-7890). | +
g.e_mail(name) |
+ An email address (e.g., alice@example.com). | +
from_openai — OpenAI Backend
+ from gimkit import from_openai
+from openai import OpenAI
+
+model = from_openai(client: OpenAI, model_name: str)
+ Returns a callable model that accepts a query string and returns a Result.
from_vllm / from_vllm_offline — vLLM Backends
+ from gimkit import from_vllm, from_vllm_offline
+ Adapters for vLLM server and offline inference. Requires pip install gimkit[vllm].
Design Philosophy
+-
+
- Stable over feature — reliability and correctness are prioritized above new features. +
- Small open-source model first — designed to work well with small, freely available language models. +