77
88 // Packages
99 opts "github.com/mutablelogic/go-client"
10+ "github.com/mutablelogic/go-llm"
1011 anthropic "github.com/mutablelogic/go-llm/pkg/anthropic"
12+ "github.com/mutablelogic/go-llm/pkg/tool"
1113 assert "github.com/stretchr/testify/assert"
1214)
1315
@@ -107,14 +109,12 @@ func Test_messages_004(t *testing.T) {
107109 t .FailNow ()
108110 }
109111
110- weather , err := anthropic .NewTool ("weather_in_location" , "Get the weather in a location" , struct {
111- Location string `name:"location" help:"The location to get the weather for" required:"true"`
112- }{})
113- if ! assert .NoError (err ) {
112+ toolkit := tool .NewToolKit ()
113+ if err := toolkit .Register (new (weather )); ! assert .NoError (err ) {
114114 t .FailNow ()
115115 }
116116
117- response , err := client .Messages (context .TODO (), model .UserPrompt ("why is the sky blue" ), anthropic .WithTool ( weather ))
117+ response , err := client .Messages (context .TODO (), model .UserPrompt ("why is the sky blue" ), anthropic .WithToolKit ( toolkit ))
118118 if assert .NoError (err ) {
119119 t .Log (response )
120120 }
@@ -136,17 +136,34 @@ func Test_messages_005(t *testing.T) {
136136 t .FailNow ()
137137 }
138138
139- weather , err := anthropic .NewTool ("weather_in_location" , "Get the weather in a location" , struct {
140- Location string `name:"location" help:"The location to get the weather for" required:"true"`
141- }{})
142- if ! assert .NoError (err ) {
139+ toolkit := tool .NewToolKit ()
140+ if err := toolkit .Register (new (weather )); ! assert .NoError (err ) {
143141 t .FailNow ()
144142 }
145143
146144 response , err := client .Messages (context .TODO (), model .UserPrompt ("why is the sky blue" ), anthropic .WithStream (func (r * anthropic.Response ) {
147145 t .Log (r )
148- }), anthropic .WithTool ( weather ))
146+ }), anthropic .WithToolKit ( toolkit ))
149147 if assert .NoError (err ) {
150148 t .Log (response )
151149 }
152150}
151+
152+ ////////////////////////////////////////////////////////////////////////////////
153+ // TOOLS
154+
155+ type weather struct {
156+ Location string `name:"location" help:"The location to get the weather for" required:"true"`
157+ }
158+
159+ func (* weather ) Name () string {
160+ return "weather_in_location"
161+ }
162+
163+ func (* weather ) Description () string {
164+ return "Get the weather in a location"
165+ }
166+
167+ func (* weather ) Run (ctx context.Context ) (any , error ) {
168+ return nil , llm .ErrNotImplemented
169+ }
0 commit comments