mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-05-12 02:19:59 +08:00
将 StreamOptimizer 中的硬编码参数改为通过配置文件可配置的参数,提高了系统的灵活性。具体修改包括: 在 .env.example 中添加 stream_optimizer 相关配置参数 在 app/core/config.py 中添加对应的配置项 修改 app/services/chat/stream_optimizer.py 从配置中读取参数 在 README.md 中添加流式输出优化配置的详细说明
38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
from pydantic_settings import BaseSettings
|
|
from typing import List
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
API_KEYS: List[str]
|
|
ALLOWED_TOKENS: List[str]
|
|
BASE_URL: str = "https://generativelanguage.googleapis.com/v1beta"
|
|
MODEL_SEARCH: List[str] = ["gemini-2.0-flash-exp"]
|
|
TOOLS_CODE_EXECUTION_ENABLED: bool = False
|
|
SHOW_SEARCH_LINK: bool = True
|
|
SHOW_THINKING_PROCESS: bool = True
|
|
AUTH_TOKEN: str = ""
|
|
MAX_FAILURES: int = 3
|
|
PAID_KEY: str = ""
|
|
CREATE_IMAGE_MODEL: str = "imagen-3.0-generate-002"
|
|
UPLOAD_PROVIDER: str = "smms"
|
|
SMMS_SECRET_TOKEN: str = ""
|
|
TEST_MODEL: str = "gemini-1.5-flash"
|
|
|
|
# 流式输出优化器配置
|
|
STREAM_MIN_DELAY: float = 0.016
|
|
STREAM_MAX_DELAY: float = 0.024
|
|
STREAM_SHORT_TEXT_THRESHOLD: int = 10
|
|
STREAM_LONG_TEXT_THRESHOLD: int = 50
|
|
STREAM_CHUNK_SIZE: int = 5
|
|
|
|
def __init__(self):
|
|
super().__init__()
|
|
if not self.AUTH_TOKEN:
|
|
self.AUTH_TOKEN = self.ALLOWED_TOKENS[0] if self.ALLOWED_TOKENS else ""
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
|
|
|
|
settings = Settings()
|