cmd

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2023 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultMaxTokens = 256
View Source
const DefaultTemperature = 0.7

Variables

View Source
var ChatCmd = &cobra.Command{
	Use:   "chat",
	Short: "read a chat from stdin and send to LLM chat",
	Run: func(cmd *cobra.Command, args []string) {

		input, err := io.ReadAll(os.Stdin)
		if err != nil {
			slog.Error("failed to read input", "err", err)
			return
		}

		lines := strings.Split(string(input), "\n")
		var temperature float32 = DefaultTemperature
		maxTokens := DefaultMaxTokens
		if strings.HasPrefix(lines[0], "#") {
			temperature = getTemperature(lines[0])
			maxTokens = getMaxTokens(lines[0])
			lines = lines[0:]
		}

		chatClient := vichat.New().WithTemperature(temperature).WithMaxTokens(maxTokens)
		messages := chat.New(CreatePrompts(lines)...)
		res, err := chatClient.Chat(context.TODO(), messages)
		if err != nil {
			slog.Error("failed", "err", err.Error())
			return
		}

		println(res)
	},
}
View Source
var InstallCmd = &cobra.Command{
	Use:     "install-vim-plugin",
	Short:   "install the vim plugin",
	Aliases: []string{"i"},
	Run: func(cmd *cobra.Command, args []string) {
		installVim()
	},
}
View Source
var TokCmd = &cobra.Command{
	Use:   "tok",
	Short: "given a piece of text, tok estimate the num of tokens for a given model offline",
	Run: func(cmd *cobra.Command, args []string) {

		f := cmd.Flags()
		model, err := f.GetString("model")
		if err != nil {
			slog.Error("failed", "err", err)
		}

		text, err := io.ReadAll(os.Stdin)
		if err != nil {
			slog.Error("failed", "err", err)
		}

		toks, err := vichat.Tokenize(string(text), model)
		if err != nil {
			slog.Error("failed", "err", err)
			return
		}

		fmt.Println(len(toks))
	},
}

Functions

func CreatePrompts

func CreatePrompts(lines []string) []chat.PromptMessage

Types

This section is empty.

Jump to

Keyboard shortcuts

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