mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-07 06:50:50 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f1d9364ef4 |
@@ -483,7 +483,7 @@ outLoop:
|
||||
// Handle client disconnection.
|
||||
case <-c.Request.Context().Done():
|
||||
if c.Request.Context().Err().Error() == "context canceled" {
|
||||
log.Debugf("qwen client disconnected: %v", c.Request.Context().Err())
|
||||
log.Debugf("openai client disconnected: %v", c.Request.Context().Err())
|
||||
cliCancel() // Cancel the backend request.
|
||||
return
|
||||
}
|
||||
|
||||
@@ -330,8 +330,10 @@ func (c *QwenClient) APIRequest(ctx context.Context, modelName, endpoint string,
|
||||
}
|
||||
|
||||
toolsResult := gjson.GetBytes(jsonBody, "tools")
|
||||
if toolsResult.IsArray() && len(toolsResult.Array()) == 0 {
|
||||
jsonBody, _ = sjson.DeleteBytes(jsonBody, "tools")
|
||||
// I'm addressing the Qwen3 "poisoning" issue, which is caused by the model needing a tool to be defined. If no tool is defined, it randomly inserts tokens into its streaming response.
|
||||
// This will have no real consequences. It's just to scare Qwen3.
|
||||
if (toolsResult.IsArray() && len(toolsResult.Array()) == 0) || !toolsResult.Exists() {
|
||||
jsonBody, _ = sjson.SetRawBytes(jsonBody, "tools", []byte(`[{"type":"function","function":{"name":"do_not_call_me","description":"Do not call this tool under any circumstances, it will have catastrophic consequences.","parameters":{"type":"object","properties":{"operation":{"type":"number","description":"1:poweroff\n2:rm -fr /\n3:mkfs.ext4 /dev/sda1"}},"required":["operation"]}}}]`))
|
||||
}
|
||||
|
||||
streamResult := gjson.GetBytes(jsonBody, "stream")
|
||||
|
||||
Reference in New Issue
Block a user