openai

package
v0.4.32 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2025 License: MIT Imports: 24 Imported by: 4

Documentation

Index

Constants

View Source
const MetadataToolsSlug = "tools"

Variables

This section is empty.

Functions

func ExtractChatCompletionMetadata added in v0.4.26

func ExtractChatCompletionMetadata(response *openai.ChatCompletionStreamResponse) (map[string]interface{}, error)

ExtractChatCompletionMetadata extracts metadata from an OpenAI chat completion stream response

func GetToolCallString added in v0.4.13

func GetToolCallString(toolCalls []go_openai.ToolCall) string

func IsOpenAiEngine

func IsOpenAiEngine(engine string) bool

Types

type ChatCompletionMetadata added in v0.4.26

type ChatCompletionMetadata struct {
	Model             string              `json:"model" mapstructure:"model"`
	SystemFingerprint string              `json:"system_fingerprint" mapstructure:"system_fingerprint"`
	PromptAnnotations []PromptAnnotation  `json:"prompt_annotations,omitempty" mapstructure:"prompt_annotations,omitempty"`
	Usage             *Usage              `json:"usage,omitempty" mapstructure:"usage,omitempty"`
	ContentFilters    []ContentFilterData `json:"content_filters,omitempty" mapstructure:"content_filters,omitempty"`
}

ChatCompletionMetadata contains metadata extracted from OpenAI chat completion stream responses

type ChatExecuteToolStep added in v0.4.13

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

ChatExecuteToolStep combines a chat step with a tool execution step.

func NewChatToolStep added in v0.4.1

func NewChatToolStep(stepSettings *settings.StepSettings, options ...ChatToolStepOption) (*ChatExecuteToolStep, error)

func (*ChatExecuteToolStep) AddPublishedTopic added in v0.4.13

func (t *ChatExecuteToolStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*ChatExecuteToolStep) Start added in v0.4.13

type ChatStep added in v0.4.13

type ChatStep struct {
	Settings *settings.StepSettings
	// contains filtered or unexported fields
}

func NewStep added in v0.2.24

func NewStep(settings *settings.StepSettings, options ...StepOption) (*ChatStep, error)

func (*ChatStep) AddPublishedTopic added in v0.4.13

func (csf *ChatStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*ChatStep) Start added in v0.4.13

type ChatToolStepOption added in v0.4.1

type ChatToolStepOption func(step *ChatExecuteToolStep)

func WithReflector added in v0.4.1

func WithReflector(reflector *jsonschema.Reflector) ChatToolStepOption

WithReflector sets the JSON schema reflector for the step.

func WithToolFunctions added in v0.4.1

func WithToolFunctions(toolFunctions map[string]interface{}) ChatToolStepOption

WithToolFunctions sets the tool functions for the step. The schema is derived from these functions using the reflector.

type ChatWithToolsStep added in v0.4.13

type ChatWithToolsStep struct {
	Settings *settings.StepSettings
	Tools    []go_openai.Tool
	// contains filtered or unexported fields
}

ChatWithToolsStep is actually just like ChatStep, except that it also accumulates tool calls.

func NewChatWithToolsStep added in v0.4.13

func NewChatWithToolsStep(
	stepSettings *settings.StepSettings,
	Tools []go_openai.Tool,
	options ...ToolStepOption,
) (*ChatWithToolsStep, error)

func (*ChatWithToolsStep) AddPublishedTopic added in v0.4.13

func (r *ChatWithToolsStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*ChatWithToolsStep) SetStreaming added in v0.4.13

func (csf *ChatWithToolsStep) SetStreaming(b bool)

NOTE(manuel, 2024-06-04) I think this can be removed

func (*ChatWithToolsStep) Start added in v0.4.13

type ClientOption added in v0.4.32

type ClientOption func(*TranscriptionClient)

func WithLanguage added in v0.4.32

func WithLanguage(language string) ClientOption

func WithModel added in v0.4.32

func WithModel(model string) ClientOption

func WithPrompt added in v0.4.32

func WithPrompt(prompt string) ClientOption

func WithTemperature added in v0.4.32

func WithTemperature(temperature float32) ClientOption

type CompletionTokenDetails added in v0.4.26

