Image-Text-to-Text
MLX
Safetensors
qwen3_5
clairic
cloudflare
systemone
structured-output
information-extraction
multimodal
custom-code
conversational
4-bit precision
Instructions to use mlx-community/clairic-flash-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use mlx-community/clairic-flash-4bit with MLX:
# Make sure mlx-vlm is installed # pip install --upgrade mlx-vlm from mlx_vlm import load, generate from mlx_vlm.prompt_utils import apply_chat_template from mlx_vlm.utils import load_config # Load the model model, processor = load("mlx-community/clairic-flash-4bit") config = load_config("mlx-community/clairic-flash-4bit") # Prepare input image = ["http://images.cocodataset.org/val2017/000000039769.jpg"] prompt = "Describe this image." # Apply chat template formatted_prompt = apply_chat_template( processor, config, prompt, num_images=1 ) # Generate output output = generate(model, processor, formatted_prompt, image) print(output) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use mlx-community/clairic-flash-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "mlx-community/clairic-flash-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent
How to use mlx-community/clairic-flash-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default mlx-community/clairic-flash-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use mlx-community/clairic-flash-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "mlx-community/clairic-flash-4bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "mlx-community/clairic-flash-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Download clairic_runtime/source_dates.py from mlx-community/clairic-flash-4bit: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/mlx-community/clairic-flash-4bit/resolve/main/clairic_runtime/source_dates.py
- Command line
-
hf download hf://mlx-community/clairic-flash-4bit/clairic_runtime/source_dates.py
-
curl -L -o source_dates.py https://huggingface.co/mlx-community/clairic-flash-4bit/resolve/main/clairic_runtime/source_dates.py
11.9 kB
| from __future__ import annotations | |
| import json | |
| import re | |
| from collections.abc import Iterable | |
| from dataclasses import asdict, dataclass | |
| from datetime import date | |
| from typing import Any | |
| VERSION = "source-date-candidates-v1" | |
| INSTRUCTION = "Return the complete calendar date for this requested field as YYYY-MM-DD. Choose only a date explicitly printed for the requested role in the supplied source. Use the full day, month, and year, including legal ordinal date wording. Do not derive an unprinted date from a duration, term length, another date, or general knowledge. Return null if the requested role has no printed date. A date for another role does not fill this field." | |
| _MONTHS = { | |
| "jan": 1, | |
| "january": 1, | |
| "feb": 2, | |
| "february": 2, | |
| "mar": 3, | |
| "march": 3, | |
| "apr": 4, | |
| "april": 4, | |
| "may": 5, | |
| "jun": 6, | |
| "june": 6, | |
| "jul": 7, | |
| "july": 7, | |
| "aug": 8, | |
| "august": 8, | |
| "sep": 9, | |
| "sept": 9, | |
| "september": 9, | |
| "oct": 10, | |
| "october": 10, | |
| "nov": 11, | |
| "november": 11, | |
| "dec": 12, | |
| "december": 12, | |
| } | |
| _MONTH = "(?:" + "|".join(sorted(_MONTHS, key=len, reverse=True)) + ")\\.?" | |
| _DMY = re.compile( | |
| "(?<!\\w)(?:the\\s+)?(?P<day>\\d{1,2})(?P<ordinal>st|nd|rd|th)?\\s+(?:(?:day\\s+)?of\\s+)?(?P<month>" | |
| + _MONTH | |
| + "),?\\s+(?P<year>\\d{4})(?!\\w)", | |
| re.IGNORECASE, | |
| ) | |
| _MDY = re.compile( | |
| "(?<!\\w)(?P<month>" | |
| + _MONTH | |
| + ")\\s+(?:the\\s+)?(?P<day>\\d{1,2})(?P<ordinal>st|nd|rd|th)?,?\\s+(?P<year>\\d{4})(?!\\w)", | |
| re.IGNORECASE, | |
| ) | |
| _YMD = re.compile( | |
| "(?<![\\w./-])(?P<year>\\d{4})(?P<sep>[-/.])(?P<month>\\d{1,2})(?P=sep)(?P<day>\\d{1,2})(?!(?:[\\w/-]|\\.\\w))" | |
| ) | |
| _NUMERIC = re.compile( | |
| "(?<![\\w./-])(?P<first>\\d{1,2})(?P<sep>[-/.])(?P<second>\\d{1,2})(?P=sep)(?P<year>\\d{4})(?!(?:[\\w/-]|\\.\\w))" | |
| ) | |
| _DERIVED = re.compile( | |
| "\\b(?:calculat\\w*|comput\\w*|deriv\\w*|infer\\w*|after|before|ago|next|previous|following|prior|add|subtract|plus|minus|earlier|later|offset|duration|anniversar\\w*|turns?)\\b|\\b(?:first|last)\\s+day\\s+of\\b|\\bnet\\s*\\d+\\b", | |
| re.IGNORECASE, | |
| ) | |
| _RELATIVE = re.compile( | |
| "\\b(?:today|tomorrow|yesterday|now)\\b|\\bcurrent\\s+(?:calendar\\s+)?date\\b|\\bbusiness\\s+days?\\b|\\b(?:days?|weeks?|months?|years?)\\s+from\\b|\\b(?:this|last)\\s+(?:week|month|year)\\b|\\b(?:in|within)\\s+(?:\\d+|[a-z]+(?:[\\s-]+[a-z]+){0,2})\\s+(?:business\\s+)?(?:days?|weeks?|months?|years?)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _READING_INTENT = re.compile( | |
| "\\b(?:dates?|dated|calendar\\s+day|printed|explicit(?:ly)?|stated|shown|recorded|written|literal|verbatim)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _EXPRESSION_REQUEST = re.compile( | |
| "\\b(?:value\\s+(?:of|for)|evaluat\\w*|expression|formula|variable|constant|function|code)\\b", | |
| re.IGNORECASE, | |
| ) | |
| _CALENDAR_EXPRESSION = re.compile( | |
| "\\b(?:add|sub(?:tract)?|plus|minus|offset|shift|set)[_]?(?:business[_]?)?(?:days?|weeks?|months?|years?)\\s*\\(|\\b(?:date_?(?:add|sub|diff)|timedelta|relativedelta|DateOffset|EDATE|EOMONTH|WORKDAY)\\s*\\(|\\.\\s*(?:set(?:UTC)?(?:Date|Month|FullYear)|add|subtract)\\s*\\(|\\binterval\\s+(?:['\\\"]|\\d)|\\b(?:date|datetime)(?:\\s*\\.\\s*\\w+)?\\s*\\([^;\\n]*\\)\\s*[+-]", | |
| re.IGNORECASE, | |
| ) | |
| def eligible(spec: dict[str, Any]) -> bool: | |
| instructions = spec.get("instructions", "") | |
| return ( | |
| spec.get("type") == "date" | |
| and (not spec.get("knowledge")) | |
| and ("source_only" not in spec) | |
| and ("null_threshold" not in spec) | |
| and isinstance(instructions, str) | |
| and bool(_READING_INTENT.search(instructions)) | |
| and ( | |
| not ( | |
| _DERIVED.search(instructions) | |
| or _RELATIVE.search(instructions) | |
| or _EXPRESSION_REQUEST.search(instructions) | |
| ) | |
| ) | |
| ) | |
| class Candidate: | |
| start: int | |
| end: int | |
| printed: str | |
| iso_values: tuple[str, ...] | |
| notation: str | |
| def ambiguous(self) -> bool: | |
| return len(self.iso_values) != 1 | |
| def _iso(year: str | int, month: str | int, day: str | int) -> str | None: | |
| try: | |
| return date(int(year), int(month), int(day)).isoformat() | |
| except ValueError: | |
| return None | |
| def _ordinal_valid(day: int, suffix: str | None) -> bool: | |
| if not suffix: | |
| return True | |
| expected = ( | |
| "th" | |
| if 11 <= day % 100 <= 13 | |
| else {1: "st", 2: "nd", 3: "rd"}.get(day % 10, "th") | |
| ) | |
| return suffix.casefold() == expected | |
| def candidates( | |
| source: str, *, numeric_order: str | None = None | |
| ) -> tuple[Candidate, ...]: | |
| if numeric_order not in (None, "mdy", "dmy"): | |
| raise ValueError("Numeric date order must be explicitly mdy or dmy") | |
| result = [] | |
| for pattern in (_DMY, _MDY): | |
| for match in pattern.finditer(source): | |
| if not _ordinal_valid(int(match["day"]), match["ordinal"]): | |
| continue | |
| value = _iso( | |
| match["year"], | |
| _MONTHS[match["month"].rstrip(".").casefold()], | |
| match["day"], | |
| ) | |
| if value: | |
| result.append( | |
| Candidate( | |
| match.start(), match.end(), match[0], (value,), "named_month" | |
| ) | |
| ) | |
| for match in _YMD.finditer(source): | |
| value = _iso(match["year"], match["month"], match["day"]) | |
| if value: | |
| result.append( | |
| Candidate(match.start(), match.end(), match[0], (value,), "year_first") | |
| ) | |
| for match in _NUMERIC.finditer(source): | |
| (first, second) = (int(match["first"]), int(match["second"])) | |
| readings = set() | |
| orders = (numeric_order,) if numeric_order else ("mdy", "dmy") | |
| for order in orders: | |
| value = _iso( | |
| match["year"], | |
| first if order == "mdy" else second, | |
| second if order == "mdy" else first, | |
| ) | |
| if value: | |
| readings.add(value) | |
| if readings: | |
| result.append( | |
| Candidate( | |
| match.start(), | |
| match.end(), | |
| match[0], | |
| tuple(sorted(readings)), | |
| "numeric", | |
| ) | |
| ) | |
| return tuple(sorted(set(result), key=lambda item: (item.start, -item.end))) | |
| class DateSource: | |
| def __init__(self, source: str, *, numeric_order: str | None = None) -> None: | |
| self.text = source | |
| self.candidates = candidates(source, numeric_order=numeric_order) | |
| self.ambiguous = tuple((item for item in self.candidates if item.ambiguous)) | |
| self.support: dict[str, list[Candidate]] = {} | |
| for item in self.candidates: | |
| if not item.ambiguous: | |
| self.support.setdefault(item.iso_values[0], []).append(item) | |
| self.values = tuple(self.support) | |
| def constraint(self, *, nullable: bool = True) -> dict[str, str]: | |
| literals = [json.dumps(value) for value in self.values] | |
| if nullable: | |
| literals.append("null") | |
| if not literals: | |
| raise ValueError( | |
| "No unambiguous source date satisfies a nonnullable date contract" | |
| ) | |
| return { | |
| "ebnf": "root ::= " + " | ".join((json.dumps(value) for value in literals)) | |
| } | |
| def span(self, value: object) -> tuple[bool, list[int] | None]: | |
| matches = self.support.get(value, ()) if isinstance(value, str) else () | |
| intervals = {(item.start, item.end) for item in matches} | |
| return ( | |
| bool(intervals), | |
| list(next(iter(intervals))) if len(intervals) == 1 else None, | |
| ) | |
| def evidence(self, value: str) -> list[dict[str, Any]]: | |
| return [asdict(item) for item in self.support.get(value, ())] | |
| def annotate_predictions( | |
| self, predictions: dict[str, dict[str, Any]], names: Iterable[str] | |
| ) -> dict[str, dict[str, Any]]: | |
| result = dict(predictions) | |
| for name in names: | |
| if name not in predictions: | |
| continue | |
| answer = dict(predictions[name]) | |
| result[name] = answer | |
| answer.update( | |
| date_decoder=VERSION, score_representation="native_json_iso_date_wire" | |
| ) | |
| if ( | |
| not answer.get("valid") | |
| or not answer.get("complete") | |
| or answer.get("value") is None | |
| ): | |
| continue | |
| (found, span) = self.span(answer["value"]) | |
| if not found: | |
| answer.update( | |
| valid=False, | |
| value=None, | |
| span=None, | |
| failure_reason="not_a_printed_date_candidate", | |
| ) | |
| continue | |
| answer.update( | |
| grounding_method="printed_date_candidates_source", | |
| span=span, | |
| source_date_candidates=self.evidence(answer["value"]), | |
| ) | |
| answer.pop("span_method", None) | |
| if span is not None: | |
| answer.update( | |
| span_method="unique_normalized_printed_date_match", | |
| printed_value=self.text[slice(*span)], | |
| ) | |
| return result | |
| def merge_predictions( | |
| self, | |
| original: dict[str, dict[str, Any]], | |
| alternatives: dict[str, dict[str, Any]], | |
| names: Iterable[str], | |
| ) -> dict[str, dict[str, Any]]: | |
| result = original | |
| if not self.automatic_route_safe(): | |
| return result | |
| for name in names: | |
| previous = original.get(name) | |
| answer = alternatives.get(name) | |
| if not isinstance(previous, dict) or not isinstance(answer, dict): | |
| continue | |
| if previous.get("type") not in (None, "date"): | |
| continue | |
| previous_value = previous.get("value") | |
| if not isinstance(previous_value, str) or previous_value in self.support: | |
| continue | |
| value = answer.get("value") | |
| if ( | |
| answer.get("valid") is not True | |
| or answer.get("complete") is not True | |
| or (not isinstance(value, str)) | |
| or (value not in self.support) | |
| or (answer.get("date_decoder") != VERSION) | |
| or (answer.get("grounding_method") != "printed_date_candidates_source") | |
| or (answer.get("span") != self.span(value)[1]) | |
| or (not isinstance(answer.get("raw"), str)) | |
| ): | |
| continue | |
| try: | |
| if ( | |
| date.fromisoformat(value).isoformat() != value | |
| or json.loads(answer["raw"]) != value | |
| ): | |
| continue | |
| except (ValueError, TypeError): | |
| continue | |
| if value == previous.get("value"): | |
| continue | |
| if result is original: | |
| result = dict(original) | |
| result[name] = {**answer, "type": "date"} | |
| return result | |
| def automatic_route_safe(self) -> bool: | |
| return ( | |
| bool(self.values) | |
| and (not self.ambiguous) | |
| and (not _CALENDAR_EXPRESSION.search(self.text)) | |
| ) | |
| def allows(self, spec: dict[str, Any]) -> bool: | |
| return eligible(spec) and self.automatic_route_safe() | |
| def report(self) -> dict[str, Any]: | |
| return { | |
| "version": VERSION, | |
| "values": self.values, | |
| "candidates": [asdict(item) for item in self.candidates], | |
| "ambiguous_candidates": [asdict(item) for item in self.ambiguous], | |
| "calendar_expression_in_source": bool( | |
| _CALENDAR_EXPRESSION.search(self.text) | |
| ), | |
| "automatic_route_safe": self.automatic_route_safe(), | |
| } | |