tool

package
v0.4.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 7, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ToolCallCmd = &cobra.Command{
	Use:   "tool-call",
	Short: "Tool call",
	Run: func(cmd *cobra.Command, args []string) {
		stepSettings := settings.NewStepSettings()
		geppettoLayers, err := cmds.CreateGeppettoLayers(stepSettings)
		cobra.CheckErr(err)
		layers_ := layers.NewParameterLayers(layers.WithLayers(geppettoLayers...))

		parser, err := cli.NewCobraParserFromLayers(
			layers_,
			cli.WithCobraMiddlewaresFunc(cmds.GetCobraCommandGeppettoMiddlewares))
		cobra.CheckErr(err)

		parsedLayers, err := parser.Parse(cmd, nil)
		cobra.CheckErr(err)

		err = stepSettings.UpdateFromParsedLayers(parsedLayers)
		cobra.CheckErr(err)

		ctx, cancel := context.WithCancel(cmd.Context())
		defer cancel()
		messages := []*conversation.Message{
			conversation.NewChatMessage(
				conversation.RoleUser,
				"Give me the weather in Boston on november 9th 1924, please, including the windspeed for me, an old ass american. Also, the weather in paris today, with temperature.",
			),
		}

		reflector := new(jsonschema.Reflector)
		err = reflector.AddGoComments("github.com/go-go-golems/geppetto", "./cmd/experiments/agent")
		if err != nil {
			log.Warn().Err(err).Msg("Could not add go comments")
		}
		getWeatherOnDayJsonSchema, _ := helpers2.GetFunctionParametersJsonSchema(reflector, getWeatherOnDay)
		s, _ := json.MarshalIndent(getWeatherOnDayJsonSchema, "", " ")
		fmt.Printf("getWeatherOnDayJsonSchema:\n%s\n\n", s)

		getWeatherJsonSchema, _ := helpers2.GetFunctionParametersJsonSchema(reflector, getWeather)
		s, _ = json.MarshalIndent(getWeatherJsonSchema, "", " ")
		fmt.Printf("getWeatherJsonSchema:\n%s\n\n", s)

		step := &openai.ToolStep{
			Settings: stepSettings,
			Tools: []go_openai.Tool{{
				Type: "function",
				Function: go_openai.FunctionDefinition{
					Name:        "getWeather",
					Description: "Get the weather",
					Parameters:  getWeatherJsonSchema,
				},
			},
				{
					Type: "function",
					Function: go_openai.FunctionDefinition{
						Name:        "getWeatherOnDay",
						Description: "Get the weather on a specific day",
						Parameters:  getWeatherOnDayJsonSchema,
					},
				},
			},
		}

		execStep := &openai.ExecuteToolStep{
			Tools: map[string]interface{}{
				"getWeather":      getWeather,
				"getWeatherOnDay": getWeatherOnDay,
			},
		}

		res, err := step.Start(ctx, messages)
		cobra.CheckErr(err)

		res_ := steps.Bind[openai.ToolCompletionResponse, map[string]interface{}](ctx, res, execStep)

		c := res_.GetChannel()
		for i := range c {
			s, err := i.Value()
			cobra.CheckErr(err)

			s_, _ := json.MarshalIndent(s, "", " ")
			fmt.Printf("%s", s_)
		}
	},
}

Functions

This section is empty.

Types

type WeatherData

type WeatherData struct {
	City        string  `json:"city"`
	Temperature float64 `json:"temperature"`
	WindSpeed   float64 `json:"wind_speed"`
}

type WeatherOnDayRequest

type WeatherOnDayRequest struct {
	WeatherRequest
	// The date for which to request the data
	Date string `json:"date"`
}

type WeatherRequest

type WeatherRequest struct {
	// The city for which to request the data
	City string `json:"city"`
	// Return windspeed in km/h
	WindSpeed bool `json:"wind_speed"`
	// Return temperature in Celsius
	Temperature bool `json:"temperature"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL