chat

package
v0.4.33 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: 9

Documentation

Index

Constants

View Source
const MetadataToolCallsSlug = "tool-calls"

MetadataToolCallsSlug is the slug used to store ToolCall metadata as returned by the openai API TODO(manuel, 2024-07-04) This needs to deleted once we have a good way to do tool calling

Variables

This section is empty.

Functions

func NewStructuredPrinter added in v0.4.26

func NewStructuredPrinter(w io.Writer, options PrinterOptions) func(msg *message.Message) error

func StepPrinterFunc added in v0.4.1

func StepPrinterFunc(name string, w io.Writer) func(msg *message.Message) error

func ToTypedEvent added in v0.4.1

func ToTypedEvent[T any](e Event) (*T, bool)

Types

type AddToHistoryStep added in v0.2.24

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

func (*AddToHistoryStep) AddPublishedTopic added in v0.4.1

func (a *AddToHistoryStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*AddToHistoryStep) Start added in v0.2.24

type CacheEntry added in v0.4.30

type CacheEntry struct {
	Conversation conversation.Conversation `json:"messages"`
	Input        conversation.Conversation `json:"input"`
	Created      time.Time                 `json:"created"`
}

type CachingStep added in v0.4.30

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

func NewCachingStep added in v0.4.30

func NewCachingStep(step Step, opts ...Option) (*CachingStep, error)

func (*CachingStep) AddPublishedTopic added in v0.4.30

func (c *CachingStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*CachingStep) Start added in v0.4.30

type EchoStep added in v0.2.24

type EchoStep struct {
	TimePerCharacter time.Duration
	// contains filtered or unexported fields
}

func NewEchoStep added in v0.2.24

func NewEchoStep() *EchoStep

func (*EchoStep) AddPublishedTopic added in v0.4.1

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

func (*EchoStep) Interrupt added in v0.2.24

func (e *EchoStep) Interrupt()

func (*EchoStep) Start added in v0.2.24

type Event added in v0.2.24

type Event interface {
	Type() EventType
	Metadata() EventMetadata
	StepMetadata() *steps.StepMetadata
	Payload() []byte
}

func NewEventFromJson added in v0.4.1

func NewEventFromJson(b []byte) (Event, error)

type EventError added in v0.4.13

type EventError struct {
	EventImpl
	Error_ string `json:"error"`
}

func NewErrorEvent added in v0.4.13

func NewErrorEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, err string) *EventError

func (EventError) MarshalZerologObject added in v0.4.13

func (e EventError) MarshalZerologObject(ev *zerolog.Event)

type EventFinal added in v0.4.13

type EventFinal struct {
	EventImpl
	Text string `json:"text"`
}

func NewFinalEvent added in v0.4.13

func NewFinalEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, text string) *EventFinal

func (EventFinal) MarshalZerologObject added in v0.4.13

func (e EventFinal) MarshalZerologObject(ev *zerolog.Event)

type EventImpl added in v0.4.13

type EventImpl struct {
	Type_     EventType           `json:"type"`
	Error_    error               `json:"error,omitempty"`
	Metadata_ EventMetadata       `json:"meta,omitempty"`
	Step_     *steps.StepMetadata `json:"step,omitempty"`
	// contains filtered or unexported fields
}

func (*EventImpl) Error added in v0.4.13

func (e *EventImpl) Error() error

func (*EventImpl) MarshalZerologObject added in v0.4.13

func (e *EventImpl) MarshalZerologObject(ev *zerolog.Event)

func (*EventImpl) Metadata added in v0.4.13

func (e *EventImpl) Metadata() EventMetadata

func (*EventImpl) Payload added in v0.4.13

func (e *EventImpl) Payload() []byte

func (*EventImpl) StepMetadata added in v0.4.13

func (e *EventImpl) StepMetadata() *steps.StepMetadata

func (*EventImpl) ToPartialCompletion added in v0.4.13

func (e *EventImpl) ToPartialCompletion() (EventPartialCompletion, bool)

func (*EventImpl) ToText added in v0.4.13

func (e *EventImpl) ToText() (EventText, bool)