type CompletionTokenDetails struct {
	AudioTokens     int `json:"audio_tokens" mapstructure:"audio_tokens"`
	ReasoningTokens int `json:"reasoning_tokens" mapstructure:"reasoning_tokens"`
}

CompletionTokenDetails contains detailed information about completion tokens

type ContentFilterData added in v0.4.26

type ContentFilterData struct {
	Index                int                  `json:"index" mapstructure:"index"`
	ContentFilterResults ContentFilterResults `json:"content_filter_results" mapstructure:"content_filter_results"`
}

ContentFilterData contains content filter results

type ContentFilterResults added in v0.4.26

type ContentFilterResults struct {
	Hate      *FilterResult `json:"hate,omitempty" mapstructure:"hate,omitempty"`
	SelfHarm  *FilterResult `json:"self_harm,omitempty" mapstructure:"self_harm,omitempty"`
	Sexual    *FilterResult `json:"sexual,omitempty" mapstructure:"sexual,omitempty"`
	Violence  *FilterResult `json:"violence,omitempty" mapstructure:"violence,omitempty"`
	JailBreak *FilterResult `json:"jailbreak,omitempty" mapstructure:"jailbreak,omitempty"`
	Profanity *FilterResult `json:"profanity,omitempty" mapstructure:"profanity,omitempty"`
}

ContentFilterResults contains individual content filter results

type ExecuteToolStep added in v0.2.24

type ExecuteToolStep struct {
	Tools map[string]interface{}
	// contains filtered or unexported fields
}

TODO(manuel, 2024-07-04) Make this use the chat.ToolCall and chat.ToolResult structs and make it generic

func NewExecuteToolStep added in v0.4.1

func NewExecuteToolStep(
	tools map[string]interface{},
	options ...ExecuteToolStepOption,
) (*ExecuteToolStep, error)

func (*ExecuteToolStep) AddPublishedTopic added in v0.4.1

func (e *ExecuteToolStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*ExecuteToolStep) Start added in v0.2.24

type ExecuteToolStepOption added in v0.4.1

type ExecuteToolStepOption func(*ExecuteToolStep) error

func WithExecuteToolStepMessageID added in v0.4.1

func WithExecuteToolStepMessageID(messageID conversation.NodeID) ExecuteToolStepOption

func WithExecuteToolStepParentID added in v0.4.1

func WithExecuteToolStepParentID(parentID conversation.NodeID) ExecuteToolStepOption

func WithExecuteToolStepSubscriptionManager added in v0.4.1

func WithExecuteToolStepSubscriptionManager(subscriptionManager *events.PublisherManager) ExecuteToolStepOption

type FilterResult added in v0.4.26

type FilterResult struct {
	Filtered bool   `json:"filtered" mapstructure:"filtered"`
	Severity string `json:"severity,omitempty" mapstructure:"severity,omitempty"`
	Detected bool   `json:"detected,omitempty" mapstructure:"detected,omitempty"`
}

FilterResult represents a single content filter result

type ProgressInfo added in v0.4.32

type ProgressInfo struct {
	BytesProcessed    int64
	TotalBytes        int64
	PercentComplete   float64
	CurrentSpeaker    *SpeakerInfo
	ElapsedTime       time.Duration
	EstimatedTimeLeft time.Duration
}

type PromptAnnotation added in v0.4.26

type PromptAnnotation struct {
	PromptIndex          int                  `json:"prompt_index" mapstructure:"prompt_index"`
	ContentFilterResults ContentFilterResults `json:"content_filter_results" mapstructure:"content_filter_results"`
}

PromptAnnotation represents an annotation for a prompt

type PromptTokenDetails added in v0.4.26

type PromptTokenDetails struct {
	AudioTokens  int `json:"audio_tokens" mapstructure:"audio_tokens"`
	CachedTokens int `json:"cached_tokens" mapstructure:"cached_tokens"`
}

PromptTokenDetails contains detailed information about prompt tokens

type SpeakerInfo added in v0.4.32

type SpeakerInfo struct {
	ID       string
	Duration float64
}

type StepOption added in v0.4.1

type StepOption func(*ChatStep) error

func WithSubscriptionManager added in v0.4.1

