fix(llm): 测试连接校验模型确有回复,并按配置的收发模式测
测试连接此前只判 err:请求通了但模型一个字不吐(思考烧光预算、正文被 安全策略吞掉、兼容层丢 content)照样报成功,而这种配置在会话里就是不 回话——正是「测试成功、对话不成功」的来源。 - TestConnection 返回回复文本,空回复直接判失败 - 回复回传前端,成功 toast 里展示,测试通过有据可查 - 测试连接改用该配置真实的收发模式:此前恒走流式(ConfigFrom 默认 Stream=true),选了非流式的配置测的是另一条通道;请求省略 streaming 时仍默认流式,老客户端不受影响 Closes #65
This commit is contained in:
1 parent
68a221eda1
commit
7b1f7e141b
5 files changed
+62
-11
No files matched your search
+17
-5
@@ -357,11 +357,12 @@ func quotaAwareHTTPClient(proxy string) (*http.Client, error) {
|
||||
}
|
||||
|
||||
// TestConnection makes a minimal real completion to verify the provider/model/
|
||||
// endpoint/key actually work. Returns the round-trip latency.
|
||||
func TestConnection(ctx context.Context, c Config) (time.Duration, error) {
|
||||
// endpoint/key actually work. Returns the round-trip latency and the model's
|
||||
// reply text.
|
||||
func TestConnection(ctx context.Context, c Config) (time.Duration, string, error) {
|
||||
prov, err := c.NewProvider()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, "", err
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(ctx, 30*time.Second)
|
||||
defer cancel()
|
||||
@@ -371,7 +372,7 @@ func TestConnection(ctx context.Context, c Config) (time.Duration, error) {
|
||||
// 就撞到输出上限(finish=length)、被截断,连接测试虽仍算通(err=nil)但显示成
|
||||
// "已中断/length/resume" 一团糟。给足预算让它把 OK 干净吐完(finish=stop)。
|
||||
// EscalateMaxTokens 保持 false:不因截断而抬额重试,避免 resume 循环空烧。
|
||||
_, err = agentcore.Run(ctx, agentcore.Options{
|
||||
reply, err := agentcore.Run(ctx, agentcore.Options{
|
||||
Provider: prov,
|
||||
SystemPrompt: []string{"你是连接测试。直接输出两个字符 OK 即可,不要思考、不要解释、不要别的。"},
|
||||
PermissionMode: acperm.ModeBypass,
|
||||
@@ -379,5 +380,16 @@ func TestConnection(ctx context.Context, c Config) (time.Duration, error) {
|
||||
MaxTokens: 8192,
|
||||
NonStreaming: !c.Stream, // 用该 profile 的真实收发模式做连接测试
|
||||
}, "ping")
|
||||
return time.Since(start), err
|
||||
lat := time.Since(start)
|
||||
if err != nil {
|
||||
return lat, "", err
|
||||
}
|
||||
// err==nil 还不够:请求通了但模型一个字都不吐的情况真实存在(思考把预算烧光、
|
||||
// 正文被安全策略吞掉、兼容层把 content 丢了)。这种配置在会话里就是"不回话",
|
||||
// 测试却报成功——正是本项要消除的落差。没有可见正文一律判失败。
|
||||
reply = strings.TrimSpace(reply)
|
||||
if reply == "" {
|
||||
return lat, "", fmt.Errorf("模型无回复内容(请求已通,但未返回任何文本)")
|
||||
}
|
||||
return lat, reply, nil
|
||||
}
|
||||
Reference in new issue
Block a user