run

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 34 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 {
	APIShape providers.APIShape
	// 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
	Gemini    *genai.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
	SystemPrompts []string

	OpenAI    []openai.ChatCompletionMessageParamUnion
	Anthropic []anthropic.MessageParam
	Gemini    []*genai.Content
}

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) ToGemini added in v0.0.7

func (messages Messages) ToGemini() (msgs []*genai.Content, systemPrompts []string, err error)

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
	Gemini    []*genai.Content
}

type MsgType

type MsgType string

type Number

type Number string

type Options

type Options struct {
	BaseCmd        string
	DefaultBaseURL string
}

type ResolvedOptions added in v0.0.8

type ResolvedOptions struct {
	AbsDefaultToolCwd string
	Token             string
	BaseUrl           string
}

func ResolveEnvOptions added in v0.0.8

func ResolveEnvOptions(defaultToolCwd string, token string, tokenEnvKey string, baseUrl string, baseUrlEnvKey string, defaultBaseUrlEnvKey string, defaultBaseUrl string) (ResolvedOptions, error)

func ResolveProviderDefaultEnvOptions added in v0.0.8

func ResolveProviderDefaultEnvOptions(apiShape providers.APIShape, provider providers.Provider, defaultToolCwd string, token string, baseUrl string, defaultBaseUrl string) (ResolvedOptions, error)

type ResponseResultAnthropic

type ResponseResultAnthropic struct {
	ToolUseNum int

	Messages    []anthropic.ContentBlockParamUnion
	ToolResults []anthropic.ContentBlockParamUnion
	TokenUsage  TokenUsage
}

type ResponseResultGemini added in v0.0.7

type ResponseResultGemini struct {
	ToolUseNum  int
	Messages    []*genai.Content
	ToolResults []*genai.Content
	TokenUsage  TokenUsage
}

type ResponseResultOpenAI

type ResponseResultOpenAI struct {
	ToolUseNum  int
	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 ToolInfo added in v0.0.8

type ToolInfo struct {
	Name   string
	Preset bool

	ToolDefinition *tools.UnifiedTool

	MCPServer string
	MCPClient *client.Client
}

func (*ToolInfo) String added in v0.0.8

func (c *ToolInfo) String() string

type ToolInfoMapping added in v0.0.8

type ToolInfoMapping map[string]*ToolInfo

func (ToolInfoMapping) AddTool added in v0.0.8

func (c ToolInfoMapping) AddTool(toolName string, toolInfo *ToolInfo) error

Jump to

Keyboard shortcuts

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