chat

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: MIT Imports: 18 Imported by: 4

Documentation

Index

Constants

View Source
const RoleAssistant = "assistant"
View Source
const RoleSystem = "system"
View Source
const RoleTool = "tool"
View Source
const RoleUser = "user"

Variables

View Source
var DefaultKeyMap = KeyMap{
	SelectPrevMessage: key.NewBinding(
		key.WithKeys("up"),
		key.WithHelp("↑", "move up")),
	SelectNextMessage: key.NewBinding(
		key.WithKeys("down"),
		key.WithHelp("↓", "move down"),
	),

	UnfocusMessage: key.NewBinding(
		key.WithKeys("esc", "ctrl+g"),
		key.WithHelp("esc", "unfocus message"),
	),
	FocusMessage: key.NewBinding(
		key.WithKeys("enter"),
		key.WithHelp("enter", "focus message"),
	),

	SubmitMessage: key.NewBinding(
		key.WithKeys("tab"),
		key.WithHelp("tab", "submit message"),
	),
	CancelCompletion: key.NewBinding(
		key.WithKeys("esc", "ctrl+g"),
		key.WithHelp("esc", "cancel completion"),
	),

	DismissError: key.NewBinding(
		key.WithKeys("esc", "ctrl+g"),
		key.WithHelp("esc", "dismiss error"),
	),

	SaveToFile: key.NewBinding(
		key.WithKeys("ctrl+s"),
		key.WithHelp("ctrl+s", "save to file"),
	),
	SaveSourceBlocksToFile: key.NewBinding(
		key.WithKeys("alt+s"),
		key.WithHelp("alt+s", "save source"),
	),

	CopyToClipboard: key.NewBinding(
		key.WithKeys("alt+c"),
		key.WithHelp("alt+c", "copy selected"),
	),
	CopyLastResponseToClipboard: key.NewBinding(
		key.WithKeys("alt+l"),
		key.WithHelp("alt+l", "copy response"),
	),
	CopySourceBlocksToClipboard: key.NewBinding(
		key.WithKeys("alt+d"),
		key.WithHelp("alt+d", "copy selected source"),
	),

	ScrollUp: key.NewBinding(
		key.WithKeys("shift+pgup"),
		key.WithHelp("shift+pgup", "scroll up"),
	),
	ScrollDown: key.NewBinding(
		key.WithKeys("shift+pgdown"),
		key.WithHelp("shift+pgdown", "scroll down"),
	),

	Quit: key.NewBinding(
		key.WithKeys("alt+q"),
		key.WithHelp("alt+q", "quit"),
	),

	Help: key.NewBinding(
		key.WithKeys("ctrl-?"),
		key.WithHelp("ctrl-?", "help")),

	PreviousConversationThread: key.NewBinding(
		key.WithKeys("left"),
		key.WithHelp("left", "previous conversation thread"),
	),

	NextConversationThread: key.NewBinding(
		key.WithKeys("right"),
		key.WithHelp("right", "next conversation thread"),
	),
}

Functions

func InitialModel

func InitialModel(manager ConversationManager, backend Backend) model

func OpenTTY

func OpenTTY() (io.ReadWriteCloser, error)

Types

type Backend

type Backend interface {
	Interrupt()
	Kill()
	GetNextCompletion() tea.Cmd
	Start(ctx context.Context, msgs []*Message) error
	IsFinished() bool
}

type BorderColors

type BorderColors struct {
	Unselected string
	Selected   string
	Focused    string
}

type ConversationManager

type ConversationManager interface {
	GetMessages() []*Message
	GetMessagesWithSystemPrompt() []*Message

	AddMessages(msgs ...*Message)
	SaveToFile(filename string) error
}

type KeyMap

type KeyMap struct {
	SelectPrevMessage key.Binding `keymap-mode:"moving-around"`
	SelectNextMessage key.Binding `keymap-mode:"moving-around"`
	UnfocusMessage    key.Binding `keymap-mode:"user-input"`
	FocusMessage      key.Binding `keymap-mode:"moving-around"`

	SubmitMessage key.Binding `keymap-mode:"user-input"`
	ScrollUp      key.Binding
	ScrollDown    key.Binding

	CancelCompletion key.Binding `keymap-mode:"stream-completion"`
	DismissError     key.Binding `keymap-mode:"error"`

	LoadFromFile key.Binding

	Regenerate         key.Binding `keymap-mode:"user-input"`
	RegenerateFromHere key.Binding `keymap-mode:"moving-around"`
	EditMessage        key.Binding `keymap-mode:"moving-around"`

	PreviousConversationThread key.Binding `keymap-mode:"moving-around"`
	NextConversationThread     key.Binding `keymap-mode:"moving-around"`

	SaveToFile             key.Binding `keymap-mode:"*"`
	SaveSourceBlocksToFile key.Binding `keymap-mode:"*"`

	CopyToClipboard             key.Binding `keymap-mode:"moving-around"`
	CopyLastResponseToClipboard key.Binding `keymap-mode:"user-input"`
	CopySourceBlocksToClipboard key.Binding `keymap-mode:"moving-around"`

	Help key.Binding `keymap-mode:"*"`
	Quit key.Binding `keymap-mode:"*"`
}

func (KeyMap) FullHelp

func (k KeyMap) FullHelp() [][]key.Binding

func (KeyMap) ShortHelp

func (k KeyMap) ShortHelp() []key.Binding

type Message

type Message struct {
	Text string    `json:"text" yaml:"text"`
	Time time.Time `json:"time" yaml:"time"`
	Role string    `json:"role" yaml:"role"`

	ID             uuid.UUID `json:"id" yaml:"id"`
	ParentID       uuid.UUID `json:"parent_id" yaml:"parent_id"`
	ConversationID uuid.UUID `json:"conversation_id" yaml:"conversation_id"`

	// additional metadata for the message
	Metadata map[string]interface{} `json:"metadata,omitempty" yaml:"metadata,omitempty"`
}

type State

type State string
const (
	StateUserInput        State = "user-input"
	StateMovingAround     State = "moving-around"
	StateStreamCompletion State = "stream-completion"
	StateError            State = "error"
)

type StreamCompletionError

type StreamCompletionError struct {
	Err error
}

type StreamCompletionMsg

type StreamCompletionMsg struct {
	Completion string
}

type StreamDoneMsg

type StreamDoneMsg struct {
}

type Style

type Style struct {
	UnselectedMessage lipgloss.Style
	SelectedMessage   lipgloss.Style
	FocusedMessage    lipgloss.Style
}

func DefaultStyles

func DefaultStyles() *Style

Jump to

Keyboard shortcuts

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