mods/messages.go
Carlos Alexandro Becker 4d10417748
feat: improve --continue, --show, auto-save, and added a db (#95)
* feat: improve --continue and auto-save

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: load from one file, save to another

* fix: last line of output being eaten

* feat: --show

Reimplemented #92 using over this branch as it had too many conflicts.

closes #92

* fix: mods with no args, mods --delete

* fix: continue should not save empty filename

* feat: --list show the beginning of the last prompt

* fix: do not write on show

* feat: use a sqlite db

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: no cgo

* fix: first line of the prompt only

* refactor: open db

* fix: --continue duplicating creating a new id

* refactor: improve cache code

* fix: crypto/rand instead of math's

* fix: close db on exit

* fix: style

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: added db_test.go

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: add cache_test.go

* test: add messages_test.go

* fix: use goreleaser-mods.yaml

* fix: line breaks

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* refactor: improvements

* fix: wrong import

* chore: missplaced commend

* refactor: improving main.go

* fix: auto-glamour

* fix: extra empty line

* test: cacheops

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: windows

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: stream output to stdout if ouput is not a terminal

also lazily cached the isatty and isaterm checks, using sync.OnceValue.

PS: this will disable the loading indicator when the output is not a
term.

* fix: std db name

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* wip: render

* fix: first char and last line

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: rename

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: donestate

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: dep

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: quiet

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: saving without a message

* fix: simplify stdout check

* docs: adding a document specifying how mods should behave in each case

This should help us test it and also clarifies the expectations to the
users.

Very WIP.

* refactor: rename func

* docs: update

* fix: trim spaces

not sure if this looks better or worse tbh)

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* test: skip on windows

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: improve db

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* chore: typo

* test: reenable on windows

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2023-08-11 14:21:11 -03:00

24 lines
392 B
Go

package main
import (
"strings"
openai "github.com/sashabaranov/go-openai"
)
func lastPrompt(messages []openai.ChatCompletionMessage) string {
var result string
for _, msg := range messages {
if msg.Role != openai.ChatMessageRoleUser {
continue
}
result = msg.Content
}
return result
}
func firstLine(s string) string {
first, _, _ := strings.Cut(s, "\n")
return first
}