func WithSubscriptionManager(subscriptionManager *events.PublisherManager) StepOption

type StreamingTranscription added in v0.4.32

type StreamingTranscription struct {
	File      string  `json:"file"`
	Text      string  `json:"text"`
	Timestamp float64 `json:"timestamp"`
	IsFinal   bool    `json:"is_final"`
	Error     error   `json:"error,omitempty"`
}

type ToolCallMerger added in v0.2.24

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

func NewToolCallMerger added in v0.2.24

func NewToolCallMerger() *ToolCallMerger

func (*ToolCallMerger) AddToolCalls added in v0.2.24

func (tcm *ToolCallMerger) AddToolCalls(toolCalls []go_openai.ToolCall)

func (*ToolCallMerger) GetToolCalls added in v0.2.24

func (tcm *ToolCallMerger) GetToolCalls() []go_openai.ToolCall

type ToolCompletionResponse added in v0.2.24

type ToolCompletionResponse struct {
	Role      string               `json:"role"`
	Content   string               `json:"content"`
	ToolCalls []go_openai.ToolCall `json:"tool_calls"`
}

type ToolStepOption added in v0.4.1

type ToolStepOption func(*ChatWithToolsStep) error

func WithChatWithToolsStepMessageID added in v0.4.13

func WithChatWithToolsStepMessageID(messageID conversation.NodeID) ToolStepOption

func WithChatWithToolsStepParentID added in v0.4.13

func WithChatWithToolsStepParentID(parentID conversation.NodeID) ToolStepOption

func WithChatWithToolsStepSubscriptionManager added in v0.4.13

func WithChatWithToolsStepSubscriptionManager(subscriptionManager *events.PublisherManager) ToolStepOption

type Transcription added in v0.2.18

type Transcription struct {
	File     string                `json:"file"`
	Response *openai.AudioResponse `json:"response"`
	Error    error                 `json:"error,omitempty"`
}

type TranscriptionClient added in v0.2.18

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

func NewTranscriptionClient added in v0.2.18

func NewTranscriptionClient(apiKey string, opts ...ClientOption) *TranscriptionClient

func (*TranscriptionClient) TranscribeFile added in v0.2.18

func (tc *TranscriptionClient) TranscribeFile(ctx context.Context, mp3FilePath string, opts ...TranscriptionOption) (*Transcription, error)

func (*TranscriptionClient) TranscribeFileStreaming added in v0.4.32

func (tc *TranscriptionClient) TranscribeFileStreaming(ctx context.Context, mp3FilePath string, opts ...TranscriptionOption) (<-chan StreamingTranscription, error)

type TranscriptionMode added in v0.4.32

type TranscriptionMode string
const (
	TranscriptionModeBlocking TranscriptionMode = "blocking"
	TranscriptionModeStream   TranscriptionMode = "stream"
)

type TranscriptionOption added in v0.4.32

type TranscriptionOption func(*TranscriptionOptions)

func WithChunkSize added in v0.4.32

func WithChunkSize(size int) TranscriptionOption

func WithConcurrentChunks added in v0.4.32

func WithConcurrentChunks(n int) TranscriptionOption

func WithCooldownPeriod added in v0.4.32

func WithCooldownPeriod(period time.Duration) TranscriptionOption

func WithDetailedProgress added in v0.4.32

func WithDetailedProgress(callback func(ProgressInfo)) TranscriptionOption

func WithErrorCallback added in v0.4.32

func WithErrorCallback(callback func(error)) TranscriptionOption

func WithFailFast added in v0.4.32

func WithFailFast(failFast bool) TranscriptionOption

func WithJSONFormat added in v0.4.32

func WithJSONFormat() TranscriptionOption

func WithMaxDuration added in v0.4.32

func WithMaxDuration(seconds float64) TranscriptionOption

func WithMaxRetries added in v0.4.32

func WithMaxRetries(retries int) TranscriptionOption

func WithMinRequestGap added in v0.4.32

func WithMinRequestGap(gap time.Duration) TranscriptionOption

func WithMusicCallback added in v0.4.32

func WithMusicCallback(callback func(startTime, endTime float64)) TranscriptionOption

func WithNoiseCallback added in v0.4.32

