build: 内置 norma 模块,构建不再依赖上游仓库
把 github.com/Autumn-27/norma v0.4.3(commit 320ae32)的源码复制到 third_party/norma,并用 go.mod 的 replace 指向本地副本。上游删除仓库或 改写 tag 都不再影响本仓库构建。 - 已验证 GOPROXY=off 下可完整编译并打出发行包 - go.sum 中该模块的两条校验记录随之删除(本地 replace 不需要哈希) - 升级方法与授权注意事项见 third_party/README.md
This commit is contained in:
1 parent
a819fa3230
commit
f782b612ec
213 files changed
+37401
-2
No files matched your search
Vendored
+52
@@ -0,0 +1,52 @@
|
||||
package llm
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// sseScanner reads Server-Sent Events from a response body, yielding the
|
||||
// (event, data) pair of each message. Anthropic uses named events; OpenAI uses
|
||||
// bare data lines. Both are handled.
|
||||
type sseScanner struct {
|
||||
r *bufio.Reader
|
||||
}
|
||||
|
||||
func newSSEScanner(body io.Reader) *sseScanner {
|
||||
return &sseScanner{r: bufio.NewReaderSize(body, 64*1024)}
|
||||
}
|
||||
|
||||
// next returns the next event's (type, data). event is "" for bare-data streams.
|
||||
// Returns io.EOF at end of stream.
|
||||
func (s *sseScanner) next() (event, data string, err error) {
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
line, rerr := s.r.ReadString('\n')
|
||||
if rerr != nil {
|
||||
if rerr == io.EOF && (buf.Len() > 0 || event != "") {
|
||||
return event, strings.TrimRight(buf.String(), "\n"), nil
|
||||
}
|
||||
return "", "", rerr
|
||||
}
|
||||
line = strings.TrimRight(line, "\r\n")
|
||||
if line == "" {
|
||||
if buf.Len() > 0 || event != "" {
|
||||
return event, strings.TrimRight(buf.String(), "\n"), nil
|
||||
}
|
||||
continue
|
||||
}
|
||||
switch {
|
||||
case strings.HasPrefix(line, "event:"):
|
||||
event = strings.TrimSpace(line[len("event:"):])
|
||||
case strings.HasPrefix(line, "data:"):
|
||||
d := line[len("data:"):]
|
||||
d = strings.TrimPrefix(d, " ")
|
||||
buf.WriteString(d)
|
||||
buf.WriteByte('\n')
|
||||
default:
|
||||
// comment / unknown field — ignore
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user