Add customizable prompts for system messages in Options
Introduced `SystemPrompt` and `ExtraSystemPrompts` to allow more flexible and context-aware system message customization. Replaced static default system message with dynamic handling using these new fields, falling back to `DefaultPrompt` if needed. Updated the request construction logic to incorporate the newly added prompt options.
This commit is contained in:
parent
e1c10eb49e
commit
1d47cf5758
@ -32,6 +32,8 @@ type Question struct {
|
|||||||
// Answers is a list of answers to a question
|
// Answers is a list of answers to a question
|
||||||
type Answers []string
|
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 {
|
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
|
// 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.
|
// 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.
|
// The "answer" and "no_answer" functions are not included in this callback.
|
||||||
// Return an error to stop the function from being called.
|
// Return an error to stop the function from being called.
|
||||||
OnNewFunction func(ctx context.Context, funcName string, question string, parameter string) error
|
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{
|
var DefaultOptions = Options{
|
||||||
@ -339,17 +350,29 @@ func (o Options) Answer(ctx context.Context, q Question) (Answers, error) {
|
|||||||
|
|
||||||
var temp float32 = 0.8
|
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{
|
req := gollm.Request{
|
||||||
Messages: []gollm.Message{
|
Messages: messages,
|
||||||
{
|
|
||||||
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,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Toolbox: gollm.NewToolBox(funcs...),
|
Toolbox: gollm.NewToolBox(funcs...),
|
||||||
Temperature: &temp,
|
Temperature: &temp,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user