run

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: MIT Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MsgType_Msg        = "msg"
	MsgType_ToolCall   = "tool_call"
	MsgType_ToolResult = "tool_result"
	MsgType_TokenUsage = "token_usage"
	MsgType_StopReason = "stop_reason" // anthropic specific
)
View Source
const (
	Role_User      = "user"
	Role_Assistant = "assistant"
	Role_System    = "system"
)

Variables

This section is empty.

Functions

func Main

func Main(args []string, opts Options) error

Types

type ChatHandler

type ChatHandler struct {
	Provider             providers.Provider
	TokenEnvKey          string
	BaseUrlEnvKey        string
	DefaultBaseUrlEnvKey string
	// contains filtered or unexported fields
}

func (*ChatHandler) Handle

func (c *ChatHandler) Handle(model string, baseUrl string, token string, msg string, opts ChatOptions) error

type ChatOptions

type ChatOptions struct {
	// contains filtered or unexported fields
}

type ClientUnion

type ClientUnion struct {
	OpenAI    *openai.Client
	Anthropic *anthropic.Client
}

type Message

type Message struct {
	Type    MsgType `json:"type"`
	Time    string  `json:"time"`
	Role    Role    `json:"role"`
	Model   string  `json:"model"`
	Content string  `json:"content"`

	ToolUseID  string      `json:"tool_use_id,omitempty"`
	ToolName   string      `json:"tool_name,omitempty"`
	TokenUsage *TokenUsage `json:"token_usage,omitempty"`
}

Message represents a message in the chat record

type MessageHistoryUnion

type MessageHistoryUnion struct {
	FullHistory Messages

	OpenAI        []openai.ChatCompletionMessageParamUnion
	Anthropic     []anthropic.MessageParam
	SystemPrompts []string
}

type Messages

type Messages []Message

Messages represents a slice of unified messages with conversion methods

func (Messages) ToAnthropic

func (messages Messages) ToAnthropic() (msgs []anthropic.MessageParam, systemPrompts []string, err error)

ToAnthropic converts unified messages to Anthropic format

func (Messages) ToOpenAI

func (messages Messages) ToOpenAI(keepSystemPrompts bool) (msgs []openai.ChatCompletionMessageParamUnion, systemPrompts []string, err error)

ToAnthropic converts unified messages to Anthropic format

func (Messages) ToOpenAI2

func (messages Messages) ToOpenAI2() []openai.ChatCompletionMessageParamUnion

ToOpenAI converts unified messages to OpenAI format

type MessagesUnion

type MessagesUnion struct {
	OpenAI    []openai.ChatCompletionMessageParamUnion
	Anthropic []anthropic.MessageParam
}

type MsgType

type MsgType string

type Number

type Number string

type Options

type Options struct {
	BaseCmd        string
	DefaultBaseURL string
}

type ResponseResultAnthropic

type ResponseResultAnthropic struct {
	HasToolCalls bool
	Messages     []anthropic.ContentBlockParamUnion
	ToolResults  []anthropic.ContentBlockParamUnion
	TokenUsage   TokenUsage
}

type ResponseResultOpenAI

type ResponseResultOpenAI struct {
	HasToolCalls bool
	Messages     []openai.ChatCompletionMessageParamUnion
	ToolResults  []openai.ChatCompletionMessageParamUnion
	TokenUsage   TokenUsage
}

type Role

type Role string

type TokenCost

type TokenCost struct {
	// the three are available for all providers
	InputUSD  string
	OutputUSD string
	TotalUSD  string

	// Input breakdown
	// anthropic has this detail
	InputBreakdown TokenCostInputBreakdown
}

func (TokenCost) Add

func (c TokenCost) Add(b TokenCost) TokenCost

type TokenCostInputBreakdown

type TokenCostInputBreakdown struct {
	CacheWriteUSD   string
	CacheReadUSD    string
	NonCacheReadUSD string
}

func (TokenCostInputBreakdown) Add

type TokenUsage

type TokenUsage struct {
	Input  int64 `json:"input"`
	Output int64 `json:"output"`
	Total  int64 `json:"total"`

	InputBreakdown  TokenUsageInputBreakdown  `json:"input_breakdown"`
	OutputBreakdown TokenUsageOutputBreakdown `json:"output_breakdown"`
}

Anthropic:

func (TokenUsage) Add

func (c TokenUsage) Add(b TokenUsage) TokenUsage

type TokenUsageCost

type TokenUsageCost struct {
	Usage TokenUsage
	Cost  TokenCost
}

type TokenUsageInputBreakdown

type TokenUsageInputBreakdown struct {
	CacheWrite   int64 `json:"cache_write"` // anthropic specific
	CacheRead    int64 `json:"cache_read"`
	NonCacheRead int64 `json:"non_cache_read"`
}

func (TokenUsageInputBreakdown) Add

type TokenUsageOutputBreakdown

type TokenUsageOutputBreakdown struct {
	CacheOutput int64 `json:"cache_output"`
}

func (TokenUsageOutputBreakdown) Add

type ToolsUnion

type ToolsUnion struct {
}

Jump to

Keyboard shortcuts

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