api

package
v0.39.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxImageSize 最大画像サイズ: 10MB
	MaxImageSize = 10 * 1024 * 1024
)

Variables

This section is empty.

Functions

func AskDeepSeekStream

func AskDeepSeekStream(query string, context string, model string) (string, error)

AskDeepSeekStream は従来のストリーミング質問(後方互換) Deprecated: 後方互換性のために残されています。ChatWithTools を使用してください。

func ChatWithTools

func ChatWithTools(systemPrompt string, history []Message, model string) (string, error)

ChatWithTools はツール対応の会話を行う(ストリーミング) Deprecated: 後方互換性のために残されています。NewDeepSeekProvider + Client を使用してください。

func FormatImageSize added in v0.29.0

func FormatImageSize(bytes int64) string

FormatImageSize はバイト数を人間が読みやすい形式に変換

func ParseStreamingResponse

func ParseStreamingResponse(ctx context.Context, resp *http.Response, spinner *ui.Spinner, parser StreamParser) (string, error)

ParseStreamingResponse は共通のストリーミングレスポンス処理 コンテキストキャンセル、スピナー制御、エラーハンドリングを統一的に処理 アイドルタイムアウト方式: データ受信がない状態がN秒続くとタイムアウト ツールJSON部分は内部で記録するが表示しない

func SupportsImages added in v0.29.0

func SupportsImages(providerName string) bool

SupportsImages はプロバイダー名から画像対応を判定

func ValidateChatResponse

func ValidateChatResponse(data []byte) error

ValidateChatResponse は非ストリーミングレスポンスの構造を検証

func ValidateErrorResponse

func ValidateErrorResponse(data []byte) (string, error)

ValidateErrorResponse はエラーレスポンスの構造を検証

func ValidateStreamResponse

func ValidateStreamResponse(data []byte) error

ValidateStreamResponse はストリーミングレスポンスの構造を検証

func ValidateToolCall

func ValidateToolCall(toolCall interface{}) error

ValidateToolCall はツール呼び出しレスポンスの構造を検証

func WebSearch

func WebSearch(query string) (string, error)

WebSearch は Serper API を使って Web 検索を実行し、上位5件の結果を返す

Types

type ChatRequest

type ChatRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Stream   bool      `json:"stream"`
}

ChatRequest はAPIリクエスト

type ChatResponse

type ChatResponse struct {
	Choices []Choice `json:"choices"`
}

ChatResponse は通常レスポンス

type Choice

type Choice struct {
	Message Message `json:"message"`
}

Choice は通常レスポンスの選択肢

type ClaudeCacheControl added in v0.31.0

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

ClaudeCacheControl 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 ClaudeContent

type ClaudeContent struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

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

type ClaudeContentPart added in v0.29.0

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

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

type ClaudeDelta

type ClaudeDelta struct {
	Type string `json:"type"`
	Text string `json:"text"`
}

ClaudeDelta はストリームの差分

type ClaudeImageSource added in v0.29.0

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

ClaudeImageSource は画像ソース

type ClaudeMessage

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

ClaudeMessage はClaudeのメッセージ構造

type ClaudeMultimodalMessage added in v0.29.0

type ClaudeMultimodalMessage struct {
	Role    string              `json:"role"`
	Content []ClaudeContentPart `json:"content"`
}

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

type ClaudeMultimodalRequest added in v0.29.0

type ClaudeMultimodalRequest struct {
	Model    string        `json:"model"`
	Messages []interface{} `json:"messages"` // ClaudeMessage or ClaudeMultimodalMessage
	// System can be either string (legacy) or []ClaudeSystemBlock (prompt caching).
	System    interface{} `json:"system,omitempty"`
	MaxTokens int         `json:"max_tokens"`
	Stream    bool        `json:"stream"`
}

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

type ClaudeProvider

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

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

func NewClaudeProvider

func NewClaudeProvider(apiKey string) *ClaudeProvider

NewClaudeProvider は新しいClaudeProviderを作成

func (*ClaudeProvider) ChatWithImage added in v0.29.0

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

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

func (*ClaudeProvider) ChatWithTools

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

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

func (*ClaudeProvider) Name

func (p *ClaudeProvider) Name() string

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

