transform

package
v0.0.21 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package transform provides IR-level request transformers (system prompt injection, role mapping, thinking pass-through/strip) that the relay pipeline applies between inbound decode and outbound encode.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyRoleMapping

func ApplyRoleMapping(messages []llmkit.Message, mapping map[llmkit.Role]llmkit.Role)

ApplyRoleMapping applies role mapping to a list of IR messages. Messages are modified in place. Unknown roles are preserved.

func ApplyThinkingPassthrough added in v0.0.8

func ApplyThinkingPassthrough(messages []llmkit.Message)

ApplyThinkingPassthrough 给"带 tool_calls 但无 thinking block"的 assistant 消息 补一个空文本占位 thinking block。逻辑从 ThinkingPassthroughTransformer 抽出,行为不变。

func ApplyThinkingStrip added in v0.0.8

func ApplyThinkingStrip(messages []llmkit.Message) []llmkit.Message

ApplyThinkingStrip 剥离 assistant 消息上的所有 thinking block,并删除仅因本次 剥离而变空的 assistant shell。

Types

type RoleMappingConfig

type RoleMappingConfig struct {
	// Default mappings applied to all models in this channel
	Default map[llmkit.Role]llmkit.Role `json:"default,omitempty"`
	// Per-model mappings; keys support wildcard patterns (e.g., "claude-*")
	Models map[string]map[llmkit.Role]llmkit.Role `json:"models,omitempty"`
}

RoleMappingConfig represents the role mapping configuration for a channel.

func ParseRoleMapping

func ParseRoleMapping(raw string) *RoleMappingConfig

ParseRoleMapping parses a JSON string into a RoleMappingConfig. Returns nil if the input is empty or invalid.

func (*RoleMappingConfig) ResolveRoleMapping

func (c *RoleMappingConfig) ResolveRoleMapping(modelName string) map[llmkit.Role]llmkit.Role

ResolveRoleMapping returns the applicable role mapping for a given model name. Priority: exact model match > wildcard match > default. Returns nil if no mapping applies.

Jump to

Keyboard shortcuts

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