Compare commits
2 Commits
c8a1e3e105
...
cb9e27542e
Author | SHA1 | Date | |
---|---|---|---|
cb9e27542e | |||
db27a22347 |
@ -12,6 +12,8 @@ import (
|
|||||||
var (
|
var (
|
||||||
maxTokens int
|
maxTokens int
|
||||||
model string
|
model string
|
||||||
|
systemPrompt string
|
||||||
|
systemPromptFile string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -19,6 +21,9 @@ func init() {
|
|||||||
for _, cmd := range inputCmds {
|
for _, cmd := range inputCmds {
|
||||||
cmd.Flags().IntVar(&maxTokens, "length", *config.OpenAI.DefaultMaxLength, "Max response length in tokens")
|
cmd.Flags().IntVar(&maxTokens, "length", *config.OpenAI.DefaultMaxLength, "Max response length in tokens")
|
||||||
cmd.Flags().StringVar(&model, "model", *config.OpenAI.DefaultModel, "The language model to use")
|
cmd.Flags().StringVar(&model, "model", *config.OpenAI.DefaultModel, "The language model to use")
|
||||||
|
cmd.Flags().StringVar(&systemPrompt, "system-prompt", *config.ModelDefaults.SystemPrompt, "The system prompt to use.")
|
||||||
|
cmd.Flags().StringVar(&systemPromptFile, "system-prompt-file", "", "A path to a file whose contents are used as the system prompt.")
|
||||||
|
cmd.MarkFlagsMutuallyExclusive("system-prompt", "system-prompt-file")
|
||||||
}
|
}
|
||||||
|
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
@ -35,6 +40,17 @@ func Execute() error {
|
|||||||
return rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SystemPrompt() string {
|
||||||
|
if systemPromptFile != "" {
|
||||||
|
content, err := FileContents(systemPromptFile)
|
||||||
|
if err != nil {
|
||||||
|
Fatal("Could not read file contents at %s: %v", systemPromptFile, err)
|
||||||
|
}
|
||||||
|
return content
|
||||||
|
}
|
||||||
|
return systemPrompt
|
||||||
|
}
|
||||||
|
|
||||||
// InputFromArgsOrEditor returns either the provided input from the args slice
|
// InputFromArgsOrEditor returns either the provided input from the args slice
|
||||||
// (joined with spaces), or if len(args) is 0, opens an editor and returns
|
// (joined with spaces), or if len(args) is 0, opens an editor and returns
|
||||||
// whatever input was provided there. placeholder is a string which populates
|
// whatever input was provided there. placeholder is a string which populates
|
||||||
@ -327,12 +343,11 @@ var newCmd = &cobra.Command{
|
|||||||
Fatal("Could not save new conversation: %v\n", err)
|
Fatal("Could not save new conversation: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
const system = "You are a helpful assistant."
|
|
||||||
messages := []Message{
|
messages := []Message{
|
||||||
{
|
{
|
||||||
ConversationID: conversation.ID,
|
ConversationID: conversation.ID,
|
||||||
Role: "system",
|
Role: "system",
|
||||||
OriginalContent: system,
|
OriginalContent: SystemPrompt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
ConversationID: conversation.ID,
|
ConversationID: conversation.ID,
|
||||||
@ -396,11 +411,10 @@ var promptCmd = &cobra.Command{
|
|||||||
Fatal("No message was provided.\n")
|
Fatal("No message was provided.\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
const system = "You are a helpful assistant."
|
|
||||||
messages := []Message{
|
messages := []Message{
|
||||||
{
|
{
|
||||||
Role: "system",
|
Role: "system",
|
||||||
OriginalContent: system,
|
OriginalContent: SystemPrompt(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Role: "user",
|
Role: "user",
|
||||||
|
@ -9,6 +9,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
|
ModelDefaults *struct {
|
||||||
|
SystemPrompt *string `yaml:"systemPrompt" default:"You are a helpful assistant."`
|
||||||
|
} `yaml:"modelDefaults"`
|
||||||
OpenAI *struct {
|
OpenAI *struct {
|
||||||
APIKey *string `yaml:"apiKey" default:"your_key_here"`
|
APIKey *string `yaml:"apiKey" default:"your_key_here"`
|
||||||
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
|
DefaultModel *string `yaml:"defaultModel" default:"gpt-4"`
|
||||||
@ -20,7 +23,7 @@ type Config struct {
|
|||||||
} `yaml:"chroma"`
|
} `yaml:"chroma"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfigDir() string {
|
func ConfigDir() string {
|
||||||
var configDir string
|
var configDir string
|
||||||
|
|
||||||
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
|
xdgConfigHome := os.Getenv("XDG_CONFIG_HOME")
|
||||||
@ -36,7 +39,7 @@ func getConfigDir() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
configFile := filepath.Join(getConfigDir(), "config.yaml")
|
configFile := filepath.Join(ConfigDir(), "config.yaml")
|
||||||
shouldWriteDefaults := false
|
shouldWriteDefaults := false
|
||||||
c := &Config{}
|
c := &Config{}
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ type Conversation struct {
|
|||||||
Title string
|
Title string
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDataDir() string {
|
func DataDir() string {
|
||||||
var dataDir string
|
var dataDir string
|
||||||
|
|
||||||
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
xdgDataHome := os.Getenv("XDG_DATA_HOME")
|
||||||
@ -49,7 +49,7 @@ func getDataDir() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewStore() (*Store, error) {
|
func NewStore() (*Store, error) {
|
||||||
databaseFile := filepath.Join(getDataDir(), "conversations.db")
|
databaseFile := filepath.Join(DataDir(), "conversations.db")
|
||||||
db, err := gorm.Open(sqlite.Open(databaseFile), &gorm.Config{})
|
db, err := gorm.Open(sqlite.Open(databaseFile), &gorm.Config{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("Error establishing connection to store: %v", err)
|
return nil, fmt.Errorf("Error establishing connection to store: %v", err)
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -158,3 +159,15 @@ func SetStructDefaults(data interface{}) bool {
|
|||||||
}
|
}
|
||||||
return changed
|
return changed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FileContents returns the string contents of the given file.
|
||||||
|
// TODO: we should support retrieving the content (or an approximation of)
|
||||||
|
// non-text documents, e.g. PDFs.
|
||||||
|
func FileContents(file string) (string, error) {
|
||||||
|
path := filepath.Clean(file)
|
||||||
|
content, err := os.ReadFile(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return strings.Trim(string(content), "\n\t "), nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user