claude

package
v0.45.0 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertToolUseToToolJSON added in v0.44.0

func ConvertToolUseToToolJSON(id, name string, input map[string]interface{}) (string, error)

ConvertToolUseToToolJSON は Claude の tool_use を内部JSON形式に変換 Returns: {"id": "toolu_01ABC...", "tool": "read_file", "args": {"path": "/path/to/file"}}

func GetToolDefinitionNames added in v0.44.0

func GetToolDefinitionNames() []string

GetToolDefinitionNames は定義済みツール名一覧を返す(テスト用)

func LevelToBudgetTokens

func LevelToBudgetTokens(level string) int

LevelToBudgetTokens は api.LevelToBudgetTokens のエイリアス(後方互換)

Types

type CacheControl

type CacheControl struct {
	Type string `json:"type"` // e.g. "ephemeral"
}

CacheControl enables prompt caching for a content block.

This is gated by config.PromptCache.Enabled and disabled by default. If the upstream schema changes, requests may fail; keep the feature optional.

type ClaudeTool added in v0.44.0

type ClaudeTool struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description,omitempty"`
	InputSchema map[string]interface{} `json:"input_schema"`
}

ClaudeTool は Anthropic Claude API 用のツール定義 OpenAI とは異なり、フラットな構造で input_schema を使用

func ConvertOpenAIToolToClaude added in v0.44.0

func ConvertOpenAIToolToClaude(tool api.OpenAIToolFunction) ClaudeTool

ConvertOpenAIToolToClaude は OpenAI 形式のツールを Claude 形式に変換する

func GetClaudeToolDefinitions added in v0.44.0

func GetClaudeToolDefinitions() []ClaudeTool

GetClaudeToolDefinitions は組み込みツール定義を Claude 形式で返す ToolRegistry から自動生成

func GetCombinedClaudeTools added in v0.44.0

func GetCombinedClaudeTools(mcpTools []api.OpenAIToolFunction) []ClaudeTool

GetCombinedClaudeTools は組み込みツール + MCPツールを返す

type Content

type Content struct {
	Type  string                 `json:"type"`            // "text" or "tool_use"
	Text  string                 `json:"text,omitempty"`  // text 用
	ID    string                 `json:"id,omitempty"`    // tool_use 用
	Name  string                 `json:"name,omitempty"`  // tool_use 用
	Input map[string]interface{} `json:"input,omitempty"` // tool_use 用
}

Content はレスポンスのコンテンツ

type ContentBlock added in v0.44.0

type ContentBlock struct {
	Type  string                 `json:"type"`            // "text" or "tool_use"
	ID    string                 `json:"id,omitempty"`    // tool_use 用
	Name  string                 `json:"name,omitempty"`  // tool_use 用
	Text  string                 `json:"text,omitempty"`  // text 用
	Input map[string]interface{} `json:"input,omitempty"` // tool_use 用(非ストリーミング)
}

ContentBlock はストリーミングのコンテンツブロック (content_block_start 用)

type ContentPart

type ContentPart struct {
	Type   string       `json:"type"`             // "text" or "image"
	Text   string       `json:"text,omitempty"`   // type="text"の場合
	Source *ImageSource `json:"source,omitempty"` // type="image"の場合
}

ContentPart はマルチモーダルコンテンツのパート

type Delta

type Delta struct {
	Type        string `json:"type"`
	Text        string `json:"text,omitempty"`
	PartialJSON string `json:"partial_json,omitempty"` // tool_use の input (input_json_delta)
	StopReason  string `json:"stop_reason,omitempty"`  // message_delta 用
}

Delta はストリームの差分

type ImageSource

type ImageSource struct {
	Type      string `json:"type"`       // "base64"
	MediaType string `json:"media_type"` // "image/png", "image/jpeg" etc
	Data      string `json:"data"`       // Base64エンコードされたデータ
}

ImageSource は画像ソース

type Message

type Message struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

Message はClaudeのメッセージ構造

type MultimodalMessage

type MultimodalMessage struct {
	Role    string        `json:"role"`
	Content []ContentPart `json:"content"`
}

MultimodalMessage はマルチモーダルメッセージ(画像含む)

type MultimodalRequest

type MultimodalRequest struct {
	Model    string        `json:"model"`
	Messages []interface{} `json:"messages"` // Message or MultimodalMessage
	// System can be either string (legacy) or []SystemBlock (prompt caching).
	System    interface{}     `json:"system,omitempty"`
	MaxTokens int             `json:"max_tokens"`
	Stream    bool            `json:"stream"`
	Thinking  *ThinkingConfig `json:"thinking,omitempty"`
	Tools     []ClaudeTool    `json:"tools,omitempty"` // Tool Use用
}

MultimodalRequest はマルチモーダルAPIリクエスト

type Provider

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

Provider はClaude (Anthropic) APIのプロバイダー実装

func New

func New(apiKey string) *Provider

New は新しいProviderを作成

func (*Provider) ChatWithImage

func (p *Provider) ChatWithImage(ctx context.Context, systemPrompt string, history []api.Message, userMessage string, image *api.ImageData, model string) (string, error)

ChatWithImage は画像付きメッセージで会話を行う

func (*Provider) ChatWithTools

func (p *Provider) ChatWithTools(ctx context.Context, systemPrompt string, history []api.Message, model string) (string, error)

ChatWithTools は Provider interface の実装(context対応)

func (*Provider) Name

func (p *Provider) Name() string

Name はプロバイダー名を返す

func (*Provider) SetMCPTools added in v0.44.0

func (p *Provider) SetMCPTools(tools []api.OpenAIToolFunction)

SetMCPTools は MCP ツール定義を設定する(Tool Use用)

func (*Provider) SupportsImages

func (p *Provider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type Request

type Request struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	// System can be either string (legacy) or []SystemBlock (prompt caching).
	System    interface{}     `json:"system,omitempty"`
	MaxTokens int             `json:"max_tokens"`
	Stream    bool            `json:"stream"`
	Thinking  *ThinkingConfig `json:"thinking,omitempty"`
	Tools     []ClaudeTool    `json:"tools,omitempty"` // Tool Use用
}

type Response

type Response struct {
	Content    []Content `json:"content"`
	StopReason string    `json:"stop_reason,omitempty"` // "end_turn", "tool_use" など
}

Response は通常レスポンス

type StreamEvent

type StreamEvent struct {
	Type         string        `json:"type"`
	Index        int           `json:"index,omitempty"`
	ContentBlock *ContentBlock `json:"content_block,omitempty"` // content_block_start 用
	Delta        *Delta        `json:"delta,omitempty"`
}

StreamEvent はストリームイベント

type SystemBlock

type SystemBlock struct {
	Type         string        `json:"type"` // "text"
	Text         string        `json:"text"`
	CacheControl *CacheControl `json:"cache_control,omitempty"`
}

SystemBlock represents a system prompt content block.

When prompt caching is enabled, we send system as an array of blocks instead of a string.

type ThinkingConfig

type ThinkingConfig struct {
	Type         string `json:"type"`          // "enabled"
	BudgetTokens int    `json:"budget_tokens"` // min 1024
}

ThinkingConfig は Extended Thinking の設定

Jump to

Keyboard shortcuts

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