codegen

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: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CodegenTestCmd = &cobra.Command{
	Use:   "codegen-test",
	Short: "Test codegen prompt",
	Run: func(cmd *cobra.Command, args []string) {
		stepSettings, err := createSettingsFromCobra(cmd)
		cobra.CheckErr(err)

		c, err := NewTestCodegenCommand()
		cobra.CheckErr(err)

		c.StepSettings = stepSettings

		params := &TestCodegenCommandParameters{
			Pretend: "Scientist",
			What:    "Size of the moon",
			Of:      "My heart",
			Query:   []string{"What is the size of the moon?"},
		}

		ctx := context.Background()
		err = c.RunIntoWriter(ctx, params, cmd.OutOrStdout())
		cobra.CheckErr(err)
	},
}
View Source
var MultiStepCodgenTestCmd = &cobra.Command{
	Use:   "multi-step",
	Short: "Test codegen prompt",
	Run: func(cmd *cobra.Command, args []string) {
		stepSettings, err := createSettingsFromCobra(cmd)
		cobra.CheckErr(err)

		scientistCommand, err := NewTestCodegenCommand()
		cobra.CheckErr(err)
		scientistCommand.StepSettings = stepSettings

		scientistParams := &TestCodegenCommandParameters{
			Pretend: "Scientist",
			What:    "Size of the moon",
			Of:      "My heart",
			Query:   []string{"What is the size of the moon?"},
		}

		manager, err := scientistCommand.CreateManager(scientistParams)
		cobra.CheckErr(err)

		logger := watermill.NewStdLogger(false, false)
		pubSub := gochannel.NewGoChannel(gochannel.Config{

			BlockPublishUntilSubscriberAck: true,
		}, logger)

		router, err := message.NewRouter(message.RouterConfig{}, logger)
		cobra.CheckErr(err)
		defer func(router *message.Router) {
			err := router.Close()
			if err != nil {
				log.Error().Err(err).Msg("Failed to close router")
			}
		}(router)

		router.AddNoPublisherHandler("scientist",
			"scientist",
			pubSub,
			chat.StepPrinterFunc("Scientist", cmd.OutOrStdout()),
		)
		router.AddNoPublisherHandler("writer",
			"writer",
			pubSub,
			chat.StepPrinterFunc("Writer", cmd.OutOrStdout()),
		)

		writerParams := &TestCodegenCommandParameters{
			Pretend: "Writer",
			What:    "Biography of the scientist",
			Of:      "The previous story",
			Query:   []string{"Write a beautiful biography."},
		}
		writerCommand, err := NewTestCodegenCommand()
		cobra.CheckErr(err)
		writerCommand.StepSettings = stepSettings

		writerManager, err := writerCommand.CreateManager(writerParams)
		cobra.CheckErr(err)

		scientistStep, err := scientistCommand.CreateStep(
			chat.WithPublishedTopic(pubSub, "scientist"),
		)
		cobra.CheckErr(err)
		writerStep, err := writerCommand.CreateStep(
			chat.WithPublishedTopic(pubSub, "writer"),
		)
		cobra.CheckErr(err)

		mergeStep := utils.NewMergeStep(writerManager, true)

		ctx := cmd.Context()

		errgrp := errgroup.Group{}
		errgrp.Go(func() error {
			var scientistResult steps.StepResult[string]
			scientistResult, err = scientistStep.Start(ctx, manager.GetConversation())
			cobra.CheckErr(err)
			mergeResult := steps.Bind[string, conversation.Conversation](ctx, scientistResult, mergeStep)
			writerResult := steps.Bind[conversation.Conversation, string](ctx, mergeResult, writerStep)

			res := writerResult.Return()
			_ = res

			return nil
		})

		errgrp.Go(func() error {
			return router.Run(ctx)
		})

		err = errgrp.Wait()
		cobra.CheckErr(err)
	},
}

Functions

func NewPrinterFunc

func NewPrinterFunc(name string, w io.Writer) func(string) error

Types

type TestCodegenCommand

