Documentation ¶
Index ¶
- Constants
- func ByteToString(b [][]byte) []string
- func ChunkFile(fs afero.Fs, path string, chunkSize int, maxChunks int, ...) error
- func ChunkFromReader(reader io.Reader, chunkSize int, maxChunks int, ...) error
- func ForEachSubdir(fs afero.Fs, path string, callback func(path string) error) error
- func GetChunks(reader io.Reader, chunkSize int, maxChunks int) ([][]byte, error)
- func GetFileChunks(ctx context.Context, fs afero.Fs, path string, chunkSize int, maxChunks int) ([][]byte, error)
- func HistoryBlocksToString(blocks []HistoryBlock) string
- func InitLogging(ctx context.Context) string
- func IsPipedStdin() bool
- func Min(a, b int) int
- func MultilineLipglossRender(style lipgloss.Style, str string) string
- type CacheWriter
- type ColorWriter
- type CompletionRequest
- type CompletionResponse
- type FunctionCall
- type FunctionDefinition
- type HistoryBlock
- type ReplaceWriter
- type StripbackticksWriter
- type StyleCodeblocksWriter
- func (this *StyleCodeblocksWriter) EndOfCodeBlock(w io.Writer) error
- func (this *StyleCodeblocksWriter) EndOfCodeLine(w io.Writer) error
- func (this *StyleCodeblocksWriter) Reset()
- func (this *StyleCodeblocksWriter) SetTerminalWidth(width int)
- func (this *StyleCodeblocksWriter) Write(p []byte) (n int, err error)
- type StyledWriter
- type ToolCall
- type ToolDefinition
Constants ¶
const ( STATE_NORMAL = iota STATE_NEWLINE STATE_ONE_TICK STATE_TWO_TICKS STATE_THREE_TICKS STATE_BLOCK STATE_BLOCK_NEWLINE STATE_BLOCK_ONE_TICK STATE_BLOCK_TWO_TICKS STATE_BLOCK_THREE_TICKS STATE_INLINE )
Variables ¶
This section is empty.
Functions ¶
func ByteToString ¶
Cast an array of byte arrays to an array of strings
func ChunkFile ¶
func ChunkFile( fs afero.Fs, path string, chunkSize int, maxChunks int, callback func(int, []byte) error) error
Read a file, break into chunks of a given number of bytes, up to a maximum number of chunks, and call the callback for each chunk
func ChunkFromReader ¶
func ForEachSubdir ¶
Call a callback for each subdirectory in a given path
func GetFileChunks ¶
func GetFileChunks(ctx context.Context, fs afero.Fs, path string, chunkSize int, maxChunks int) ([][]byte, error)
Given a filesystem, a path, a chunk size, and maximum number of chunks, return a list of chunks of the file at the given path
func HistoryBlocksToString ¶ added in v0.0.20
func HistoryBlocksToString(blocks []HistoryBlock) string
func InitLogging ¶ added in v0.2.4
Open a log file named butterfish.log in a temporary directory
func IsPipedStdin ¶
func IsPipedStdin() bool
Returns true if there is piped stdin data that can be read
func MultilineLipglossRender ¶
Lipgloss is a little tricky - if you render a string with newlines it turns it into a "block", i.e. each line will be padding to be the same length. This is not what we want, so we split on newlines and render each line separately.
Types ¶
type CacheWriter ¶
type CacheWriter struct {
// contains filtered or unexported fields
}
A io.Writer that caches bytes written and forwards writes to another writer
func NewCacheWriter ¶
func NewCacheWriter(forward io.Writer) *CacheWriter
func (*CacheWriter) GetCache ¶
func (this *CacheWriter) GetCache() []byte
func (*CacheWriter) GetLastN ¶
func (this *CacheWriter) GetLastN(n int) []byte
type ColorWriter ¶ added in v0.0.27
func NewColorWriter ¶ added in v0.0.27
func NewColorWriter(writer io.Writer, color string) *ColorWriter
type CompletionRequest ¶
type CompletionRequest struct { Ctx context.Context Prompt string Model string MaxTokens int Temperature float32 HistoryBlocks []HistoryBlock SystemMessage string Functions []FunctionDefinition Tools []ToolDefinition Verbose bool TokenTimeout time.Duration }
We define types for calling LLM APIs here because I don't want the internal interfaces to depend on OpenAI-specific types.
type CompletionResponse ¶ added in v0.1.4
type FunctionCall ¶ added in v0.2.5
type FunctionDefinition ¶ added in v0.1.4
type FunctionDefinition struct { Name string `json:"name"` Description string `json:"description,omitempty"` Parameters jsonschema.Definition `json:"parameters"` }
type HistoryBlock ¶ added in v0.0.20
type HistoryBlock struct { Type int Content string FunctionName string FunctionParams string ToolCalls []*ToolCall ToolCallId string }
func (HistoryBlock) String ¶ added in v0.0.20
func (this HistoryBlock) String() string
type ReplaceWriter ¶ added in v0.0.20
A Writer implementation that allows you to string replace the content flowing through
func NewReplaceWriter ¶ added in v0.0.20
func NewReplaceWriter(writer io.Writer, from string, to string) *ReplaceWriter
type StripbackticksWriter ¶ added in v0.2.4
func NewStripbackticksWriter ¶ added in v0.2.4
func NewStripbackticksWriter(writer io.Writer) *StripbackticksWriter
type StyleCodeblocksWriter ¶ added in v0.2.4
func NewStyleCodeblocksWriter ¶ added in v0.2.4
func (*StyleCodeblocksWriter) EndOfCodeBlock ¶ added in v0.2.4
func (this *StyleCodeblocksWriter) EndOfCodeBlock(w io.Writer) error
func (*StyleCodeblocksWriter) EndOfCodeLine ¶ added in v0.2.4
func (this *StyleCodeblocksWriter) EndOfCodeLine(w io.Writer) error
func (*StyleCodeblocksWriter) Reset ¶ added in v0.2.9
func (this *StyleCodeblocksWriter) Reset()
func (*StyleCodeblocksWriter) SetTerminalWidth ¶ added in v0.2.4
func (this *StyleCodeblocksWriter) SetTerminalWidth(width int)
func (*StyleCodeblocksWriter) Write ¶ added in v0.2.4
func (this *StyleCodeblocksWriter) Write(p []byte) (n int, err error)
This writer receives bytes in a stream and looks for markdown code blocks (```) and renders them with syntax highlighting. The hard part is the stream splits the input into chunks, so we need to buffer the input in places.
type StyledWriter ¶
type StyledWriter struct { Writer io.Writer Style lipgloss.Style // contains filtered or unexported fields }
An implementation of io.Writer that renders output with a lipgloss style and filters out the special token "NOOP". This is specially handled - we seem to get "NO" as a separate token from GPT.
func NewStyledWriter ¶
func NewStyledWriter(writer io.Writer, style lipgloss.Style) *StyledWriter
type ToolCall ¶ added in v0.2.5
type ToolCall struct { Id string Type string Function FunctionCall }
type ToolDefinition ¶ added in v0.2.5
type ToolDefinition struct { Type string `json:"type"` Function FunctionDefinition `json:"function"` }