Something went wrong. Try again.
Parametric learning in your code harness.
Something went wrong. Try again.
Python
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116#!/usr/bin/env python3"""No-provider Inkling probe for expanded LAST_ASSISTANT_MESSAGE targets."""from __future__ import annotations
import ioimport jsonimport sysfrom contextlib import redirect_stderrfrom pathlib import Path
ROOT = Path(__file__).resolve().parentsys.path.insert(0, str(ROOT))
stderr_buf = io.StringIO()try: with redirect_stderr(stderr_buf): from tinker_cookbook import model_info from tinker_cookbook.tokenizer_utils import get_tokenizer from tinker_cookbook.renderers import get_rendererexcept Exception as e: print(json.dumps({"ok": False, "skipped": True, "stage": "import", "error": f"{type(e).__name__}: {e}"})) raise SystemExit(0)
from assistant_targets import expand_assistant_targetsfrom thinking_renderer_validation import probe_rendered_shape, validate_messages_thinking_renderer
MODEL = "thinkingmachines/Inkling-Small"THINKING = "This is a casual greeting rather than a substantive request. Match its brevity and wait for the actual request."
ANSWER_FIRST = [ {"role": "user", "content": "Good morning."}, { "role": "assistant", "content": [ {"type": "thinking", "thinking": THINKING}, {"type": "text", "text": "Good morning."}, ], },]
TOOL_CALL_FIRST = [ {"role": "user", "content": "Write a Turing model"}, { "role": "assistant", "content": [{"type": "thinking", "thinking": "Check whether Julia is installed before drafting code."}], "tool_calls": [{ "id": "call_julia", "type": "function", "function": {"name": "bash", "arguments": "{\"command\":\"which julia\"}"}, }], }, {"role": "tool", "content": "/usr/bin/julia", "tool_call_id": "call_julia"}, {"role": "assistant", "content": "Julia is installed."},]
try: with redirect_stderr(stderr_buf): renderer_name = model_info.get_recommended_renderer_name(MODEL) tokenizer = get_tokenizer(MODEL) renderer = get_renderer(renderer_name, tokenizer)except Exception as e: print(json.dumps({"ok": False, "stage": "renderer", "error": f"{type(e).__name__}: {e}"})) raise SystemExit(0)
def summarize(messages): with redirect_stderr(stderr_buf): validation = validate_messages_thinking_renderer(messages, renderer, tokenizer) targets = expand_assistant_targets(messages) target_probes = [probe_rendered_shape(target, renderer, tokenizer) for target in targets] return { "ok": validation.get("ok", False), "targetCount": len(targets), "trainOnWhat": "LAST_ASSISTANT_MESSAGE", "totalTokens": validation.get("totalTokens"), "weightedTokens": validation.get("weightedTokens"), "hasContentThinking": validation.get("hasContentThinking"), "hasQwenThink": validation.get("hasQwenThink"), "hasThinkingChannel": validation.get("hasThinkingChannel"), "thinkingChannels": validation.get("thinkingChannels"), "hasContentText": validation.get("hasContentText"), "toolPreserved": validation.get("toolPreserved"), "toolNames": validation.get("toolNames"), "thinkingCount": validation.get("thinkingCount"), "targetReceipts": validation.get("targetReceipts"), "targetProbes": [ { "totalTokens": probe.get("totalTokens"), "weightedTokens": probe.get("weightedTokens"), "hasThinkingChannel": probe.get("hasThinkingChannel"), "toolNames": probe.get("toolNames"), "toolPreserved": probe.get("toolPreserved"), } for probe in target_probes ], "reason": validation.get("reason"), }
answer_first = summarize(ANSWER_FIRST)tool_call_first = summarize(TOOL_CALL_FIRST)stderr_text = stderr_buf.getvalue()extension_warning = "has_extension_property=False" in stderr_text or "ALL_ASSISTANT_MESSAGES" in stderr_textok = answer_first.get("ok") and tool_call_first.get("ok") and not extension_warning
print(json.dumps({ "ok": ok, "model": MODEL, "renderer": renderer_name, "trainOnWhat": "LAST_ASSISTANT_MESSAGE", "extensionPropertyWarning": extension_warning, "stderr": stderr_text.strip()[:2000] if stderr_text.strip() else "", "answerFirst": answer_first, "toolCallFirst": tool_call_first,}))