openai

package
v0.4.26 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 22 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 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 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 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 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"`
	// contains filtered or unexported fields
}

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, model, prompt, language string, temperature float32) *TranscriptionClient

func (*TranscriptionClient) TranscribeFile added in v0.2.18

func (tc *TranscriptionClient) TranscribeFile(mp3FilePath string, out chan<- Transcription, wg *sync.WaitGroup)

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