feat: initialize Eino examples and ADK applications
Include chat, weather, image, travel, streaming ASR and text examples, shared model initialization, documentation, and existing tests. Co-authored-by: TRAE CLI <traecli@bytedance.com>
This commit is contained in:
commit
81deca8c8e
75 files changed
+7048
No files matched your search
+102
@@ -0,0 +1,102 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"example.com/ueino/legacy/round"
|
||||
"example.com/ueino/pkg/memory"
|
||||
"example.com/ueino/pkg/model"
|
||||
"example.com/ueino/pkg/opt"
|
||||
"example.com/ueino/pkg/provider"
|
||||
"example.com/ueino/pkg/tool"
|
||||
)
|
||||
|
||||
var (
|
||||
baseURL string
|
||||
modelName string
|
||||
apiKeyEnv string
|
||||
maxToken int
|
||||
)
|
||||
|
||||
func init() {
|
||||
flag.StringVar(&baseURL, "base-url", "https://ai.loveuer.com/v1", "")
|
||||
flag.StringVar(&modelName, "model", "local-mini", "")
|
||||
flag.StringVar(&apiKeyEnv, "api-key-env", "AI_KEY", "")
|
||||
flag.IntVar(&maxToken, "max-token", 4096, "")
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer cancel()
|
||||
|
||||
done := make(chan struct{})
|
||||
go func() {
|
||||
defer close(done)
|
||||
run(ctx)
|
||||
}()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
fmt.Println()
|
||||
case <-done:
|
||||
}
|
||||
}
|
||||
|
||||
func run(ctx context.Context) {
|
||||
chat := provider.NewChat(
|
||||
provider.ChatBaseURL(baseURL),
|
||||
provider.ChatModel(modelName),
|
||||
provider.ChatApiKeyByEnv(apiKeyEnv),
|
||||
)
|
||||
|
||||
mem := memory.NewMemory(maxToken)
|
||||
tools := []tool.Tool{tool.NewWeather()}
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
fmt.Println("输入消息开始聊天,按 Ctrl+C 退出。")
|
||||
|
||||
for ctx.Err() == nil {
|
||||
fmt.Print("📝 > ")
|
||||
if !scanner.Scan() {
|
||||
break
|
||||
}
|
||||
|
||||
input := strings.TrimSpace(scanner.Text())
|
||||
if input == "" {
|
||||
continue
|
||||
}
|
||||
|
||||
messages := []model.ChatMessage{{Role: "system", Content: opt.SYSTEM_PROMPT}}
|
||||
messages = append(messages, mem.LoadHistory()...)
|
||||
messages = append(messages, model.ChatMessage{Role: "user", Content: input})
|
||||
|
||||
fmt.Println("🤖 thinking...")
|
||||
reply, err := round.Complete(ctx, chat, messages, tools, func(chunk string) {
|
||||
fmt.Print(chunk)
|
||||
})
|
||||
fmt.Println()
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("请求失败: %v", err)
|
||||
continue
|
||||
}
|
||||
if reply != "" {
|
||||
mem.Save(input, reply)
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Printf("读取输入失败: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user