func (*EventImpl) ToToolCall added in v0.4.13

func (e *EventImpl) ToToolCall() (EventToolCall, bool)

func (*EventImpl) Type added in v0.4.13

func (e *EventImpl) Type() EventType

type EventInterrupt added in v0.4.13

type EventInterrupt struct {
	EventImpl
	Text string `json:"text"`
}

func NewInterruptEvent added in v0.4.13

func NewInterruptEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, text string) *EventInterrupt

func (EventInterrupt) MarshalZerologObject added in v0.4.13

func (e EventInterrupt) MarshalZerologObject(ev *zerolog.Event)

type EventMetadata added in v0.4.1

type EventMetadata struct {
	conversation.LLMMessageMetadata
	ID       conversation.NodeID `json:"message_id" yaml:"message_id" mapstructure:"message_id"`
	ParentID conversation.NodeID `json:"parent_id" yaml:"parent_id" mapstructure:"parent_id"`
}

EventMetadata contains all the information that is passed along with watermill message, specific to chat steps.

func (EventMetadata) MarshalZerologObject added in v0.4.13

func (em EventMetadata) MarshalZerologObject(e *zerolog.Event)

type EventPartialCompletion added in v0.4.1

type EventPartialCompletion struct {
	EventImpl
	Delta string `json:"delta"`
	// This is the complete completion string so far (when using openai, this is currently also the toolcall json)
	Completion string `json:"completion"`
}

EventPartialCompletion is the event type for textual partial completion. We don't support partial tool completion.

func NewPartialCompletionEvent added in v0.4.13

func NewPartialCompletionEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, delta string, completion string) *EventPartialCompletion

func (EventPartialCompletion) MarshalZerologObject added in v0.4.13

func (e EventPartialCompletion) MarshalZerologObject(ev *zerolog.Event)

type EventPartialCompletionStart added in v0.4.13

type EventPartialCompletionStart struct {
	EventImpl
}

func NewStartEvent added in v0.4.13

func NewStartEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata) *EventPartialCompletionStart

func (EventPartialCompletionStart) MarshalZerologObject added in v0.4.13

func (e EventPartialCompletionStart) MarshalZerologObject(ev *zerolog.Event)

type EventText added in v0.4.1

type EventText struct {
	EventImpl
	Text string `json:"text"`
}

TODO(manuel, 2024-07-05) This might be possible to delete

func NewTextEvent added in v0.4.13

func NewTextEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, text string) *EventText

func (EventText) MarshalZerologObject added in v0.4.13

func (e EventText) MarshalZerologObject(ev *zerolog.Event)

type EventToolCall added in v0.4.13

type EventToolCall struct {
	EventImpl
	ToolCall ToolCall `json:"tool_call"`
}

TODO(manuel, 2024-07-04) Handle multiple tool calls

func NewToolCallEvent added in v0.4.13

func NewToolCallEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, toolCall ToolCall) *EventToolCall

func (EventToolCall) MarshalZerologObject added in v0.4.13

func (e EventToolCall) MarshalZerologObject(ev *zerolog.Event)

type EventToolResult added in v0.4.13

type EventToolResult struct {
	EventImpl
	ToolResult ToolResult `json:"tool_result"`
}

func NewToolResultEvent added in v0.4.13

func NewToolResultEvent(metadata EventMetadata, stepMetadata *steps.StepMetadata, toolResult ToolResult) *EventToolResult

func (EventToolResult) MarshalZerologObject added in v0.4.13

func (e EventToolResult) MarshalZerologObject(ev *zerolog.Event)

type EventType added in v0.2.24

type EventType string
const (
	// EventTypeStart to EventTypeFinal are for text completion, actually
	EventTypeStart             EventType = "start"
	EventTypeFinal             EventType = "final"
	EventTypePartialCompletion EventType = "partial"

	// TODO(manuel, 2024-07-04) I'm not sure if this is needed
	EventTypeStatus EventType = "status"

	// TODO(manuel, 2024-07-04) Should potentially have a EventTypeText for a block stop here
	EventTypeToolCall   EventType = "tool-call"
	EventTypeToolResult EventType = "tool-result"
	EventTypeError      EventType = "error"
	EventTypeInterrupt  EventType = "interrupt"
)

