Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
153 commits
Select commit Hold shift + click to select a range
a3dfe70
Remove the unused auto-refresh functionality and related imports.
luuquangvu Nov 21, 2025
3a692ab
Enhance error handling in client initialization and message sending
luuquangvu Nov 22, 2025
d57e367
Refactor link handling to extract file paths and simplify Google sear…
luuquangvu Nov 22, 2025
ccd55f9
Fix regex pattern for Google search link matching
luuquangvu Nov 22, 2025
37632b3
Fix regex patterns for Markdown escaping, code fence and Google searc…
luuquangvu Nov 22, 2025
b11cfcc
Increase timeout value in configuration files from 60 to 120 seconds …
luuquangvu Nov 22, 2025
f0bff2d
Merge branch 'Nativu5:main' into main
luuquangvu Nov 24, 2025
5b4eaca
Merge branch 'Nativu5:main' into main
luuquangvu Nov 26, 2025
b36a682
Merge branch 'Nativu5:main' into main
luuquangvu Nov 29, 2025
f00ebfc
Fix Image generation
luuquangvu Dec 2, 2025
d911c33
Refactor tool handling to support standard and image generation tools…
luuquangvu Dec 2, 2025
a8241ad
Fix: use "ascii" decoding for base64-encoded image data consistency
luuquangvu Dec 2, 2025
5d55780
Merge branch 'Nativu5:main' into main
luuquangvu Dec 3, 2025
fd2723d
Fix: replace `running` with `_running` for internal client status checks
luuquangvu Dec 3, 2025
8ee6cc0
Refactor: replace direct `_running` access with `running()` method in…
luuquangvu Dec 3, 2025
0be8aef
Merge remote-tracking branch 'upstream/main'
luuquangvu Dec 3, 2025
453700e
Extend models with new fields for annotations, reasoning, audio, log …
luuquangvu Dec 3, 2025
9260f8b
Extend models with new fields (annotations, error), add `normalize_ou…
luuquangvu Dec 3, 2025
d6a8e6b
Extend response models to support tool choices, image output, and imp…
luuquangvu Dec 4, 2025
16435a2
Set default `text` value to an empty string for `ResponseOutputConten…
luuquangvu Dec 4, 2025
fc99c2d
feat: Add /images endpoint with dedicated router and improved image m…
luuquangvu Dec 4, 2025
2844176
feat: Add token-based verification for image access
luuquangvu Dec 4, 2025
4509c14
Refactor: rename image store directory to `ai_generated_images` for c…
luuquangvu Dec 4, 2025
75e2f61
fix: Update create_response to use FastAPI Request object for base_ur…
luuquangvu Dec 4, 2025
bde6d0d
fix: Correct attribute access in request_data handling within `chat.p…
luuquangvu Dec 4, 2025
601451a
fix: Save generated images to persistent storage
luuquangvu Dec 4, 2025
893eb6d
fix: Remove unused `output_image` type from `ResponseOutputContent` a…
luuquangvu Dec 4, 2025
80462b5
fix: Update image URL generation in chat response to use Markdown for…
luuquangvu Dec 4, 2025
af91c4f
Merge branch 'Nativu5:main' into main
luuquangvu Dec 4, 2025
f088b5f
Merge branch 'Nativu5:main' into main
luuquangvu Dec 6, 2025
8d49a72
fix: Enhance error handling for full-size image saving and add fallba…
luuquangvu Dec 8, 2025
d37eae0
fix: Use filename as image ID to ensure consistency in generated imag…
luuquangvu Dec 9, 2025
b9f776d
fix: Enhance tempfile saving by adding custom headers, content-type h…
luuquangvu Dec 16, 2025
4b5fe07
feat: Add support for custom Gemini models and model loading strategies
luuquangvu Dec 30, 2025
5cb29e8
feat: Improve Gemini model environment variable parsing and nested fi…
luuquangvu Dec 30, 2025
f25f16d
refactor: Consolidate utility functions and clean up unused code
luuquangvu Dec 31, 2025
a1bc8e2
fix: Handle None input in `estimate_tokens` and return 0 for empty text
luuquangvu Dec 31, 2025
a7e15d9
refactor: Simplify model configuration and add JSON parsing validators
luuquangvu Dec 31, 2025
61c5f3b
refactor: Simplify Gemini model environment variable parsing with JSO…
luuquangvu Dec 31, 2025
efd056c
fix: Enhance Gemini model environment variable parsing with fallback …
luuquangvu Dec 31, 2025
476b9dd
fix: Improve regex patterns in helper module
luuquangvu Dec 31, 2025
35c1e99
docs: Update README files to include custom model configuration and e…
luuquangvu Jan 13, 2026
9b81621
fix: Remove unused headers from HTTP client in helper module
luuquangvu Jan 13, 2026
32a48dc
fix: Update README and README.zh to clarify model configuration via e…
luuquangvu Jan 15, 2026
0c00b08
Update README and README.zh to clarify model configuration via JSON s…
luuquangvu Jan 15, 2026
e2233f4
Merge branch 'Nativu5:main' into main
luuquangvu Jan 22, 2026
b599d99
Refactor: compress JSON content to save tokens and streamline sending…
luuquangvu Jan 23, 2026
186b844
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 23, 2026
6dd1fec
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 24, 2026
20ed245
Refactor: Update all functions to use orjson for better performance
luuquangvu Jan 24, 2026
f67fe63
Update project dependencies
luuquangvu Jan 24, 2026
889f2d2
Fix IDE warnings
luuquangvu Jan 24, 2026
66b6202
Incorrect IDE warnings
luuquangvu Jan 24, 2026
3297f53
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 24, 2026
5399b26
Refactor: Centralized the mapping of the 'developer' role to 'system'…
luuquangvu Jan 24, 2026
de01c78
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 24, 2026
1964147
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 24, 2026
8c5c749
Refactor: Modify the LMDB store to fix issues where no conversation i…
luuquangvu Jan 24, 2026
ce67d66
Refactor: Avoid reusing an existing chat session if its idle time exc…
luuquangvu Jan 24, 2026
3d32d12
Refactor: Update the LMDB store to resolve issues preventing conversa…
luuquangvu Jan 24, 2026
2eb9f05
Refactor: Update the _prepare_messages_for_model helper to omit the s…
luuquangvu Jan 24, 2026
ade61d6
Refactor: Modify the logic to convert a large prompt into a temporary…
luuquangvu Jan 26, 2026
bdd893f
Enable streaming responses and fully resolve the problem with reusabl…
luuquangvu Jan 28, 2026
a51f75c
Merge branch 'Nativu5:main' into main
luuquangvu Jan 28, 2026
767f0b3
Merge branch 'main' of https://github.com/luuquangvu/Gemini-FastAPI
luuquangvu Jan 28, 2026
52547a9
Enable real-time streaming responses and completely solve the issue w…
luuquangvu Jan 30, 2026
c0b32c6
Enable real-time streaming responses and completely solve the issue w…
luuquangvu Jan 30, 2026
4d51a5f
Enable real-time streaming responses and completely solve the issue w…
luuquangvu Feb 2, 2026
d69aaf0
Enable real-time streaming responses and completely solve the issue w…
luuquangvu Feb 2, 2026
8e15a86
Enable real-time streaming responses and completely solve the issue w…
luuquangvu Feb 2, 2026
7716c62
build: update dependencies
luuquangvu Feb 3, 2026
61672cc
Refactor: Use `strip_system_hints` to standardize the content.
luuquangvu Feb 3, 2026
cc0b13f
Refactor: Only inject code block hint if NOT a structured response re…
luuquangvu Feb 3, 2026
6b90e5d
Refactor: Remove the code block hint entirely
luuquangvu Feb 3, 2026
553bd94
Refactor: Remove the code block hint entirely
luuquangvu Feb 3, 2026
fd767da
Refactor: fix missing whitespace in the streaming response.
luuquangvu Feb 3, 2026
f6b60aa
Merge remote-tracking branch 'upstream/main'
luuquangvu Feb 3, 2026
4beb33b
Refactor: remove unnecessary code
luuquangvu Feb 4, 2026
6b8dd4e
Refactor: Update `StreamingOutputFilter` logic to improve handling of…
luuquangvu Feb 4, 2026
d86ae59
Refactor: Adjust function call format to prevent streaming issues
luuquangvu Feb 4, 2026
db39ad1
Refactor: Adjust function call format to prevent streaming issues
luuquangvu Feb 4, 2026
556a638
Refactor: Adjust function call format to prevent streaming issues
luuquangvu Feb 4, 2026
d5fec7a
Refactor: Adjust function call format to prevent streaming issues
luuquangvu Feb 5, 2026
dbc553d
Refactor: Enhance prompt to prevent issues with parsing tool call arg…
luuquangvu Feb 5, 2026
ca721cf
Refactor: Enhance prompt to prevent issues with parsing tool call arg…
luuquangvu Feb 5, 2026
d3b60c8
Merge branch 'Nativu5:main' into main
luuquangvu Feb 5, 2026
263158e
Refactor: enhance system prompts
luuquangvu Feb 6, 2026
68ce2df
Refactor: Enhance system prompts
luuquangvu Feb 6, 2026
77f7210
Refactor: Enhance system prompts
luuquangvu Feb 6, 2026
3addb2b
Refactor: Enhance system prompts
luuquangvu Feb 7, 2026
2a53eed
fix: missing image extension
luuquangvu Feb 8, 2026
26d39c7
fix: missing image extension
luuquangvu Feb 8, 2026
598b563
fix: missing or duplicate ChatML tags.
luuquangvu Feb 8, 2026
6d563c5
Refactor: Consistently use ChatML tags throughout.
luuquangvu Feb 8, 2026
58db419
Refactor: normalize text before calculating message hash
luuquangvu Feb 9, 2026
d5d1c5a
Refactor: remove unescape helpers to avoid side effects
luuquangvu Feb 9, 2026
a4a987c
Refactor: Implement fuzzy matching to better handle complex data form…
luuquangvu Feb 9, 2026
551eb87
Refactor: Implement fuzzy matching to better handle complex data form…
luuquangvu Feb 9, 2026
b2dbb08
Feat: Add watchdog_timeout parameter
luuquangvu Feb 10, 2026
969cd4a
Update required dependencies
luuquangvu Feb 10, 2026
c258d32
Move `maketrans` to global variable
luuquangvu Feb 10, 2026
157028f
Move `maketrans` to global variable
luuquangvu Feb 10, 2026
5f9a7ec
Refactor: Add a filter to catch orphaned tool calls.
luuquangvu Feb 10, 2026
c81c2ce
Update required dependencies
luuquangvu Feb 10, 2026
a170825
Add dependabot
luuquangvu Feb 10, 2026
a0136af
Refactor: Implement the logic changes recommended by Copilot
luuquangvu Feb 11, 2026
5eb9f50
Refactor: Optimize fuzzy matching logic
luuquangvu Feb 11, 2026
971f2c7
Update dependencies
luuquangvu Feb 11, 2026
cad2379
Refactor: Update Markdown unescape helpers to prevent impacting clien…
luuquangvu Feb 11, 2026
795b8d8
Refactor: Update Markdown unescape helpers to prevent impacting clien…
luuquangvu Feb 11, 2026
e85252a
Revert "Refactor: Update Markdown unescape helpers to prevent impacti…
luuquangvu Feb 12, 2026
4be4150
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
d86798b
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
0d18e9e
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
8fa4329
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
dcd7276
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
737aa3a
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 12, 2026
2c80895
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
9b0e1d5
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
95f87f6
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
4569689
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
5a65cb6
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
8a03c33
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
7ed2132
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
d92bc1c
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
4ecad56
Refactor: Update `unescape_llm_text` to standardize and repair LLM-ge…
luuquangvu Feb 13, 2026
28378b4
Update dependencies
luuquangvu Feb 13, 2026
3fcd01e
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
ef24704
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
4edf4cd
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
dcadabb
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
8390414
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
ce43d63
Refactor: Remove all escape logic handlers.
luuquangvu Feb 13, 2026
8792948
Refactor: Remove all escape logic handlers.
luuquangvu Feb 13, 2026
5482e0c
Refactor: Remove all escape logic handlers.
luuquangvu Feb 13, 2026
b324aef
Revert "Refactor: Remove all escape logic handlers."
luuquangvu Feb 13, 2026
8ef108d
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
30043e5
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
bc888d1
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
d5349a0
Refactor: Rewrite the function call format to match the client's comp…
luuquangvu Feb 13, 2026
7e217e9
Reattempt changing tool call tags to `snake_case`.
luuquangvu Feb 13, 2026
fe30a5d
Revert "Reattempt changing tool call tags to `snake_case`."
luuquangvu Feb 13, 2026
93e9ccd
Refactor: Handle all escape tags
luuquangvu Feb 13, 2026
30f6125
Refactor: Handle all escape tags
luuquangvu Feb 13, 2026
a355252
Refactor: Remove `_strip_google_search` as it's no longer needed
luuquangvu Feb 14, 2026
45af127
Update `TOOL_WRAP_HINT` to ensure Gemini strictly follows the instruc…
luuquangvu Feb 14, 2026
f144e14
Update required dependencies
luuquangvu Feb 14, 2026
4461ca3
Merge branch 'Nativu5:main' into main
luuquangvu Feb 18, 2026
808463f
Merge branch 'Nativu5:main' into main
luuquangvu Feb 18, 2026
9d014b0
Ignore github directory
luuquangvu Feb 18, 2026
3fab502
Upgrade to fully support Python 3.13
luuquangvu Feb 18, 2026
35864f6
Upgrade to fully support Python 3.13
luuquangvu Feb 18, 2026
a48c38d
Upgrade to fully support Python 3.13
luuquangvu Feb 18, 2026
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
9 changes: 7 additions & 2 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ on:
- "v*"
paths-ignore:
- "**/*.md"
- ".github/workflows/ruff.yaml"
- ".github/workflows/track.yml"
- ".github/*"
- "LICENSE"
- ".gitignore"

env:
REGISTRY: ghcr.io
Expand All @@ -26,6 +27,9 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v6

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

Expand All @@ -46,6 +50,7 @@ jobs:
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value={{date 'YYYYMMDD'}}-{{sha}}
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ruff.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: "3.12"
python-version: "3.13"

- name: Install Ruff
run: |
python -m pip install --upgrade pip
pip install "ruff>=0.11.7"
pip install "ruff>=0.15.1"

- name: Run Ruff
run: ruff check .
18 changes: 14 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,26 @@
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim
FROM ghcr.io/astral-sh/uv:python3.13-trixie-slim

LABEL org.opencontainers.image.description="Web-based Gemini models wrapped into an OpenAI-compatible API."

WORKDIR /app

# Install dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
tini \
&& rm -rf /var/lib/apt/lists/*

ENV UV_COMPILE_BYTECODE=1 \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1

COPY pyproject.toml uv.lock ./
RUN uv sync --no-cache --no-dev
RUN uv sync --no-cache --frozen --no-install-project --no-dev

COPY app/ app/
COPY config/ config/
COPY run.py .

# Command to run the application
EXPOSE 8000

ENTRYPOINT ["/usr/bin/tini", "--"]

CMD ["uv", "run", "--no-dev", "run.py"]
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gemini-FastAPI

[![Python 3.12](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![Python 3.13](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-green.svg)](https://fastapi.tiangolo.com/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Expand All @@ -24,7 +24,7 @@ Web-based Gemini models wrapped into an OpenAI-compatible API. Powered by [Hanao

### Prerequisites

- Python 3.12
- Python 3.13
- Google account with Gemini access on web
- `secure_1psid` and `secure_1psidts` cookies from Gemini web interface

Expand Down
4 changes: 2 additions & 2 deletions README.zh.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Gemini-FastAPI

[![Python 3.12](https://img.shields.io/badge/python-3.12+-blue.svg)](https://www.python.org/downloads/)
[![Python 3.13](https://img.shields.io/badge/python-3.13+-blue.svg)](https://www.python.org/downloads/)
[![FastAPI](https://img.shields.io/badge/FastAPI-0.115+-green.svg)](https://fastapi.tiangolo.com/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Expand All @@ -24,7 +24,7 @@

### 前置条件

- Python 3.12
- Python 3.13
- 拥有网页版 Gemini 访问权限的 Google 账号
- 从 Gemini 网页获取的 `secure_1psid` 和 `secure_1psidts` Cookie

Expand Down
2 changes: 1 addition & 1 deletion app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async def _run_retention_cleanup(stop_event: asyncio.Event) -> None:
stop_event.wait(),
timeout=RETENTION_CLEANUP_INTERVAL_SECONDS,
)
except asyncio.TimeoutError:
except TimeoutError:
continue

logger.info("LMDB retention cleanup task stopped.")
Expand Down
60 changes: 59 additions & 1 deletion app/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
from .models import * # noqa: F403
from .models import (
ChatCompletionRequest,
ChatCompletionResponse,
Choice,
ContentItem,
ConversationInStore,
FunctionCall,
HealthCheckResponse,
Message,
ModelData,
ModelListResponse,
ResponseCreateRequest,
ResponseCreateResponse,
ResponseImageGenerationCall,
ResponseImageTool,
ResponseInputContent,
ResponseInputItem,
ResponseOutputContent,
ResponseOutputMessage,
ResponseToolCall,
ResponseToolChoice,
ResponseUsage,
Tool,
ToolCall,
ToolChoiceFunction,
ToolChoiceFunctionDetail,
ToolFunctionDefinition,
Usage,
)

__all__ = [
"ChatCompletionRequest",
"ChatCompletionResponse",
"Choice",
"ContentItem",
"ConversationInStore",
"FunctionCall",
"HealthCheckResponse",
"Message",
"ModelData",
"ModelListResponse",
"ResponseCreateRequest",
"ResponseCreateResponse",
"ResponseImageGenerationCall",
"ResponseImageTool",
"ResponseInputContent",
"ResponseInputItem",
"ResponseOutputContent",
"ResponseOutputMessage",
"ResponseToolCall",
"ResponseToolChoice",
"ResponseUsage",
"Tool",
"ToolCall",
"ToolChoiceFunction",
"ToolChoiceFunctionDetail",
"ToolFunctionDefinition",
"Usage",
]
Loading