-
-
Notifications
You must be signed in to change notification settings - Fork 592
/
mrkl_agent.go
48 lines (44 loc) · 909 Bytes
/
mrkl_agent.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"fmt"
"os"
"github.com/tmc/langchaingo/agents"
"github.com/tmc/langchaingo/chains"
"github.com/tmc/langchaingo/llms/openai"
"github.com/tmc/langchaingo/tools"
"github.com/tmc/langchaingo/tools/serpapi"
)
func main() {
if err := run(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}
func run() error {
llm, err := openai.New()
if err != nil {
return err
}
search, err := serpapi.New()
if err != nil {
return err
}
agentTools := []tools.Tool{
tools.Calculator{},
search,
}
executor, err := agents.Initialize(
llm,
agentTools,
agents.ZeroShotReactDescription,
agents.WithMaxIterations(3),
)
if err != nil {
return err
}
question := "Who is Olivia Wilde's boyfriend? What is his current age raised to the 0.23 power?"
answer, err := chains.Run(context.Background(), executor, question)
fmt.Println(answer)
return err
}