ir

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package ir defines the gateway-owned chat internal representation.

Index

Constants

View Source
const (
	DialectOpenAI    = chatir.DialectOpenAI
	DialectAnthropic = chatir.DialectAnthropic
	DialectGemini    = chatir.DialectGemini
)
View Source
const (
	ContentText  = chatir.ContentText
	ContentImage = chatir.ContentImage
)
View Source
const (
	ToolChoiceAuto     = chatir.ToolChoiceAuto
	ToolChoiceNone     = chatir.ToolChoiceNone
	ToolChoiceRequired = chatir.ToolChoiceRequired
	ToolChoiceTool     = chatir.ToolChoiceTool
)
View Source
const (
	StreamMessageStart  = chatir.StreamMessageStart
	StreamTextDelta     = chatir.StreamTextDelta
	StreamToolCallStart = chatir.StreamToolCallStart
	StreamToolCallDelta = chatir.StreamToolCallDelta
	StreamMessageEnd    = chatir.StreamMessageEnd
	StreamError         = chatir.StreamError
)
View Source
const (
	DialectSupportsTools  = true
	DialectSupportsVision = true
)

Gateway dialect IR capabilities for the current chat IR version. Catalog advertising and request validation must stay in sync with these.

Variables

This section is empty.

Functions

func EncodeAnthropic

func EncodeAnthropic(req ChatRequest, targetModel string) ([]byte, error)

EncodeAnthropic marshals a ChatRequest to Anthropic messages JSON.

func EncodeAnthropicResponse

func EncodeAnthropicResponse(resp ChatResponse) ([]byte, error)

EncodeAnthropicResponse marshals ChatResponse to Anthropic message JSON.

func EncodeOpenAI

func EncodeOpenAI(req ChatRequest) ([]byte, error)

EncodeOpenAI marshals a ChatRequest to OpenAI chat.completions JSON.

This is the canonical bridge format used between hooks and provider adapters, so it must faithfully carry tools, multimodal content, and tool messages.

func EncodeOpenAIResponse

func EncodeOpenAIResponse(resp ChatResponse) ([]byte, error)

EncodeOpenAIResponse marshals ChatResponse to OpenAI chat.completion JSON.

func MapAnthropicStopReason

func MapAnthropicStopReason(r string) string

MapAnthropicStopReason maps Anthropic stop_reason to IR finish_reason.

func Unsupported

func Unsupported(feature, message string) error

Unsupported returns a new UnsupportedError.

Types

type ChatRequest

type ChatRequest = chatir.Request

ChatRequest is the dialect-neutral chat request.

func DecodeAnthropicRequest

func DecodeAnthropicRequest(body []byte) (ChatRequest, error)

DecodeAnthropicRequest parses Anthropic messages JSON into ChatRequest.

func DecodeOpenAIRequest

func DecodeOpenAIRequest(body []byte) (ChatRequest, error)

DecodeOpenAIRequest parses OpenAI chat.completions JSON into ChatRequest.

type ChatResponse

type ChatResponse = chatir.Response

ChatResponse is a non-streaming assistant reply.

func DecodeAnthropicResponse

func DecodeAnthropicResponse(body []byte) (ChatResponse, error)

DecodeAnthropicResponse parses Anthropic message JSON into ChatResponse.

func DecodeOpenAIResponse

func DecodeOpenAIResponse(body []byte) (ChatResponse, error)

DecodeOpenAIResponse parses OpenAI chat.completion JSON into ChatResponse.

type ChatResult

type ChatResult = chatir.Result

ChatResult is either a completed response, a stream of events, or an upstream HTTP error body.

type ContentPart

type ContentPart = chatir.ContentPart

ContentPart is one piece of multimodal message content.

type ContentPartType

type ContentPartType = chatir.ContentPartType

ContentPartType enumerates supported content part kinds.

type Dialect

type Dialect = chatir.Dialect

Dialect identifies a client wire format.

type ImageSource

type ImageSource = chatir.ImageSource

ImageSource references image bytes either by URL or inline base64 data.

type Message

type Message = chatir.Message

Message is a single chat turn.

type StreamEvent

type StreamEvent = chatir.StreamEvent

StreamEvent is one IR streaming unit.

type StreamEventKind

type StreamEventKind = chatir.StreamEventKind

StreamEventKind classifies streaming IR events.

type Tool

type Tool = chatir.Tool

Tool is a function tool the model may call.

type ToolCall

type ToolCall = chatir.ToolCall

ToolCall is a model-issued function call.

type ToolChoice

type ToolChoice = chatir.ToolChoice

ToolChoice expresses tool_choice across dialects.

type ToolChoiceMode

type ToolChoiceMode = chatir.ToolChoiceMode

ToolChoiceMode controls whether/which tool the model must call.

type UnsupportedError

type UnsupportedError struct {
	Feature string
	Message string
}

UnsupportedError is returned when a client request uses a feature chat IR cannot serve yet.

func AsUnsupported

func AsUnsupported(err error) (*UnsupportedError, bool)

AsUnsupported extracts UnsupportedError from err.

func (*UnsupportedError) Error

func (e *UnsupportedError) Error() string

type Usage

type Usage = chatir.Usage

Usage holds token counts.

Jump to

Keyboard shortcuts

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