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
@@ -0,0 +1,51 @@
|
||||
package terminal
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"io"
|
||||
)
|
||||
|
||||
type inputLine struct {
|
||||
text string
|
||||
err error
|
||||
}
|
||||
|
||||
// terminalInput 统一读取标准输入,聊天、录音结束和生图确认顺序消费。
|
||||
type terminalInput struct {
|
||||
lines <-chan inputLine
|
||||
}
|
||||
|
||||
func newInput(ctx context.Context, reader io.Reader) *terminalInput {
|
||||
lines := make(chan inputLine)
|
||||
go func() {
|
||||
defer close(lines)
|
||||
scanner := bufio.NewScanner(reader)
|
||||
for scanner.Scan() {
|
||||
select {
|
||||
case lines <- inputLine{text: scanner.Text()}:
|
||||
case <-ctx.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
select {
|
||||
case lines <- inputLine{err: err}:
|
||||
case <-ctx.Done():
|
||||
}
|
||||
}
|
||||
}()
|
||||
return &terminalInput{lines: lines}
|
||||
}
|
||||
|
||||
func (i *terminalInput) next(ctx context.Context) (string, error) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return "", ctx.Err()
|
||||
case line, ok := <-i.lines:
|
||||
if !ok {
|
||||
return "", io.EOF
|
||||
}
|
||||
return line.text, line.err
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user