openai

package
v0.44.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertHistoryToInputItems

func ConvertHistoryToInputItems(history []api.Message) []api.InputItem

ConvertHistoryToInputItems は api.ConvertHistoryToInputItems のエイリアス

func ConvertToolCallToToolJSON added in v0.44.0

func ConvertToolCallToToolJSON(tc *api.OpenAIToolCall) (string, error)

ConvertToolCallToToolJSON は OpenAI tool_call を内部JSON形式に変換 Returns: {"id": "call_xxx", "tool": "read_file", "args": {"path": "/path/to/file"}}

func GetCombinedOpenAITools added in v0.44.0

func GetCombinedOpenAITools(mcpTools []api.OpenAIToolFunction) []api.OpenAITool

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

func GetOpenAIToolDefinitions added in v0.44.0

func GetOpenAIToolDefinitions() []api.OpenAITool

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

func GetToolDefinitionNames added in v0.44.0

func GetToolDefinitionNames() []string

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

func LevelToReasoningEffort

func LevelToReasoningEffort(level string) string

LevelToReasoningEffort は Thinking Level を OpenAI reasoning_effort に変換

Types

type CompactRequest

type CompactRequest struct {
	Model        string          `json:"model"`
	Input        []api.InputItem `json:"input"` // フル会話ウィンドウ
	Instructions string          `json:"instructions,omitempty"`
}

CompactRequest は /responses/compact リクエスト

type CompactResponse

type CompactResponse = api.CompactResponse

CompactResponse は api.CompactResponse のエイリアス

type ContentPart

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

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

type ImageURL

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

ImageURL は画像URL

type InputContentPart

type InputContentPart = api.InputContentPart

InputContentPart は api.InputContentPart のエイリアス(api packageで定義)

type InputItem

type InputItem = api.InputItem

InputItem は api.InputItem のエイリアス(api packageで定義)

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
	Stream          bool          `json:"stream"`
	ReasoningEffort string        `json:"reasoning_effort,omitempty"` // low/medium/high
}

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

type Provider

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

Provider はOpenAI 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) ClearResponseID added in v0.43.0

func (p *Provider) ClearResponseID()

ClearResponseID は responseID をクリアする(圧縮後などに使用)

func (*Provider) CompactHistory

func (p *Provider) CompactHistory(ctx context.Context, input []api.InputItem, model, instructions string) (*CompactResponse, error)

CompactHistory は会話履歴を Compact API で圧縮

func (*Provider) HasCachedResponseID added in v0.43.0

func (p *Provider) HasCachedResponseID() bool

HasCachedResponseID は Responses API のキャッシュ済み responseID があるか返す

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 ツール定義を設定する(Function Calling用)

func (*Provider) SupportsCompact

func (p *Provider) SupportsCompact() bool

SupportsCompact は Compact API 対応を返す

func (*Provider) SupportsImages

func (p *Provider) SupportsImages() bool

SupportsImages は画像入力対応を返す

type ReasoningConfig

type ReasoningConfig struct {
	Effort string `json:"effort"` // none, low, medium, high(omitempty削除で明示的に送信)
}

ReasoningConfig は OpenAI Extended Thinking の設定

type ResponseMetadata

type ResponseMetadata struct {
	ID     string `json:"id"`               // "resp_xxx..."
	Status string `json:"status,omitempty"` // "in_progress", "completed"
	Model  string `json:"model,omitempty"`
}

ResponseMetadata はレスポンスメタデータ(response.created イベント用)

type ResponsesItem added in v0.44.0

type ResponsesItem struct {
	Type      string `json:"type,omitempty"`      // "function_call"
	Name      string `json:"name,omitempty"`      // ツール名
	CallID    string `json:"call_id,omitempty"`   // 呼び出しID
	Arguments string `json:"arguments,omitempty"` // 完了時の引数(response.function_call_arguments.done)
}

ResponsesItem は output_item のデータ(function_call 等)

type ResponsesRequest

type ResponsesRequest struct {
	Model              string           `json:"model"`
	Input              interface{}      `json:"input,omitempty"`                // string or []InputItem(previous_response_id使用時は省略可)
	PreviousResponseID string           `json:"previous_response_id,omitempty"` // 前回のレスポンスID(キャッシュ用)
	Instructions       string           `json:"instructions,omitempty"`         // システムプロンプト
	Stream             bool             `json:"stream,omitempty"`
	Reasoning          *ReasoningConfig `json:"reasoning,omitempty"` // Extended Thinking
	Tools              []ResponsesTool  `json:"tools,omitempty"`     // ツール定義
}

ResponsesRequest は Responses API リクエスト

type ResponsesResult

type ResponsesResult struct {
	Content    string // テキストコンテンツ
	ResponseID string // レスポンスID(response.created から取得)
}

ResponsesResult は Responses API のレスポンス結果(ID付き)

type ResponsesStreamChunk

type ResponsesStreamChunk struct {
	Type     string            `json:"type"`               // "response.output_text.delta", "response.created", etc.
	Delta    string            `json:"delta,omitempty"`    // テキスト差分
	Response *ResponseMetadata `json:"response,omitempty"` // response.created で取得
	Item     *ResponsesItem    `json:"item,omitempty"`     // response.output_item.added で取得(function_call用)
}

ResponsesStreamChunk は Responses API ストリーミングチャンク

type ResponsesTool added in v0.44.0

type ResponsesTool struct {
	Type        string                 `json:"type"`                  // "function"
	Name        string                 `json:"name"`                  // ツール名
	Description string                 `json:"description,omitempty"` // ツールの説明
	Parameters  map[string]interface{} `json:"parameters,omitempty"`  // JSON Schema
	Strict      bool                   `json:"strict,omitempty"`      // Structured Output
}

ResponsesTool は Responses API 用のツール定義 Chat Completions API と異なり、"function" キーのネストが不要

func GetResponsesToolDefinitions added in v0.44.0

func GetResponsesToolDefinitions(mcpTools []api.OpenAIToolFunction) []ResponsesTool

GetResponsesToolDefinitions は Responses API 用のツール定義を返す Responses API は Chat Completions と異なりフラットな形式

Jump to

Keyboard shortcuts

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