func (*ClaudeProvider) SupportsImages added in v0.29.0

func (p *ClaudeProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type ClaudeRequest

type ClaudeRequest struct {
	Model    string          `json:"model"`
	Messages []ClaudeMessage `json:"messages"`
	// System can be either string (legacy) or []ClaudeSystemBlock (prompt caching).
	System    interface{} `json:"system,omitempty"`
	MaxTokens int         `json:"max_tokens"`
	Stream    bool        `json:"stream"`
}

type ClaudeResponse

type ClaudeResponse struct {
	Content []ClaudeContent `json:"content"`
}

ClaudeResponse は通常レスポンス

type ClaudeStreamEvent

type ClaudeStreamEvent struct {
	Type  string      `json:"type"`
	Delta ClaudeDelta `json:"delta"`
}

ClaudeStreamEvent はストリームイベント

type ClaudeSystemBlock added in v0.31.0

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

ClaudeSystemBlock represents a system prompt content block.

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

type Client

type Client struct {
	Provider Provider
	Timeout  time.Duration
}

Client はLLM APIクライアント

func NewClient

func NewClient(provider Provider) *Client

NewClient は新しいClientを作成

func (*Client) ChatWithTools

func (c *Client) ChatWithTools(systemPrompt string, history []Message, model string) (string, error)

ChatWithTools はProviderに委譲

type DeepSeekProvider

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

DeepSeekProvider はDeepSeek APIのプロバイダー実装

func NewDeepSeekProvider

func NewDeepSeekProvider(apiKey string) *DeepSeekProvider

NewDeepSeekProvider は新しいDeepSeekProviderを作成

func (*DeepSeekProvider) ChatWithImage added in v0.29.0

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

ChatWithImage は画像付きメッセージで会話を行う(非対応:テキストのみ送信)

func (*DeepSeekProvider) ChatWithTools

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

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

func (*DeepSeekProvider) Name

func (p *DeepSeekProvider) Name() string

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

func (*DeepSeekProvider) SupportsImages added in v0.29.0

func (p *DeepSeekProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type Delta

type Delta struct {
	Content string `json:"content"`
}

Delta はストリームレスポンスの差分

type GeminiCandidate

type GeminiCandidate struct {
	Content GeminiContent `json:"content"`
}

GeminiCandidate はレスポンスの候補

type GeminiContent

type GeminiContent struct {
	Parts []GeminiPart `json:"parts"`
	Role  string       `json:"role,omitempty"` // "user" or "model"
}

GeminiContent はGeminiの contents 構造

type GeminiInlineData added in v0.29.0

type GeminiInlineData struct {
	MimeType string `json:"mime_type"` // "image/png", "image/jpeg" etc
	Data     string `json:"data"`      // Base64エンコードされたデータ
}

GeminiInlineData は画像データ

type GeminiMultimodalContent added in v0.29.0

type GeminiMultimodalContent struct {
	Parts []GeminiMultimodalPart `json:"parts"`
	Role  string                 `json:"role,omitempty"` // "user" or "model"
}

GeminiMultimodalContent はマルチモーダル対応のcontents構造

type GeminiMultimodalPart added in v0.29.0

type GeminiMultimodalPart struct {
	Text       string            `json:"text,omitempty"`
	InlineData *GeminiInlineData `json:"inline_data,omitempty"`
}

GeminiMultimodalPart はマルチモーダル対応のparts構造

type GeminiMultimodalRequest added in v0.29.0

type GeminiMultimodalRequest struct {
	Contents []interface{} `json:"contents"` // GeminiContent or GeminiMultimodalContent
}

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

type GeminiPart

type GeminiPart struct {
	Text string `json:"text"`
}

GeminiPart はGeminiの parts 構造(テキストのみ)

type GeminiProvider

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

GeminiProvider はGemini APIのプロバイダー実装

func NewGeminiProvider

func NewGeminiProvider(apiKey string) *GeminiProvider

NewGeminiProvider は新しいGeminiProviderを作成

func (*GeminiProvider) ChatWithImage added in v0.29.0

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

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

func (*GeminiProvider) ChatWithTools

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

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

func (*GeminiProvider) Name

func (p *GeminiProvider) Name() string

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

func (*GeminiProvider) SupportsImages added in v0.29.0

func (p *GeminiProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type GeminiRequest

type GeminiRequest struct {
	Contents []GeminiContent `json:"contents"`
}

GeminiRequest はGemini APIリクエスト

type GeminiResponse

type GeminiResponse struct {
	Candidates []GeminiCandidate `json:"candidates"`
}

GeminiResponse はGeminiレスポンス

type GroqProvider

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

GroqProvider はGroq APIのプロバイダー実装(OpenAI互換)

func NewGroqProvider

func NewGroqProvider(apiKey string) *GroqProvider

NewGroqProvider は新しいGroqProviderを作成

func (*GroqProvider) ChatWithImage added in v0.29.0

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

ChatWithImage は画像付きメッセージで会話を行う(非対応:テキストのみ送信)

func (*GroqProvider) ChatWithTools

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

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

func (*GroqProvider) Name

func (p *GroqProvider) Name() string

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

func (*GroqProvider) SupportsImages added in v0.29.0

func (p *GroqProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type ImageData added in v0.29.0

type ImageData struct {
	Path      string // 元のファイルパス
	MediaType string // "image/png", "image/jpeg" 等
	Base64    string // Base64エンコードされた画像データ
	Size      int64  // ファイルサイズ(バイト)
}

ImageData は画像データを表す

func LoadImage added in v0.29.0

func LoadImage(path string) (*ImageData, error)

LoadImage は画像ファイルを読み込んでBase64エンコードする

type Message

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

Message はチャットメッセージ(provider.goで定義されているが、ここでも使用)

type MultimodalMessage added in v0.29.0

type MultimodalMessage struct {
	Role    string     `json:"role"`
	Content string     `json:"content"`
	Image   *ImageData `json:"-"` // JSON保存しない(一時的なもの)
}

MultimodalMessage は画像を含むメッセージ

func (MultimodalMessage) HasImage added in v0.29.0

func (m MultimodalMessage) HasImage() bool

HasImage は画像が添付されているか

func (MultimodalMessage) ToMessage added in v0.29.0

func (m MultimodalMessage) ToMessage() Message

ToMessage は通常のMessageに変換(画像なし)

type OllamaMessageContent

type OllamaMessageContent struct {
	Content string `json:"content"`
}

OllamaMessageContent はOllamaのメッセージコンテンツ

type OllamaModel

type OllamaModel struct {
	Name string `json:"name"`
}

OllamaModel はモデル情報

type OllamaProvider

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

OllamaProvider はOllama APIのプロバイダー実装

func NewOllamaProvider

func NewOllamaProvider(baseURL string) *OllamaProvider

NewOllamaProvider は新しいOllamaProviderを作成

func (*OllamaProvider) ChatWithImage added in v0.29.0

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

ChatWithImage は画像付きメッセージで会話を行う(非対応:テキストのみ送信)

func (*OllamaProvider) ChatWithTools

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

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

func (*OllamaProvider) ListModels

func (p *OllamaProvider) ListModels() ([]string, error)

ListModels はインストール済みモデルを取得

func (*OllamaProvider) Name

func (p *OllamaProvider) Name() string

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

func (*OllamaProvider) SupportsImages added in v0.29.0

func (p *OllamaProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type OllamaRequest

type OllamaRequest struct {
	Model    string    `json:"model"`
	Messages []Message `json:"messages"`
	Stream   bool      `json:"stream"`
}

OllamaRequest はOllama APIリクエスト

type OllamaStreamResponse

type OllamaStreamResponse struct {
	Message OllamaMessageContent `json:"message"`
	Done    bool                 `json:"done"`
}

OllamaStreamResponse はOllamaのストリームレスポンス

type OllamaTagsResponse

type OllamaTagsResponse struct {
	Models []OllamaModel `json:"models"`
}

OllamaTagsResponse はモデル一覧のレスポンス

type OpenAIContentPart added in v0.29.0

type OpenAIContentPart struct {
	Type     string          `json:"type"`                // "text" or "image_url"
	Text     string          `json:"text,omitempty"`      // type="text"の場合
	ImageURL *OpenAIImageURL `json:"image_url,omitempty"` // type="image_url"の場合
}

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

type OpenAIImageURL added in v0.29.0

type OpenAIImageURL struct {
	URL string `json:"url"` // "data:image/png;base64,..." 形式
}

OpenAIImageURL は画像URL

type OpenAIMultimodalMessage added in v0.29.0

type OpenAIMultimodalMessage struct {
	Role    string              `json:"role"`
	Content []OpenAIContentPart `json:"content"`
}

OpenAIMultimodalMessage はマルチモーダルメッセージ

type OpenAIMultimodalRequest added in v0.29.0

type OpenAIMultimodalRequest struct {
	Model    string        `json:"model"`
	Messages []interface{} `json:"messages"` // Message or OpenAIMultimodalMessage
	Stream   bool          `json:"stream"`
}

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

type OpenAIProvider

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

OpenAIProvider はOpenAI APIのプロバイダー実装

func NewOpenAIProvider

func NewOpenAIProvider(apiKey string) *OpenAIProvider

NewOpenAIProvider は新しいOpenAIProviderを作成

func (*OpenAIProvider) ChatWithImage added in v0.29.0

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

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

func (*OpenAIProvider) ChatWithTools

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

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

func (*OpenAIProvider) Name

func (p *OpenAIProvider) Name() string

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

func (*OpenAIProvider) SupportsImages added in v0.29.0

func (p *OpenAIProvider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type Provider

type Provider interface {
	// Name はプロバイダー名を返す
	Name() string

	// ChatWithTools はツール対応の会話を行う(ストリーミング)
	ChatWithTools(ctx context.Context, systemPrompt string, history []Message, model string) (string, error)

	// SupportsImages はプロバイダーが画像入力に対応しているかを返す
	SupportsImages() bool

	// ChatWithImage は画像付きメッセージで会話を行う
	// imageがnilまたはプロバイダーが画像非対応の場合、テキストのみで会話する
	ChatWithImage(ctx context.Context, systemPrompt string, history []Message, userMessage string, image *ImageData, model string) (string, error)
}

Provider はLLMプロバイダーの共通インターフェース

func NewProvider added in v0.29.0

func NewProvider(providerName string) (Provider, error)

NewProvider はプロバイダー名から Provider インスタンスを生成

type RAGRequest

type RAGRequest struct {
	Query  string `json:"query"`
	UserID string `json:"user_id"`
	Model  string `json:"model"`
	TopK   int    `json:"top_k"`
}

type RAGResponse

type RAGResponse struct {
	Results []RAGResult `json:"results"`
	Query   string      `json:"query"`
	Count   int         `json:"count"`
}

func SearchRAG

func SearchRAG(query string, userID string, topK int) (*RAGResponse, error)

type RAGResult

type RAGResult struct {
	ID            string  `json:"id"`
	Content       string  `json:"content"`
	DocumentID    string  `json:"document_id"`
	DocumentTitle string  `json:"document_title"`
	DocumentType  string  `json:"document_type"`
	Similarity    float64 `json:"similarity"`
}

type SerperResponse

type SerperResponse struct {
	Organic []SerperSearchResult `json:"organic"`
}

SerperResponse は Serper API のレスポンス構造

type SerperSearchRequest

type SerperSearchRequest struct {
	Q  string `json:"q"`
	Gl string `json:"gl,omitempty"` // 地域コード (optional)
	Hl string `json:"hl,omitempty"` // 言語コード (optional)
}

SerperSearchRequest は Serper API へのリクエスト構造

type SerperSearchResult

type SerperSearchResult struct {
	Title   string `json:"title"`
	Link    string `json:"link"`
	Snippet string `json:"snippet"`
}

SerperSearchResult は検索結果の1件

type StreamChoice

type StreamChoice struct {
	Delta Delta `json:"delta"`
}

StreamChoice はストリームの選択肢

type StreamParser

type StreamParser func(line string) (content string, done bool, err error)

StreamParser はストリーミングレスポンスの1行をパースする関数型 戻り値: (content string, done bool, err error)

  • content: この行から抽出されたテキストコンテンツ
  • done: ストリームの終了を示すフラグ
  • err: パースエラー

type StreamResponse

type StreamResponse struct {
	Choices []StreamChoice `json:"choices"`
}

StreamResponse はストリームレスポンス

Jump to

Keyboard shortcuts

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