type TestCodegenCommand struct {
	*cmds.CommandDescription
	StepSettings *settings.StepSettings  `yaml:"-"`
	Prompt       string                  `yaml:"prompt"`
	Messages     []*conversation.Message `yaml:"messages,omitempty"`
	SystemPrompt string                  `yaml:"system-prompt"`
}

func NewTestCodegenCommand

func NewTestCodegenCommand() (*TestCodegenCommand, error)

func (*TestCodegenCommand) CreateManager

func (*TestCodegenCommand) CreateStep

func (c *TestCodegenCommand) CreateStep(options ...chat.StepOption) (
	chat.Step,
	error,
)

func (*TestCodegenCommand) RunIntoWriter

func (c *TestCodegenCommand) RunIntoWriter(
	ctx context2.Context,
	params *TestCodegenCommandParameters,
	w io.Writer,
) error

func (*TestCodegenCommand) RunToContextManager

func (c *TestCodegenCommand) RunToContextManager(
	ctx context2.Context,
	params *TestCodegenCommandParameters,
) (conversation.Manager, error)

func (*TestCodegenCommand) RunToString

func (c *TestCodegenCommand) RunToString(
	ctx context2.Context,
	params *TestCodegenCommandParameters,
) (string, error)

func (*TestCodegenCommand) RunWithManager

func (c *TestCodegenCommand) RunWithManager(
	ctx context2.Context,
	manager conversation.Manager,
) (steps.StepResult[string], error)

type TestCodegenCommandParameters

type TestCodegenCommandParameters struct {
	Pretend string   `glazed.parameter:"pretend"`
	What    string   `glazed.parameter:"what"`
	Of      string   `glazed.parameter:"of"`
	Query   []string `glazed.argument:"query"`
}

type UnitTestsCommand

type UnitTestsCommand struct {
	*cmds.CommandDescription
	StepSettings settings.StepSettings     `yaml:"-"`
	Prompt       string                    `yaml:"prompt"`
	Messages     conversation.Conversation `yaml:"messages,omitempty"`
	SystemPrompt string                    `yaml:"system-prompt"`
}

func NewUnitTestsCommand

func NewUnitTestsCommand() (*UnitTestsCommand, error)

func (*UnitTestsCommand) CreateManager

func (*UnitTestsCommand) CreateStep

func (c *UnitTestsCommand) CreateStep(options ...chat.StepOption) (chat.Step, error)

func (*UnitTestsCommand) RunIntoWriter

func (c *UnitTestsCommand) RunIntoWriter(ctx context.Context, params *UnitTestsCommandParameters, w io.Writer) error

func (*UnitTestsCommand) RunToContextManager

func (c *UnitTestsCommand) RunToContextManager(ctx context.Context, params *UnitTestsCommandParameters) (conversation.Manager, error)

func (*UnitTestsCommand) RunToString

func (c *UnitTestsCommand) RunToString(ctx context.Context, params *UnitTestsCommandParameters) (string, error)

func (*UnitTestsCommand) RunWithManager

func (c *UnitTestsCommand) RunWithManager(ctx context.Context, manager conversation.Manager) (steps.StepResult[string], error)

type UnitTestsCommandParameters

type UnitTestsCommandParameters struct {
	Code               string                `glazed.parameter:"code"`
	Language           string                `glazed.parameter:"language"`
	WithSignature      bool                  `glazed.parameter:"with_signature"`
	WithImplementation bool                  `glazed.parameter:"with_implementation"`
	WithComments       bool                  `glazed.parameter:"with_comments"`
	OnlyCode           bool                  `glazed.parameter:"only_code"`
	Framework          string                `glazed.parameter:"framework"`
	TableDriven        bool                  `glazed.parameter:"table_driven"`
	AdditionalSystem   string                `glazed.parameter:"additional_system"`
	Additional         []string              `glazed.parameter:"additional"`
	Context            []parameters.FileData `glazed.parameter:"context"`
	Bracket            bool                  `glazed.parameter:"bracket"`
}

Jump to

Keyboard shortcuts

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