Documentation
¶
Index ¶
- Constants
- func NewOpenaiProvider(opts ...types.ProviderOption) (types.Provider, error)
- type AudioFormatType
- type ClientEventConversationItemCreate
- type ClientEventInputAudioBufferAppend
- type ClientEventResponseCreate
- type ClientEventSessionUpdate
- type ClientEventSessionUpdateSession
- type ClientEventSessionUpdateSessionAudio
- type ClientEventSessionUpdateSessionAudioInput
- type ClientEventSessionUpdateSessionAudioInputTurnDetection
- type ClientEventSessionUpdateSessionAudioOutput
- type ClientEventSessionUpdateSessionToolFunctions
- type ClientSession
- type ClientTurnDetectionType
- type CompletionChoise
- type CompletionMessage
- type CompletionMessageParam
- type CompletionReq
- type CompletionReqExtra
- type CompletionReqStreamOptions
- type CompletionRsp
- type CompletionTokenDetail
- type CompletionToolCall
- type CompletionToolCallFunction
- type CompletionUsage
- type EmbeddingReq
- type EmbeddingRsp
- type EmbeddingRspData
- type Event
- type EventBase
- type EventPayload
- type EventType
- type Modality
- type OpenaiProvider
- func (p *OpenaiProvider) Completion(ctx context.Context, model string, messages []*types.Message, ...) (*types.Completion, error)
- func (p *OpenaiProvider) Embedding(ctx context.Context, model string, input []string, ...) (*types.Embedding, error)
- func (p *OpenaiProvider) Realtime(ctx context.Context, model string, messages []*types.Message, ...) (types.RealTimeSession, error)
- type RealTimeContent
- type RealTimeItem
- type ReasoningEffort
- type Role
- type ServerEventResponseDone
- type ServerEventResponseDoneResponse
- type ServerEventResponseFunctionCallArgumentsDone
- type ServerEventResponseOutputAudioDelta
- type ServerTurnDetectionType
- type Tool
- type ToolFunction
- type ToolType
- type Voice
Constants ¶
View Source
const ( CompletionModelDefault = openai.ChatModelGPT5_4 CompletionPath = "/chat/completions" )
View Source
const (
DefaultBaseUrl = "https://api.openai.com/v1"
)
View Source
const (
DefaultRealTimeModel = "gpt-4o-realtime-preview"
)
View Source
const (
EmbeddingPath = "/embeddings"
)
Variables ¶
This section is empty.
Functions ¶
func NewOpenaiProvider ¶
func NewOpenaiProvider(opts ...types.ProviderOption) (types.Provider, error)
Types ¶
type AudioFormatType ¶
type AudioFormatType string
const ( AudioFormatTypePcm16 AudioFormatType = "audio/pcm" AudioFormatTypeG711Ulaw AudioFormatType = "audio/pcmu" AudioFormatTypeG711Alaw AudioFormatType = "audio/pcma" )
type ClientEventConversationItemCreate ¶
type ClientEventConversationItemCreate struct {
EventBase
PreviousItemId string `json:"previous_item_id,omitempty"`
Item RealTimeItem `json:"item,omitempty"`
}
func NewClientEventConversationItemCreate ¶
func NewClientEventConversationItemCreate() *ClientEventConversationItemCreate
type ClientEventInputAudioBufferAppend ¶
func NewClientEventInputAudioBufferAppend ¶
func NewClientEventInputAudioBufferAppend() *ClientEventInputAudioBufferAppend
type ClientEventResponseCreate ¶
type ClientEventResponseCreate struct {
EventBase
}
func NewClientEventResponseCreate ¶
func NewClientEventResponseCreate() *ClientEventResponseCreate
type ClientEventSessionUpdate ¶
type ClientEventSessionUpdate struct {
EventBase
Session ClientEventSessionUpdateSession `json:"session"`
}
func CreateSessionUpdateEvent ¶
func CreateSessionUpdateEvent(model string, opts *types.RealTimeOptions) (*ClientEventSessionUpdate, error)
func NewClientEventSessionUpdate ¶
func NewClientEventSessionUpdate() *ClientEventSessionUpdate
type ClientEventSessionUpdateSession ¶
type ClientEventSessionUpdateSession struct {
Type string `json:"type"` //realtime,transcription
Model string `json:"model,omitempty"`
Instructions string `json:"instructions,omitempty"`
OutputModalities []Modality `json:"output_modalities,omitempty"`
Tools []*ClientEventSessionUpdateSessionToolFunctions `json:"tools,omitempty"`
Audio *ClientEventSessionUpdateSessionAudio `json:"audio,omitempty"`
}
type ClientEventSessionUpdateSessionAudio ¶
type ClientEventSessionUpdateSessionAudio struct {
Input *ClientEventSessionUpdateSessionAudioInput `json:"input,omitempty"`
Output *ClientEventSessionUpdateSessionAudioOutput `json:"output,omitempty"`
}
type ClientEventSessionUpdateSessionAudioInput ¶
type ClientEventSessionUpdateSessionAudioInput struct {
TurnDetection *ClientEventSessionUpdateSessionAudioInputTurnDetection `json:"turn_detection,omitempty"`
}
type ClientEventSessionUpdateSessionAudioInputTurnDetection ¶
type ClientEventSessionUpdateSessionAudioInputTurnDetection struct {
Type ClientTurnDetectionType `json:"type"` //server_vad or semantic_vad
CreateResponse bool `json:"create_response"`
InterruptResponse bool `json:"interrupt_response"`
}
type ClientEventSessionUpdateSessionAudioOutput ¶
type ClientEventSessionUpdateSessionAudioOutput struct {
Voice Voice `json:"voice"`
}
type ClientSession ¶
type ClientSession struct {
// contains filtered or unexported fields
}
func (*ClientSession) Close ¶
func (r *ClientSession) Close()
func (*ClientSession) Recv ¶
func (r *ClientSession) Recv(ctx context.Context) (*types.Completion, error)
type ClientTurnDetectionType ¶
type ClientTurnDetectionType string
const ( ClientTurnDetectionTypeServerVad ClientTurnDetectionType = "server_vad" ClientTurnDetectionTypeSemanticVad ClientTurnDetectionType = "semantic_vad" )
type CompletionChoise ¶
type CompletionChoise struct {
Index int `json:"index"`
FinishReason string `json:"finish_reason"`
Delta *CompletionMessage `json:"delta"`
Message *CompletionMessage `json:"message"`
}
type CompletionMessage ¶
type CompletionMessage struct {
ReasoningContent string `json:"reasoning_content"`
Content string `json:"content"`
Refusal string `json:"refusal"`
ToolCalls []CompletionToolCall `json:"tool_calls"`
}
type CompletionMessageParam ¶
type CompletionMessageParam struct {
Role string `json:"role"`
Content string `json:"content,omitempty"`
ReasoningContent string `json:"reasoning_content,omitempty"`
Refusal string `json:"refusal,omitempty"`
ToolCalls []*CompletionToolCall `json:"tool_calls,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
}
type CompletionReq ¶
type CompletionReq struct {
Model string `json:"model,omitempty"`
Messages []*CompletionMessageParam `json:"messages,omitempty"`
Stream bool `json:"stream,omitempty"`
StreamOptions *CompletionReqStreamOptions `json:"stream_options,omitempty"`
Tools []*Tool `json:"tools,omitempty"`
Temperature *float32 `json:"temperature,omitempty"`
TopP *float32 `json:"top_p,omitempty"`
MaxTokens *int64 `json:"max_tokens,omitempty"`
MaxCompletionTokens *int64 `json:"max_completion_tokens,omitempty"`
Stop []string `json:"stop,omitempty"`
ReasoningEffort *ReasoningEffort `json:"reasoning_effort,omitempty"`
ExtraBody map[string]any `json:"-"`
}
func (*CompletionReq) MarshalJSON ¶
func (c *CompletionReq) MarshalJSON() ([]byte, error)
type CompletionReqExtra ¶
type CompletionReqStreamOptions ¶
type CompletionReqStreamOptions struct {
IncludeUsage bool `json:"include_usage"`
}
type CompletionRsp ¶
type CompletionRsp struct {
ID string `json:"id,omitempty"`
Object string `json:"object,omitempty"`
Created int64 `json:"created,omitempty"`
Model string `json:"model,omitempty"`
SystemFingerprint string `json:"system_fingerprint,omitempty"`
Choices []*CompletionChoise `json:"choices,omitempty"`
Usage CompletionUsage `json:"usage,omitempty"`
}
type CompletionTokenDetail ¶
type CompletionToolCall ¶
type CompletionToolCall struct {
Index int `json:"index"`
ID string `json:"id"`
Type ToolType `json:"type"` // function, custom
Function *CompletionToolCallFunction `json:"function"`
}
type CompletionUsage ¶
type CompletionUsage struct {
CompletionTokens int64 `json:"completion_tokens"`
PromptTokens int64 `json:"prompt_tokens"`
TotalTokens int64 `json:"total_tokens"`
TokenDetail CompletionTokenDetail `json:"completion_tokens_details"`
}
type EmbeddingReq ¶
type EmbeddingRsp ¶
type EmbeddingRsp struct {
Model string `json:"model"`
Data []*EmbeddingRspData `json:"data"`
Usage CompletionUsage `json:"usage"`
Object string `json:"object"`
Message string `json:"message"`
}
type EmbeddingRspData ¶
type Event ¶
type Event struct {
EventBase
EventPayload
}
func (Event) MarshalJSON ¶
func (*Event) UnmarshalJSON ¶
type EventPayload ¶
type EventType ¶
type EventType string
var ( ClientEventTypeSessionUpdate EventType = "session.update" ClientEventTypeConversationItemCreate EventType = "conversation.item.create" ClientEventTypeInputAudioBufferAppend EventType = "input_audio_buffer.append" ClientEventTypeResponseCreate EventType = "response.create" ServerEventTypeResponseOutputAudioDelta EventType = "response.output_audio.delta" ServerEventTypeResponseFunctionCallArgumentsDone EventType = "response.function_call_arguments.done" ServerEventTypeResponseDone EventType = "response.done" )
type OpenaiProvider ¶
type OpenaiProvider struct {
types.ProviderNop
// contains filtered or unexported fields
}
func (*OpenaiProvider) Completion ¶
func (p *OpenaiProvider) Completion(ctx context.Context, model string, messages []*types.Message, options ...types.CompletionOption) (*types.Completion, error)
func (*OpenaiProvider) Embedding ¶
func (p *OpenaiProvider) Embedding(ctx context.Context, model string, input []string, options ...types.EmbeddingOption) (*types.Embedding, error)
func (*OpenaiProvider) Realtime ¶
func (p *OpenaiProvider) Realtime(ctx context.Context, model string, messages []*types.Message, options ...types.RealTimeOption) (types.RealTimeSession, error)
type RealTimeContent ¶
type RealTimeContent struct {
Type string `json:"type,omitempty"` //input_text, input_audio, input_image, output_text, output_audio
//text
Text string `json:"text,omitempty"`
//audio
Audio string `json:"audio,omitempty"`
Transcript string `json:"transcript,omitempty"`
//image
ImageUrl string `json:"image_url,omitempty"`
Detail string `json:"detail,omitempty"`
}
type RealTimeItem ¶
type RealTimeItem struct {
Role string `json:"role,omitempty"`
Type string `json:"type,omitempty"` //message,function_call,function_call_output
ID string `json:"id,omitempty"`
//message
Content []*RealTimeContent `json:"content,omitempty"`
//function_call
CallID string `json:"call_id,omitempty"`
Name string `json:"name,omitempty"`
Arguments string `json:"arguments,omitempty"`
//function_call_output
Output string `json:"output,omitempty"`
}
type ReasoningEffort ¶
type ReasoningEffort string
const ( ReasoningEffortNone ReasoningEffort = "none" ReasoningEffortMinimal ReasoningEffort = "minimal" ReasoningEffortLow ReasoningEffort = "low" ReasoningEffortMedium ReasoningEffort = "medium" ReasoningEffortHigh ReasoningEffort = "high" ReasoningEffortXhigh ReasoningEffort = "xhigh" )
type ServerEventResponseDone ¶
type ServerEventResponseDone struct {
EventBase
ID string `json:"id"`
Response ServerEventResponseDoneResponse `json:"response"`
}
type ServerEventResponseDoneResponse ¶
type ServerEventResponseDoneResponse struct {
ConversationId string `json:"conversation_id"`
Status string `json:"status"`
Output []*RealTimeItem `json:"ouput"`
}
type ServerTurnDetectionType ¶
type ServerTurnDetectionType string
const ( ServerTurnDetectionTypeNone ServerTurnDetectionType = "none" ServerTurnDetectionTypeServerVad ServerTurnDetectionType = "server_vad" ServerTurnDetectionTypeSemanticVad ServerTurnDetectionType = "semantic_vad" )
type Tool ¶
type Tool struct {
Type ToolType `json:"type"`
Function *ToolFunction `json:"function"`
}
type ToolFunction ¶
type Voice ¶
type Voice string
const ( VoiceNone Voice = "" VoiceAlloy Voice = "alloy" VoiceAsh Voice = "ash" VoiceBallad Voice = "ballad" VoiceCoral Voice = "coral" VoiceEcho Voice = "echo" VoiceFable Voice = "fable" VoiceOnyx Voice = "onyx" VoiceNova Voice = "nova" VoiceSage Voice = "sage" VoiceShimmer Voice = "shimmer" VoiceVerse Voice = "verse" )
Click to show internal directories.
Click to hide internal directories.