api

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 ParseStreamingResponse

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

ParseStreamingResponse は共通のストリーミングレスポンス処理 コンテキストキャンセル、スピナー制御、エラーハンドリングを統一的に処理

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 ClaudeContent

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

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

type ClaudeDelta

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

ClaudeDelta はストリームの差分

type ClaudeMessage

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

ClaudeMessage はClaudeのメッセージ構造

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) 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 はプロバイダー名を返す

type ClaudeRequest

type ClaudeRequest struct {
	Model     string          `json:"model"`
	Messages  []ClaudeMessage `json:"messages"`
	System    string          `json:"system,omitempty"`
	MaxTokens int             `json:"max_tokens"`
	Stream    bool            `json:"stream"`
}

ClaudeRequest はClaude APIリクエスト

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 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) 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 はプロバイダー名を返す

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 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) 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 はプロバイダー名を返す

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) 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 はプロバイダー名を返す

type Message

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

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

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) 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 はプロバイダー名を返す

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 OpenAIProvider

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

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

func NewOpenAIProvider

func NewOpenAIProvider(apiKey string) *OpenAIProvider

NewOpenAIProvider は新しいOpenAIProviderを作成

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 はプロバイダー名を返す

type Provider

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

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

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

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