diff --git a/go.mod b/go.mod index ff9cf1a..a9361c3 100644 --- a/go.mod +++ b/go.mod @@ -9,6 +9,7 @@ replace github.com/rocketlaunchr/google-search => github.com/chrisjoyce911/googl require ( gitea.stevedudenhoeffer.com/steve/go-extractor v0.0.0-20250315044602-7c0e44a22f2c gitea.stevedudenhoeffer.com/steve/go-llm v0.0.0-20250317023858-7f5e34e437a7 + github.com/Edw590/go-wolfram v0.0.0-20241010091529-fb9031908c5d github.com/advancedlogic/GoOse v0.0.0-20231203033844-ae6b36caf275 github.com/joho/godotenv v1.5.1 github.com/playwright-community/playwright-go v0.5001.0 diff --git a/pkg/answer/answer.go b/pkg/answer/answer.go index 5cb17f7..f510438 100644 --- a/pkg/answer/answer.go +++ b/pkg/answer/answer.go @@ -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)