コード例 #1
0
ファイル: server.go プロジェクト: xh3b4sd/anna
func (s *server) EncodeRequest(streamTextRequest *StreamTextRequest) (objectspec.TextInput, error) {
	textInputConfig := textinput.DefaultConfig()
	textInputConfig.Echo = streamTextRequest.Echo
	//textInputConfig.Expectation = streamTextRequest.Expectation
	textInputConfig.Input = streamTextRequest.Input
	textInputConfig.SessionID = streamTextRequest.SessionID
	textInput, err := textinput.New(textInputConfig)
	if err != nil {
		return nil, maskAny(err)
	}

	return textInput, nil
}
コード例 #2
0
func (a *annactl) ExecAnnactlInterfaceTextReadPlainCmd(cmd *cobra.Command, args []string) {
	a.Log.WithTags(spec.Tags{C: nil, L: "D", O: a, V: 13}, "call ExecAnnactlInterfaceTextReadPlainCmd")

	ctx := context.Background()

	go func() {
		a.Log.WithTags(spec.Tags{C: nil, L: "I", O: a, V: 10}, "Waiting for input.\n")

		scanner := bufio.NewScanner(os.Stdin)
		for scanner.Scan() {
			newTextInputConfig := textinput.DefaultConfig()
			newTextInputConfig.Echo = a.Flags.InterfaceTextReadPlain.Echo
			newTextInputConfig.Input = scanner.Text()
			newTextInputConfig.SessionID = a.SessionID
			newTextInput, err := textinput.New(newTextInputConfig)
			if err != nil {
				a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
			}

			a.Service().TextInput().GetChannel() <- newTextInput

			err = scanner.Err()
			if err != nil {
				a.Log.WithTags(spec.Tags{C: nil, L: "E", O: a, V: 4}, "%#v", maskAny(err))
			}
		}
	}()

	go func() {
		err := a.TextInterface.StreamText(ctx)
		if err != nil {
			a.Log.WithTags(spec.Tags{C: nil, L: "F", O: a, V: 1}, "%#v", maskAny(err))
		}
	}()

	for {
		select {
		case textResponse := <-a.Service().TextOutput().GetChannel():
			fmt.Printf("%s\n", textResponse.GetOutput())
		}
	}
}