func main()

in llm/go-client/cmd/client.go [136:229]


func main() {
	cfg, err := config.GetConfig()
	if err != nil {
		fmt.Printf("Error loading config: %v\n", err)
		return
	}

	availableModels = cfg.OllamaModels
	currentModel = cfg.DefaultModel()
	maxContextCount = cfg.MaxContextCount

	currentCtxID = createContext()

	ins, err := dubbo.NewInstance(
		dubbo.WithRegistry(
			registry.WithNacos(),
			registry.WithAddress(cfg.NacosURL),
		),
	)
	if err != nil {
		panic(err)
	}
	// configure the params that only client layer cares
	cli, err := ins.NewClient()
	if err != nil {
		panic(err)
	}

	svc, err := chat.NewChatService(cli)
	if err != nil {
		fmt.Printf("Error creating service: %v\n", err)
		return
	}

	fmt.Printf("\nSend a message (/? for help) - Using model: %s\n", currentModel)
	scanner := bufio.NewScanner(os.Stdin)
	for {
		fmt.Print("\n> ")
		scanner.Scan()
		input := scanner.Text()

		// handle command
		if strings.HasPrefix(input, "/") {
			fmt.Println(handleCommand(input))
			continue
		}

		func() {
			currentCtx := contexts[currentCtxID]
			currentCtx.History = append(currentCtx.History,
				&chat.ChatMessage{
					Role:    "human",
					Content: input,
					Bin:     nil,
				})

			stream, err := svc.Chat(context.Background(), &chat.ChatRequest{
				Messages: currentCtx.History,
				Model:    currentModel,
			})
			if err != nil {
				panic(err)
			}
			defer func(stream chat.ChatService_ChatClient) {
				err := stream.Close()
				if err != nil {
					fmt.Printf("Error closing stream: %v\n", err)
				}
			}(stream)

			resp := ""

			for stream.Recv() {
				msg := stream.Msg()
				c := msg.Content
				resp += c
				fmt.Print(c)
			}
			fmt.Print("\n")

			if err := stream.Err(); err != nil {
				fmt.Printf("Stream error: %v\n", err)
				return
			}

			currentCtx.History = append(currentCtx.History,
				&chat.ChatMessage{
					Role:    "ai",
					Content: resp,
					Bin:     nil,
				})
		}()
	}
}