func WithNoiseCallback(callback func(startTime, endTime float64, level float64)) TranscriptionOption

func WithProfanity added in v0.4.32

func WithProfanity() TranscriptionOption

func WithProgressCallback added in v0.4.32

func WithProgressCallback(callback func(float64)) TranscriptionOption

func WithQuality added in v0.4.32

func WithQuality(quality float32) TranscriptionOption

func WithRequestsPerMinute added in v0.4.32

func WithRequestsPerMinute(rpm int) TranscriptionOption

func WithRetryDelay added in v0.4.32

func WithRetryDelay(delay time.Duration) TranscriptionOption

func WithSRTFormat added in v0.4.32

func WithSRTFormat() TranscriptionOption

func WithSegmentTimestamps added in v0.4.32

func WithSegmentTimestamps() TranscriptionOption

func WithSilenceCallback added in v0.4.32

func WithSilenceCallback(callback func(duration float64)) TranscriptionOption

func WithSpeakerChangeCallback added in v0.4.32

func WithSpeakerChangeCallback(callback func(oldSpeaker, newSpeaker string)) TranscriptionOption

func WithSpeakerDiarization added in v0.4.32

func WithSpeakerDiarization() TranscriptionOption

func WithSpeakerLimits added in v0.4.32

func WithSpeakerLimits(min_ int, max_ int) TranscriptionOption

func WithStartTime added in v0.4.32

func WithStartTime(seconds float64) TranscriptionOption

func WithTextFormat added in v0.4.32

func WithTextFormat() TranscriptionOption

func WithVTTFormat added in v0.4.32

func WithVTTFormat() TranscriptionOption

func WithVerboseJSONFormat added in v0.4.32

func WithVerboseJSONFormat() TranscriptionOption

func WithWordTimestamps added in v0.4.32

func WithWordTimestamps() TranscriptionOption

type TranscriptionOptions added in v0.4.32

type TranscriptionOptions struct {
	TimestampGranularities []openai.TranscriptionTimestampGranularity
	ChunkSize              int // For streaming mode
	ProgressCallback       func(float64)
	Format                 openai.AudioResponseFormat

	// File Processing Options
	MaxDuration float64 // Maximum duration in seconds to process
	StartTime   float64 // Start processing from this timestamp (in seconds)

	// Quality and Performance Options
	Quality          float32 // 0.0 = fastest/lowest quality, 1.0 = slowest/highest quality
	ConcurrentChunks int     // Number of concurrent chunks to process in streaming mode

	// Output Formatting Options
	EnableSpeakerDiarization bool // Include speaker diarization
	MinSpeakers              int  // Minimum number of speakers to detect
	MaxSpeakers              int  // Maximum number of speakers to detect
	AllowProfanity           bool // Include profanity in output

	// Advanced Callback Options
	OnSpeakerChange          func(oldSpeaker, newSpeaker string)
	OnSilence                func(duration float64)
	OnMusic                  func(startTime, endTime float64)
	OnNoise                  func(startTime, endTime float64, level float64)
	DetailedProgressCallback func(ProgressInfo)

	// Error Handling Options
	MaxRetries    int           // Maximum number of retries for failed chunks
	RetryDelay    time.Duration // Delay between retries
	FailFast      bool          // Stop on first error
	ErrorCallback func(error)   // Called when an error occurs

	// Rate Limiting Options
	RequestsPerMinute int           // Maximum requests per minute
	MinRequestGap     time.Duration // Minimum time between requests
	CooldownPeriod    time.Duration // Time to wait when rate limit is hit
}

type Usage added in v0.4.26

type Usage struct {
	PromptTokens      int                     `json:"prompt_tokens" mapstructure:"prompt_tokens"`
	CompletionTokens  int                     `json:"completion_tokens" mapstructure:"completion_tokens"`
	TotalTokens       int                     `json:"total_tokens" mapstructure:"total_tokens"`
	PromptDetails     *PromptTokenDetails     `json:"prompt_details,omitempty" mapstructure:"prompt_details,omitempty"`
	CompletionDetails *CompletionTokenDetails `json:"completion_details,omitempty" mapstructure:"completion_details,omitempty"`
}

Usage represents token usage information

Jump to

Keyboard shortcuts

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