Documentation
¶
Overview ¶
Package session saves chats, so they can be resumed: one JSONL file per chat under ~/.docsgpt/sessions/<cwd slug>-<cwd hash>/, a header line and then the messages as they complete (pi's format, without its tree: a fork is a new file starting with a copy of the messages it keeps).
Index ¶
- func Dir(cwd string) string
- type Entry
- type Session
- func (s *Session) Delete() error
- func (s *Session) Fork(turn int) *Session
- func (s *Session) Record(server, key, conversationID string, msgs ...Entry) error
- func (s *Session) Saved() bool
- func (s *Session) SetName(name string) error
- func (s *Session) Title() string
- func (s *Session) Turns() []Turn
- func (s *Session) Usage() (last, total docsgpt.Usage)
- type Turn
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
Type string `json:"type"`
Time time.Time `json:"time"`
ID string `json:"id,omitempty"` // header
Cwd string `json:"cwd,omitempty"` // header
Parent string `json:"parent,omitempty"` // header: the file this chat was forked from
Name string `json:"name,omitempty"` // name
Server string `json:"server,omitempty"` // header, state
Key string `json:"key,omitempty"` // header, state
ConversationID string `json:"conversation_id,omitempty"` // header, state
Message *docsgpt.Message `json:"message,omitempty"`
Text string `json:"text,omitempty"` // what the user typed; Message adds the context
// Attachments are the files a user message carried: their paths and
// hashes, not their bytes, which the server keeps.
Attachments []attach.File `json:"attachments,omitempty"`
Sources []docsgpt.Source `json:"sources,omitempty"`
Usage *docsgpt.Usage `json:"usage,omitempty"` // an exchange's last message: the tokens it took
// contains filtered or unexported fields
}
Entry is one line of a session file: the "session" header first, then "message" lines, "state" lines (the server, key or server conversation changed) and "name" lines (the chat was named, or the name cleared).
type Session ¶
type Session struct {
Path string
Cwd string
Name string // given with /name; "" for none
Parent string // the file this chat was forked from
Server string // the latest
Key string // the latest
ConversationID string // the latest
Created time.Time
Updated time.Time
Messages []Entry // the "message" entries, in order
// contains filtered or unexported fields
}
Session is one saved chat.
func (*Session) Fork ¶
Fork starts a new session holding a copy of the exchanges before turn (counted from 0), so the chat can go on from there while this one stays as it is. Its file is written with its first record.
func (*Session) Record ¶
Record appends messages, noting first whether the server, the key or the server conversation changed. The first call writes the header (and what a fork copies).
func (*Session) SetName ¶
SetName names the chat, "" clearing the name. A chat not saved yet writes it with its first record.
type Turn ¶
type Turn struct {
Question string
Files []attach.File // attached to the question
Answer string // the assistant's texts of the exchange, joined
Sources []docsgpt.Source
Usage *docsgpt.Usage // nil when the server reported none
// Where the exchange took place: the server, the key and the server
// conversation ("" when the server named none), and the exchange's
// index in that conversation.
Server, Key, ConversationID string
Index int
}
Turn is one exchange: what the user typed and the answer.