diff --git a/pkg/answer/answer.go b/pkg/answer/answer.go index d6541d1..ab77e50 100644 --- a/pkg/answer/answer.go +++ b/pkg/answer/answer.go @@ -32,6 +32,8 @@ type Question struct { // Answers is a list of answers to a question type Answers []string +const DefaultPrompt = "You are being asked to answer a question. You must respond with a function. You can answer it if you know the answer, or if some functions exist you can use those to help you find the answer." + type Options struct { // MaxSearches is the maximum possible number of searches to execute for this question. If this is set to 5, the function could // search up to 5 possible times to find an answer. @@ -50,6 +52,15 @@ type Options struct { // The "answer" and "no_answer" functions are not included in this callback. // Return an error to stop the function from being called. OnNewFunction func(ctx context.Context, funcName string, question string, parameter string) error + + // SystemPrompt is the prompt to use when asking the system to answer a question. + // If this is empty, DefaultPrompt will be used. + SystemPrompt string + + // ExtraSystemPrompts is a list of extra prompts to use when asking the system to answer a question. Use these for + // variety in the prompts, or passing in some useful contextually relevant information. + // All of these will be used in addition to the SystemPrompt. + ExtraSystemPrompts []string } var DefaultOptions = Options{ @@ -339,17 +350,29 @@ func (o Options) Answer(ctx context.Context, q Question) (Answers, error) { var temp float32 = 0.8 + var messages []gollm.Message + + if o.SystemPrompt != "" { + messages = append(messages, gollm.Message{ + Role: gollm.RoleSystem, + Text: o.SystemPrompt, + }) + } else { + messages = append(messages, gollm.Message{ + Role: gollm.RoleSystem, + Text: DefaultPrompt, + }) + } + + for _, prompt := range o.ExtraSystemPrompts { + messages = append(messages, gollm.Message{ + Role: gollm.RoleSystem, + Text: prompt, + }) + } + req := gollm.Request{ - Messages: []gollm.Message{ - { - Role: gollm.RoleSystem, - Text: "You are being asked to answer a question. You must respond with a function. You can answer it if you know the answer, or if some functions exist you can use those to help you find the answer.", - }, - { - Role: gollm.RoleUser, - Text: q.Question, - }, - }, + Messages: messages, Toolbox: gollm.NewToolBox(funcs...), Temperature: &temp, }