chat

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2024 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	LEFT_HALF_CIRCLE  string = string(0xe0b6)
	RIGHT_HALF_CIRCLE string = string(0xe0b4)
	BORDER_TOP_LEFT   string = string(0x256d)
	BORDER_TOP_RIGHT  string = string(0x256e)
	BORDER_HORIZONTAL string = string(0x2500)
)
View Source
var DisabledHighlightStyle = lipgloss.NewStyle().
	Foreground(gray).
	Bold(true)
View Source
var HighlightActiveStyle = lipgloss.NewStyle().
	Background(teal).
	Foreground(black).
	Bold(true).
	Padding(0, 1)
View Source
var HighlightForegroundStyle = lipgloss.NewStyle().
	Foreground(purple).
	Bold(true)
View Source
var HighlightStyle = lipgloss.NewStyle().
	Background(purple).
	Bold(true).
	Padding(0, 1)
View Source
var Keys = KeyMap{
	Up: key.NewBinding(
		key.WithKeys("ctrl+up", "k"),
		key.WithHelp("ctrl+↑", "Move view up"),
	),
	Down: key.NewBinding(
		key.WithKeys("ctrl+down", "j"),
		key.WithHelp("ctrl+↓", "Move view down"),
	),
	HalfPageUp: key.NewBinding(
		key.WithKeys("ctrl+u"),
		key.WithHelp("ctrl+u", "Half page up"),
	),
	HalfPageDown: key.NewBinding(
		key.WithKeys("ctrl+d"),
		key.WithHelp("ctrl+d", "Half page down"),
	),
	HighlightPreviousMessage: key.NewBinding(
		key.WithKeys("ctrl+p"),
		key.WithHelp("ctrl+p", "Previous message"),
	),
	HighlightNextMessage: key.NewBinding(
		key.WithKeys("ctrl+n"),
		key.WithHelp("ctrl+n", "Next message"),
	),
	CopyLastResponse: key.NewBinding(
		key.WithKeys("ctrl+y"),
		key.WithHelp("ctrl+y", "Copy last response"),
	),
	CopyHighlightedMessage: key.NewBinding(
		key.WithKeys("alt+y"),
		key.WithHelp("alt+y", "Copy highlighted message"),
	),
	ToggleImagePicker: key.NewBinding(
		key.WithKeys("ctrl+o"),
		key.WithHelp("ctrl+o", "Toggle image picker"),
	),
	RemoveAttachment: key.NewBinding(
		key.WithKeys("ctrl+x"),
		key.WithHelp("ctrl+x", "Remove attachment"),
	),
	ToggleHelp: key.NewBinding(
		key.WithKeys("ctrl+h"),
		key.WithHelp("ctrl+h", "Toggle help"),
	),
	Quit: key.NewBinding(
		key.WithKeys("ctrl+c"),
		key.WithHelp("ctrl+c", "Exit chat"),
	),
}
View Source
var NotificationStyle = lipgloss.NewStyle().
	Background(notif).
	Foreground(black).
	Bold(true).
	Padding(0, 1)
View Source
var RoundedBorder = lipgloss.NewStyle().
	BorderStyle(lipgloss.RoundedBorder())

Functions

func CenterString

func CenterString(str string, width int, color lipgloss.Color) string

Helper function to center a string within a given width (top rounded border)

func DecodeGob

func DecodeGob(r io.Reader, messages *[]ChatMessage) error

Decodes the gob-encoded messages from the reader and stores them in the provided messages slice

func EncodeGob

func EncodeGob(w io.Writer, messages *[]ChatMessage) error

Encodes the provided messages to gob format and writes it to the writer

func GenerateChatID

func GenerateChatID() string

Generates a unique chat ID using the UUID Version 4 algorithm

func NewChatSettingsForm

func NewChatSettingsForm() (client.Chat, error)

Huh form for creating a new chat, returns the new chat settings TODO: add more Ollama settings and sliders (temperature, max tokens, etc.)

Types

type Chat

type Chat struct {
	Glamour *glamour.TermRenderer

	ChatHistory  []ChatMessage
	ChatSettings client.Chat
	// contains filtered or unexported fields
}

func NewChat

func NewChat(chatSettings client.Chat) *Chat

Creates a new Chat instance with the provided chat settings Loads the chat history from the database if it exists Sets up the chat's viewport, prompt form, and image picker Sets default values for the chat settings if they don't exist

func (*Chat) CopyToClipboard added in v0.1.11

func (chat *Chat) CopyToClipboard(content string, copyType CopyType) tea.Cmd

Helper function to copy the provided content to the clipboard Shows a notification with the copied content

func (*Chat) ImagePickerView

func (m *Chat) ImagePickerView() string

func (*Chat) Init

func (chat *Chat) Init() tea.Cmd

Initializes the chat by resetting the prompt and image picker Sets the chat's width and height based on the terminal size (initial)

func (*Chat) Resize

func (chat *Chat) Resize() tea.Cmd

Resizes the chat's viewport and prompt form based on the chat's width

func (*Chat) Update

func (chat *Chat) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (*Chat) View

func (chat *Chat) View() string

type ChatMessage

type ChatMessage struct {
	CreatedAt time.Time
	Role      string
	Message   string
	Images    []string
}

type ContentType

type ContentType string

type CopyType added in v0.1.11

type CopyType string
const (
	CopyLastResponse CopyType = "CopyLastResponse"
	CopyHighlighted  CopyType = "CopyHighlighted"
)

type FinishedStreaming

type FinishedStreaming bool

type KeyMap added in v0.1.11

type KeyMap struct {
	Up                       key.Binding // ctrl+up
	Down                     key.Binding // ctrl+down
	HalfPageUp               key.Binding // ctrl+u
	HalfPageDown             key.Binding // ctrl+d
	HighlightPreviousMessage key.Binding // ctrl+p
	HighlightNextMessage     key.Binding // ctrl+n
	CopyHighlightedMessage   key.Binding // alt+c
	CopyLastResponse         key.Binding // ctrl+shift+c
	ToggleImagePicker        key.Binding // ctrl+o
	RemoveAttachment         key.Binding // ctrl+x
	ToggleHelp               key.Binding // ctrl+h
	Quit                     key.Binding // ctrl+c
	FullHelpKeys             [][]key.Binding
}

func (*KeyMap) DefaultFullHelpKeys added in v0.1.11

func (k *KeyMap) DefaultFullHelpKeys() [][]key.Binding

func (*KeyMap) DefaultFullHelpKeysNonMultiModal added in v1.0.0

func (k *KeyMap) DefaultFullHelpKeysNonMultiModal() [][]key.Binding

func (KeyMap) FullHelp added in v0.1.11

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

FullHelp returns keybindings for the expanded help view. It's part of the key.Map interface.

func (*KeyMap) SetFullHelpKeys added in v0.1.11

func (k *KeyMap) SetFullHelpKeys(keys [][]key.Binding)

func (KeyMap) ShortHelp added in v0.1.11

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

ShortHelp returns keybindings to be shown in the mini help view. It's part of the key.Map interface.

type StreamChunk

type StreamChunk string

type Type

type Type string

Jump to

Keyboard shortcuts

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