thinking

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 18, 2026 License: BSD-3-Clause Imports: 0 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

thinking

Fold how hard to think into the native shape each upstream model accepts.

Callers speak two dialects — Anthropic sends a token budget, OpenAI sends an effort ordinal — and every upstream reasons by its own control. Between them sits one neutral value, a Depth ordinal: each dialect is a constructor into it, each upstream a projection out of it.

d := thinking.Budget(32000)        // Anthropic "ultrathink" → Max
d := thinking.Effort("high")       // OpenAI reasoning_effort → High

v := thinking.Of("glm-5.2")        // GLM
d.Fields(v)                        // {"reasoning_effort": "max"}

thinking.Max.Fields(thinking.Of("kimi-k2.6"))
// {"thinking": {"type": "enabled", "preserve_thinking": "all"}}

thinking.High.Fields(thinking.Of("qwen3.5-397b-a17b"))
// {"enable_thinking": true}

One home for the map, so every serving layer folds the same way. Clear thinking.Keys on the outbound body before merging Fields, so the fold is the sole writer and no field leaks across a vocabulary boundary.

Vocabularies

Vocab upstreams control
GLM GLM-5.*, DeepSeek V4, the DO-AI default reasoning_effort ∈ {high, max}
OpenAI o-series reasoning_effort ∈ {low, medium, high}
Qwen Qwen 3.* enable_thinking gate
Kimi Kimi K2.* thinking object (preserve_thinking)

The fold is total and monotone — deeper in, harder out — and lossy where a vocabulary is coarser (GLM has no low/medium; OpenAI has no max).

Documentation

Overview

Package thinking folds how-hard-to-think into the native shape each upstream model accepts. Callers speak two dialects — Anthropic sends a token budget, OpenAI sends an effort ordinal — and every upstream reasons by its own control: GLM/DeepSeek by a reasoning_effort ordinal, Qwen by an enable_thinking gate, Kimi by a thinking object. Between them sits ONE neutral value, a Depth ordinal: each dialect is a constructor into it, each upstream a projection out of it.

This is the sole home of that map, so ai and zen share one table (as they already share hanzoai/decimal and hanzoai/money). The fold is total and monotone — deeper in, harder out — and lossy where a vocabulary is coarser.

Index

Constants

This section is empty.

Variables

View Source
var Keys = []string{"reasoning_effort", "enable_thinking", "thinking_budget", "thinking"}

Keys is every field any vocabulary may write. A caller clears these before applying Fields so the fold is the sole writer and nothing leaks across a vocabulary boundary.

Functions

This section is empty.

Types

type Depth

type Depth int

Depth is how hard to think, as an ordinal — the neutral value both wire dialects normalize into and every upstream projects out of. Off means the caller declined to think; the rest ascend.

const (
	Off  Depth = iota // don't think — the instant path
	Low               // light
	Mid               // moderate
	High              // hard
	Max               // hardest
)

func Budget

func Budget(tokens int) Depth

Budget folds an Anthropic thinking.budget_tokens into a Depth. Zero (thinking absent or disabled) is Off; any positive budget is on, at a tier set by size.

func Effort

func Effort(ordinal string) Depth

Effort folds an OpenAI reasoning_effort ordinal into a Depth. An unknown or empty value is Off.

func (Depth) Fields

func (d Depth) Fields(v Vocab) map[string]any

Fields projects the depth into the request fields a vocabulary accepts, as a map to merge into an upstream chat body — {} when the vocabulary takes no field for the depth. It is the sole producer of these keys, so a caller clears Keys first: a stale field from another vocabulary must never reach this upstream.

Off is not always empty: a GLM-family upstream reasons BY DEFAULT, so Off (the instant path) must actively send reasoning_effort:"none" — the absence of the field would leave the model reasoning, streaming a long content:null preamble that reads as an empty completion. Vocabularies that default OFF (Qwen/Kimi gates, OpenAI o-series) write nothing for Off, as before.

func (Depth) On

func (d Depth) On() bool

On reports whether the caller asked to think at all. Off writes no field, leaving the upstream at its own default.

type Vocab

type Vocab string

Vocab is the reasoning control an upstream accepts, keyed by request shape — not by brand. Pick it with Of.

const (
	GLM    Vocab = "glm"    // reasoning_effort ∈ {none, high, max}: GLM-5.*, DeepSeek V4, the DO-AI default (reasons unless told none)
	OpenAI Vocab = "openai" // reasoning_effort ∈ {low, medium, high}: o-series
	Qwen   Vocab = "qwen"   // enable_thinking gate
	Kimi   Vocab = "kimi"   // a thinking object {type, preserve_thinking}
)

func Of

func Of(upstream string) Vocab

Of returns the vocabulary an upstream model id accepts, keyed by id prefix — the one place brand maps to control shape. Unknown ids fold as GLM: the DO-AI family (glm-5.*, deepseek-*, minimax-*, nemotron-*, llama*) is the universal upstream and its two-tier ordinal is the safe supposition.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址