implement the wolfram function

This commit is contained in:
2025-03-16 22:59:25 -04:00
parent bf16b4b0cd
commit bdaa3b7d96
2 changed files with 28 additions and 9 deletions

View File

@@ -15,6 +15,7 @@ import (
"gitea.stevedudenhoeffer.com/steve/answer/pkg/extractor"
"gitea.stevedudenhoeffer.com/steve/answer/pkg/search"
gollm "gitea.stevedudenhoeffer.com/steve/go-llm"
)
var ErrMaxTries = errors.New("maximum number of pages tried reached")
@@ -64,6 +65,10 @@ type Options struct {
// 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
// WolframAppID is the Wolfram Alpha App ID to use when searching Wolfram Alpha for answers. If not set, the
// wolfram function will not be available.
WolframAppID string
}
var DefaultOptions = Options{
@@ -307,14 +312,23 @@ func (o Options) Answer(ctx context.Context, q Question) (Answers, error) {
return args.Answer, nil
})
fnWolfram := gollm.NewFunction(
"wolfram",
"Search Wolfram Alpha for an answer to a question.",
func(ctx *gollm.Context, args struct {
Question string `description:"the question to search for"`
}) (string, error) {
return "", nil
})
var fnWolfram *gollm.Function
if o.WolframAppID != "" {
fnWolfram = gollm.NewFunction(
"wolfram",
"Search Wolfram Alpha for an answer to a question.",
func(ctx *gollm.Context, args struct {
Question string `description:"the question to search for"`
}) (string, error) {
cl := wolfram.Client{
AppID: o.WolframAppID,
}
unit := wolfram.Imperial
return cl.GetShortAnswerQuery(args.Question, unit, 10)
})
}
fnCalculate := gollm.NewFunction(
"calculate",
@@ -331,7 +345,11 @@ func (o Options) Answer(ctx context.Context, q Question) (Answers, error) {
return v.String(), nil
})
var funcs = []*gollm.Function{fnAnswer, fnWolfram, fnCalculate}
var funcs = []*gollm.Function{fnAnswer, fnCalculate}
if fnWolfram != nil {
funcs = append(funcs, fnWolfram)
}
if o.MaxSearches > 0 {
funcs = append(funcs, fnSearch)