Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ __pycache__

.env
config.debug.yaml
data/
data/
# local secrets / host-specific
config/config.yaml
.DS_Store
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,20 @@ export CONFIG_GEMINI__CLIENTS__0__IMPERSONATE="chrome"


# Override conversation storage size limit
export CONFIG_STORAGE__MAX_SIZE=268435456 # 256 MB
export CONFIG_STORAGE__MAX_SIZE=1073741824 # 1 GB

# Override conversation retention (days before automatic cleanup, 0 disables cleanup)
export CONFIG_STORAGE__RETENTION_DAYS=7
```

> [!NOTE]
> The LMDB map size (`storage.max_size`, default 1 GB) is fixed when the store
> opens. When the data file grows to that ceiling every write fails with
> `MDB_MAP_FULL` — the map never grows on its own. If that happens, raise
> `max_size` and **restart** the server; existing data is preserved. The
> 6-hourly cleanup task (main.py) reclaims space once conversations are older
> than `retention_days` (default 7).

### Client IDs and Conversation Reuse

Conversations are stored with the ID of the client that generated them.
Expand Down
2 changes: 1 addition & 1 deletion README.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ export CONFIG_GEMINI__CLIENTS__0__IMPERSONATE="chrome"


# 覆盖对话存储大小限制
export CONFIG_STORAGE__MAX_SIZE=268435456 # 256 MB
export CONFIG_STORAGE__MAX_SIZE=1073741824 # 1 GB
```

### 客户端 ID 与会话重用
Expand Down
20 changes: 20 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
import asyncio
import mimetypes
from contextlib import asynccontextmanager

from fastapi import FastAPI
from loguru import logger

# Canonical audio MIME types: Python's platform mapping yields legacy "x-"
# types (audio/x-wav, audio/x-aac, audio/x-flac) that Google's upload
# endpoint does not classify as audio, so the attached file never reaches
# the model as an audible attachment. Registered before any upload happens.
for _ext, _mime in (
(".wav", "audio/wav"),
(".aac", "audio/aac"),
(".flac", "audio/flac"),
(".m4a", "audio/mp4"),
):
try:
mimetypes.add_type(_mime, _ext)
except ValueError:
pass

from .server.chat import refresh_available_models_cache
from .server.chat import router as chat_router
from .server.gemini import add_gemini_exception_handlers # noqa: E402
from .server.gemini import router as gemini_router # noqa: E402
from .server.health import router as health_router
from .server.media import router as media_router
from .server.middleware import (
Expand Down Expand Up @@ -106,9 +124,11 @@ def create_app() -> FastAPI:

add_cors_middleware(app)
add_exception_handler(app)
add_gemini_exception_handlers(app)

app.include_router(health_router, tags=["Health"])
app.include_router(chat_router, tags=["Chat"])
app.include_router(media_router, tags=["Media"])
app.include_router(gemini_router, tags=["Gemini"])

return app
34 changes: 33 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
# ruff: noqa: F403
# ruff: noqa: F403, F401

from .core import *
from .gemini_models import (
GeminiCandidate,
GeminiCitationMetadata,
GeminiCitationSource,
GeminiContent,
GeminiErrorDetail,
GeminiErrorResponse,
GeminiFileData,
GeminiFunctionCall,
GeminiFunctionCallingConfig,
GeminiFunctionDeclaration,
GeminiFunctionResponse,
GeminiGenerateContentRequest,
GeminiGenerateContentResponse,
GeminiGenerationConfig,
GeminiGroundingChunk,
GeminiGroundingChunkWeb,
GeminiGroundingMetadata,
GeminiGroundingSupport,
GeminiInlineData,
GeminiModelInfo,
GeminiModelListResponse,
GeminiPart,
GeminiSafetyRating,
GeminiSafetySetting,
GeminiSearchEntryPoint,
GeminiSystemInstruction,
GeminiThinkingConfig,
GeminiTool,
GeminiToolConfig,
GeminiUsageMetadata,
)
from .models import *
Loading
Loading