fix: nano banana pro 4k(StreamScannerMaxBufferMB env)
This commit is contained in:
@@ -303,6 +303,7 @@ docker run --name new-api -d --restart always \
|
|||||||
| `SQL_DSN` | Database connection string | - |
|
| `SQL_DSN` | Database connection string | - |
|
||||||
| `REDIS_CONN_STRING` | Redis connection string | - |
|
| `REDIS_CONN_STRING` | Redis connection string | - |
|
||||||
| `STREAMING_TIMEOUT` | Streaming timeout (seconds) | `300` |
|
| `STREAMING_TIMEOUT` | Streaming timeout (seconds) | `300` |
|
||||||
|
| `STREAM_SCANNER_MAX_BUFFER_MB` | Max per-line buffer (MB) for the stream scanner; increase when upstream sends huge image/base64 payloads | `64` |
|
||||||
| `AZURE_DEFAULT_API_VERSION` | Azure API version | `2025-04-01-preview` |
|
| `AZURE_DEFAULT_API_VERSION` | Azure API version | `2025-04-01-preview` |
|
||||||
| `ERROR_LOG_ENABLED` | Error log switch | `false` |
|
| `ERROR_LOG_ENABLED` | Error log switch | `false` |
|
||||||
|
|
||||||
|
|||||||
@@ -299,6 +299,7 @@ docker run --name new-api -d --restart always \
|
|||||||
| `SQL_DSN` | Chaine de connexion à la base de données | - |
|
| `SQL_DSN` | Chaine de connexion à la base de données | - |
|
||||||
| `REDIS_CONN_STRING` | Chaine de connexion Redis | - |
|
| `REDIS_CONN_STRING` | Chaine de connexion Redis | - |
|
||||||
| `STREAMING_TIMEOUT` | Délai d'expiration du streaming (secondes) | `300` |
|
| `STREAMING_TIMEOUT` | Délai d'expiration du streaming (secondes) | `300` |
|
||||||
|
| `STREAM_SCANNER_MAX_BUFFER_MB` | Taille max du buffer par ligne (Mo) pour le scanner SSE ; à augmenter quand les sorties image/base64 sont très volumineuses (ex. images 4K) | `64` |
|
||||||
| `AZURE_DEFAULT_API_VERSION` | Version de l'API Azure | `2025-04-01-preview` |
|
| `AZURE_DEFAULT_API_VERSION` | Version de l'API Azure | `2025-04-01-preview` |
|
||||||
| `ERROR_LOG_ENABLED` | Interrupteur du journal d'erreurs | `false` |
|
| `ERROR_LOG_ENABLED` | Interrupteur du journal d'erreurs | `false` |
|
||||||
|
|
||||||
|
|||||||
@@ -308,6 +308,7 @@ docker run --name new-api -d --restart always \
|
|||||||
| `SQL_DSN** | データベース接続文字列 | - |
|
| `SQL_DSN** | データベース接続文字列 | - |
|
||||||
| `REDIS_CONN_STRING` | Redis接続文字列 | - |
|
| `REDIS_CONN_STRING` | Redis接続文字列 | - |
|
||||||
| `STREAMING_TIMEOUT` | ストリーミング応答のタイムアウト時間(秒) | `300` |
|
| `STREAMING_TIMEOUT` | ストリーミング応答のタイムアウト時間(秒) | `300` |
|
||||||
|
| `STREAM_SCANNER_MAX_BUFFER_MB` | ストリームスキャナの1行あたりバッファ上限(MB)。4K画像など巨大なbase64 `data:` ペイロードを扱う場合は値を増加させてください | `64` |
|
||||||
| `AZURE_DEFAULT_API_VERSION` | Azure APIバージョン | `2025-04-01-preview` |
|
| `AZURE_DEFAULT_API_VERSION` | Azure APIバージョン | `2025-04-01-preview` |
|
||||||
| `ERROR_LOG_ENABLED` | エラーログスイッチ | `false` |
|
| `ERROR_LOG_ENABLED` | エラーログスイッチ | `false` |
|
||||||
|
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -297,15 +297,16 @@ docker run --name new-api -d --restart always \
|
|||||||
<details>
|
<details>
|
||||||
<summary>常用环境变量配置</summary>
|
<summary>常用环境变量配置</summary>
|
||||||
|
|
||||||
| 变量名 | 说明 | 默认值 |
|
| 变量名 | 说明 | 默认值 |
|
||||||
|--------|------|--------|
|
|--------|--------------------------------------------------------------|--------|
|
||||||
| `SESSION_SECRET` | 会话密钥(多机部署必须) | - |
|
| `SESSION_SECRET` | 会话密钥(多机部署必须) | - |
|
||||||
| `CRYPTO_SECRET` | 加密密钥(Redis 必须) | - |
|
| `CRYPTO_SECRET` | 加密密钥(Redis 必须) | - |
|
||||||
| `SQL_DSN` | 数据库连接字符串 | - |
|
| `SQL_DSN` | 数据库连接字符串 | - |
|
||||||
| `REDIS_CONN_STRING` | Redis 连接字符串 | - |
|
| `REDIS_CONN_STRING` | Redis 连接字符串 | - |
|
||||||
| `STREAMING_TIMEOUT` | 流式超时时间(秒) | `300` |
|
| `STREAMING_TIMEOUT` | 流式超时时间(秒) | `300` |
|
||||||
| `AZURE_DEFAULT_API_VERSION` | Azure API 版本 | `2025-04-01-preview` |
|
| `STREAM_SCANNER_MAX_BUFFER_MB` | 流式扫描器单行最大缓冲(MB),图像生成等超大 `data:` 片段(如 4K 图片 base64)需适当调大 | `64` |
|
||||||
| `ERROR_LOG_ENABLED` | 错误日志开关 | `false` |
|
| `AZURE_DEFAULT_API_VERSION` | Azure API 版本 | `2025-04-01-preview` |
|
||||||
|
| `ERROR_LOG_ENABLED` | 错误日志开关 | `false` |
|
||||||
|
|
||||||
📖 **完整配置:** [环境变量文档](https://docs.newapi.pro/installation/environment-variables)
|
📖 **完整配置:** [环境变量文档](https://docs.newapi.pro/installation/environment-variables)
|
||||||
|
|
||||||
|
|||||||
@@ -114,6 +114,7 @@ func initConstantEnv() {
|
|||||||
constant.StreamingTimeout = GetEnvOrDefault("STREAMING_TIMEOUT", 300)
|
constant.StreamingTimeout = GetEnvOrDefault("STREAMING_TIMEOUT", 300)
|
||||||
constant.DifyDebug = GetEnvOrDefaultBool("DIFY_DEBUG", true)
|
constant.DifyDebug = GetEnvOrDefaultBool("DIFY_DEBUG", true)
|
||||||
constant.MaxFileDownloadMB = GetEnvOrDefault("MAX_FILE_DOWNLOAD_MB", 20)
|
constant.MaxFileDownloadMB = GetEnvOrDefault("MAX_FILE_DOWNLOAD_MB", 20)
|
||||||
|
constant.StreamScannerMaxBufferMB = GetEnvOrDefault("STREAM_SCANNER_MAX_BUFFER_MB", 64)
|
||||||
// ForceStreamOption 覆盖请求参数,强制返回usage信息
|
// ForceStreamOption 覆盖请求参数,强制返回usage信息
|
||||||
constant.ForceStreamOption = GetEnvOrDefaultBool("FORCE_STREAM_OPTION", true)
|
constant.ForceStreamOption = GetEnvOrDefaultBool("FORCE_STREAM_OPTION", true)
|
||||||
constant.CountToken = GetEnvOrDefaultBool("CountToken", true)
|
constant.CountToken = GetEnvOrDefaultBool("CountToken", true)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package constant
|
|||||||
var StreamingTimeout int
|
var StreamingTimeout int
|
||||||
var DifyDebug bool
|
var DifyDebug bool
|
||||||
var MaxFileDownloadMB int
|
var MaxFileDownloadMB int
|
||||||
|
var StreamScannerMaxBufferMB int
|
||||||
var ForceStreamOption bool
|
var ForceStreamOption bool
|
||||||
var CountToken bool
|
var CountToken bool
|
||||||
var GetMediaToken bool
|
var GetMediaToken bool
|
||||||
|
|||||||
@@ -22,11 +22,18 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
InitialScannerBufferSize = 64 << 10 // 64KB (64*1024)
|
InitialScannerBufferSize = 64 << 10 // 64KB (64*1024)
|
||||||
MaxScannerBufferSize = 10 << 20 // 10MB (10*1024*1024)
|
DefaultMaxScannerBufferSize = 64 << 20 // 64MB (64*1024*1024) default SSE buffer size
|
||||||
DefaultPingInterval = 10 * time.Second
|
DefaultPingInterval = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func getScannerBufferSize() int {
|
||||||
|
if constant.StreamScannerMaxBufferMB > 0 {
|
||||||
|
return constant.StreamScannerMaxBufferMB << 20
|
||||||
|
}
|
||||||
|
return DefaultMaxScannerBufferSize
|
||||||
|
}
|
||||||
|
|
||||||
func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo, dataHandler func(data string) bool) {
|
func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon.RelayInfo, dataHandler func(data string) bool) {
|
||||||
|
|
||||||
if resp == nil || dataHandler == nil {
|
if resp == nil || dataHandler == nil {
|
||||||
@@ -95,7 +102,7 @@ func StreamScannerHandler(c *gin.Context, resp *http.Response, info *relaycommon
|
|||||||
close(stopChan)
|
close(stopChan)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
scanner.Buffer(make([]byte, InitialScannerBufferSize), MaxScannerBufferSize)
|
scanner.Buffer(make([]byte, InitialScannerBufferSize), getScannerBufferSize())
|
||||||
scanner.Split(bufio.ScanLines)
|
scanner.Split(bufio.ScanLines)
|
||||||
SetEventStreamHeaders(c)
|
SetEventStreamHeaders(c)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user