type MemoryCacheEntry added in v0.4.30

type MemoryCacheEntry struct {
	Conversation conversation.Conversation
	Input        conversation.Conversation
	Created      time.Time
	// contains filtered or unexported fields
}

type MemoryCachingStep added in v0.4.30

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

func NewMemoryCachingStep added in v0.4.30

func NewMemoryCachingStep(step Step, opts ...MemoryOption) (*MemoryCachingStep, error)

func (*MemoryCachingStep) AddPublishedTopic added in v0.4.30

func (c *MemoryCachingStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*MemoryCachingStep) ClearCache added in v0.4.30

func (c *MemoryCachingStep) ClearCache()

func (*MemoryCachingStep) MaxSize added in v0.4.30

func (c *MemoryCachingStep) MaxSize() int

func (*MemoryCachingStep) Size added in v0.4.30

func (c *MemoryCachingStep) Size() int

func (*MemoryCachingStep) Start added in v0.4.30

type MemoryOption added in v0.4.30

type MemoryOption func(*MemoryCachingStep)

func WithMemoryMaxSize added in v0.4.30

func WithMemoryMaxSize(size int) MemoryOption

func WithMemorySubscriptionManager added in v0.4.33

func WithMemorySubscriptionManager(subscriptionManager *events.PublisherManager) MemoryOption

type MockStep added in v0.4.30

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

func NewMockStep added in v0.4.30

func NewMockStep(messages []*conversation.Message) *MockStep

func (*MockStep) AddPublishedTopic added in v0.4.30

func (s *MockStep) AddPublishedTopic(publisher message.Publisher, topic string) error

func (*MockStep) Start added in v0.4.30

type Option added in v0.4.30

type Option func(*CachingStep)

func WithCacheDirectory added in v0.4.30

func WithCacheDirectory(dir string) Option

func WithMaxEntries added in v0.4.30

func WithMaxEntries(count int) Option

func WithMaxSize added in v0.4.30

func WithMaxSize(size int64) Option

func WithSubscriptionManager added in v0.4.33

func WithSubscriptionManager(subscriptionManager *events.PublisherManager) Option

type PrinterFormat added in v0.4.26

type PrinterFormat string
const (
	FormatText PrinterFormat = "text"
	FormatJSON PrinterFormat = "json"
	FormatYAML PrinterFormat = "yaml"
)

type PrinterOptions added in v0.4.26

type PrinterOptions struct {
	// Format determines the output format (text, json, yaml)
	Format PrinterFormat
	// Name is the prefix to use for text output
	Name string
	// IncludeMetadata controls whether to include Event.Metadata() in output
	IncludeMetadata bool
	// Full controls whether to print all available metadata (overrides IncludeMetadata and IncludeStepMetadata)
	Full bool
}

type RunnableStep added in v0.2.24

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

func (*RunnableStep) AddPublishedTopic added in v0.4.1

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

func (*RunnableStep) Start added in v0.2.24

func (r *RunnableStep) Start(ctx context.Context, input interface{}) (steps.StepResult[*conversation.Message], error)

type StepOption added in v0.2.24

type StepOption func(Step) error

func WithPublishedTopic added in v0.4.5

func WithPublishedTopic(publisher message.Publisher, topic string) StepOption

type ToolCall added in v0.4.1

type ToolCall struct {
	ID    string `json:"id"`
	Name  string `json:"name"`
	Input string `json:"input"`
}

func (ToolCall) MarshalZerologObject added in v0.4.13

func (tc ToolCall) MarshalZerologObject(ev *zerolog.Event)

type ToolResult added in v0.4.13

type ToolResult struct {
	ID     string `json:"id"`
	Result string `json:"result"`
}

func (ToolResult) MarshalZerologObject added in v0.4.13

func (tr ToolResult) MarshalZerologObject(ev *zerolog.Event)

Jump to

Keyboard shortcuts

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