mirror of
https://gitcode.com/JianFeeeee/ModelRouter.git
synced 2026-09-20 08:57:57 +00:00
refactor: unify oneLineStr/oneLine into types.OneLine
provider.oneLineStr and gateway.oneLine had byte-identical bodies (flatten whitespace + cap length). Move the single implementation into the types package, which both layers already depend on, and delete both locals.
This commit is contained in:
@ -528,10 +528,10 @@ func clientUpstreamErr(err error) string {
|
||||
if errors.As(err, &ce) {
|
||||
parts := make([]string, 0, len(ce.Tiers)+len(ce.Skipped))
|
||||
for _, t := range ce.Tiers {
|
||||
parts = append(parts, oneLine(fmt.Sprintf("%s/%s: %v", t.Source, t.Model, t.Err), 80))
|
||||
parts = append(parts, types.OneLine(fmt.Sprintf("%s/%s: %v", t.Source, t.Model, t.Err), 80))
|
||||
}
|
||||
for _, sk := range ce.Skipped {
|
||||
parts = append(parts, oneLine(sk, 80))
|
||||
parts = append(parts, types.OneLine(sk, 80))
|
||||
}
|
||||
msg := strings.Join(parts, "; ")
|
||||
if len(msg) > 300 {
|
||||
@ -539,16 +539,7 @@ func clientUpstreamErr(err error) string {
|
||||
}
|
||||
return fmt.Sprintf("all %d auto providers failed: %s", len(parts), msg)
|
||||
}
|
||||
return oneLine(err.Error(), 160)
|
||||
}
|
||||
|
||||
// oneLine flattens an error string to a single line capped at n chars.
|
||||
func oneLine(s string, n int) string {
|
||||
s = strings.Join(strings.Fields(s), " ")
|
||||
if len(s) > n {
|
||||
s = s[:n] + "..."
|
||||
}
|
||||
return s
|
||||
return types.OneLine(err.Error(), 160)
|
||||
}
|
||||
|
||||
func (g *Gateway) singleChat(w http.ResponseWriter, ctx context.Context, cands []*provider.Provider, req *types.ChatRequest, effective string, rec *Req) {
|
||||
|
||||
Reference in New Issue
Block a user