Compare commits

..

2 Commits

Author SHA1 Message Date
5b338d4129 implement the wolfram function 2025-03-16 23:00:04 -04:00
bdaa3b7d96 implement the wolfram function 2025-03-16 22:59:25 -04:00
2 changed files with 28 additions and 9 deletions

1
go.mod
View File

@ -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

View File

@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"github.com/Edw590/go-wolfram"
"go.starlark.net/lib/math"
"go.starlark.net/starlark"
"go.starlark.net/syntax"
@ -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)