Code
Hub
Workspaces
Following
Trending
Connect
MCP
copy
Create free account
hub
/
github.com/Nativu5/Gemini-FastAPI
/ functions
Functions
125 in github.com/Nativu5/Gemini-FastAPI
⨍
Functions
125
◇
Types & classes
50
↳
Endpoints
5
↓ 41 callers
Method
get
Retrieve conversation data by key. Args: key: Storage key (hash or custom key) Returns: Conversatio
app/services/lmdb.py:316
↓ 24 callers
Function
make_event
(etype: str, data: dict)
app/server/chat.py:1313
↓ 8 callers
Method
_get_transaction
Context manager for LMDB transactions. Args: write: Whether the transaction should be writable.
app/services/lmdb.py:197
↓ 7 callers
Function
_hash_conversation
Generate a hash for a list of messages and model name, tied to a specific client_id.
app/services/lmdb.py:128
↓ 6 callers
Function
get_image_token
Generate a HMAC-SHA256 token for a filename using the API key.
app/server/middleware.py:25
↓ 5 callers
Function
_process_conversation_with_compaction
Build conversation payload and optionally compact oversized histories.
app/server/chat.py:164
↓ 5 callers
Function
_resolve
(value: Any, fallback: Any)
app/services/client.py:20
↓ 5 callers
Method
running
(self)
app/services/client.py:66
↓ 4 callers
Function
_calculate_usage
Calculate prompt, completion, total and reasoning tokens consistently.
app/server/chat.py:238
↓ 4 callers
Function
_image_to_base64
Persist an image provided by gemini_webapi and return base64 plus dimensions, filename, and hash.
app/server/chat.py:202
↓ 4 callers
Function
_normalize_text
Perform safe semantic normalization for hashing using helper utilities.
app/services/lmdb.py:36
↓ 4 callers
Function
_persist_conversation
Unified logic to save conversation history to LMDB.
app/server/chat.py:423
↓ 4 callers
Function
_prepare_messages_for_model
Return a copy of messages enriched with tool instructions when needed.
app/server/chat.py:608
↓ 4 callers
Function
_process_llm_output
Post-process Gemini output to extract tool calls and prepare clean text for display and storage. Returns: (thoughts, visible_text, storage_ou
app/server/chat.py:385
↓ 4 callers
Method
_remove_from_index
Remove a specific storage key from the index for a given hash.
app/services/lmdb.py:250
↓ 4 callers
Method
acquire
Return a healthy client by id or using round-robin.
app/services/pool.py:58
↓ 4 callers
Method
close
Close the LMDB environment.
app/services/lmdb.py:577
↓ 4 callers
Method
delete
Delete conversation model by key.
app/services/lmdb.py:445
↓ 4 callers
Function
strip_system_hints
Remove system hints, ChatML tags, and technical protocol markers from text.
app/utils/helper.py:253
↓ 4 callers
Function
unescape_text
Remove CommonMark backslash escapes from LLM-generated text.
app/utils/helper.py:147
↓ 3 callers
Method
_decode_index_value
Decode index value, handling both legacy single-string and new list-of-strings formats.
app/services/lmdb.py:223
↓ 3 callers
Method
_find_by_message_list
Internal find implementation based on a message list. Args: model: Model name messages: Message list to hash
app/services/lmdb.py:381
↓ 3 callers
Function
_hash_message
Generate a stable, canonical hash for a single message.
app/services/lmdb.py:53
↓ 3 callers
Method
_is_outputting
Determines if the current state allows yielding text to the stream.
app/server/chat.py:1019
↓ 3 callers
Function
add_tag
Surround content with ChatML role tags.
app/utils/helper.py:123
↓ 3 callers
Function
estimate_tokens
Estimate the number of tokens heuristically based on character count.
app/utils/helper.py:175
↓ 3 callers
Method
exists
Check if a key exists in the store.
app/services/lmdb.py:436
↓ 3 callers
Function
extract_tool_calls
Extract tool calls and return cleaned text.
app/utils/helper.py:344
↓ 3 callers
Method
init
Initialize all clients in the pool.
app/services/pool.py:36
↓ 3 callers
Method
sanitize_messages
Clean all messages of internal markers, hints and normalize tool calls.
app/services/lmdb.py:589
↓ 2 callers
Function
_append_tool_hint_to_last_user_message
Ensure the last user message carries the tool wrap hint.
app/server/chat.py:582
↓ 2 callers
Function
_build_structured_requirement
Translate OpenAI-style response_format into internal instructions.
app/server/chat.py:458
↓ 2 callers
Function
_create_responses_standard_payload
Unified factory for building ResponseCreateResponse objects.
app/server/chat.py:272
↓ 2 callers
Function
_decode_value
Decode a value from LMDB to Python data.
scripts/dump_lmdb.py:10
↓ 2 callers
Function
_effective_max_chars_per_request
Compute effective request size guardrail from config values.
app/server/chat.py:94
↓ 2 callers
Method
_ensure_client_ready
Make sure the client is running, attempting a restart if needed.
app/services/pool.py:81
↓ 2 callers
Function
_find_reusable_session
Find an existing chat session matching the longest suitable history prefix.
app/server/chat.py:853
↓ 2 callers
Function
_get_model_by_name
Retrieve a Model instance by name.
app/server/chat.py:803
↓ 2 callers
Function
_process_tools_internal
Extract tool metadata and return text stripped of technical markers. Arguments are parsed into JSON and assigned deterministic call IDs.
app/utils/helper.py:281
↓ 2 callers
Function
_send_with_internal_fallback
( *, pool: GeminiClientPool, model: Model, session: ChatSession, client: GeminiClientWrapp
app/server/chat.py:951
↓ 2 callers
Function
_send_with_split
Send text to Gemini, splitting or converting to attachment if too long.
app/server/chat.py:905
↓ 2 callers
Method
_update_index
Add a storage key to the index for a given hash, avoiding duplicates.
app/services/lmdb.py:240
↓ 2 callers
Method
extract_output
(response: ModelOutput, include_thoughts: bool = True)
app/services/client.py:190
↓ 2 callers
Method
find
Search conversation data by message list. Tries raw matching, then sanitized matching, and finally fuzzy matching. Args:
app/services/lmdb.py:344
↓ 2 callers
Method
flush
Release remaining buffer content and perform final cleanup at stream end.
app/server/chat.py:1075
↓ 2 callers
Function
generate_stream
()
app/server/chat.py:1111
↓ 2 callers
Function
get_image_store_dir
Returns a persistent directory for storing images.
app/server/middleware.py:20
↓ 2 callers
Function
normalize_llm_text
Safely normalize LLM-generated text for both display and hashing. Includes: HTML unescaping, NFC normalization, and line ending standardizati
app/utils/helper.py:132
↓ 2 callers
Method
process
(self, chunk: str)
app/server/chat.py:1023
↓ 2 callers
Method
process_conversation
( messages: list[Message], tempdir: Path | None = None )
app/services/client.py:156
↓ 2 callers
Method
process_message
Process a Message into Gemini API format using the PascalCase technical protocol. Extracts text, handles files, and appends ToolCalls
app/services/client.py:70
↓ 2 callers
Function
remove_tool_call_blocks
Strip tool call blocks from text for display.
app/utils/helper.py:338
↓ 2 callers
Function
save_url_to_tempfile
Download content from a URL and save to a temporary file.
app/utils/helper.py:194
↓ 2 callers
Function
text_from_message
Concatenate text and tool arguments from a message for token estimation.
app/utils/helper.py:349
↓ 1 callers
Function
_build_history_summary_message
Create a compact summary message for older turns to reduce oversized replay payloads.
app/server/chat.py:102
↓ 1 callers
Function
_build_image_generation_instruction
Construct explicit guidance so Gemini emits images when requested.
app/server/chat.py:555
↓ 1 callers
Function
_build_tool_prompt
Generate a system prompt describing available tools and the PascalCase protocol.
app/server/chat.py:511
↓ 1 callers
Function
_compact_messages_with_summary
Keep recent turns verbatim and compact older turns into one summary message.
app/server/chat.py:134
↓ 1 callers
Function
_create_chat_completion_standard_payload
Unified factory for building Chat Completion response objects.
app/server/chat.py:346
↓ 1 callers
Function
_create_real_streaming_response
Create a real-time streaming response. Reconciles manual delta accumulation with the model's final authoritative state.
app/server/chat.py:1093
↓ 1 callers
Function
_create_responses_real_streaming_response
Create a real-time streaming response for the Responses API. Ensures final accumulated text and thoughts are synchronized and follow the form
app/server/chat.py:1284
↓ 1 callers
Function
_create_tool_call
(name: str, raw_args: str)
app/utils/helper.py:291
↓ 1 callers
Function
_dump_all
Return all records from the database.
scripts/dump_lmdb.py:18
↓ 1 callers
Function
_dump_selected
Return records for the provided keys.
scripts/dump_lmdb.py:26
↓ 1 callers
Method
_ensure_db_path
Create database directory if it doesn't exist.
app/services/lmdb.py:176
↓ 1 callers
Function
_fuzzy_normalize
Lowercase and remove all whitespace and punctuation. Used as a fallback for complex/malformed contents matching.
app/services/lmdb.py:26
↓ 1 callers
Function
_get_available_models
Return a list of available models based on configuration strategy.
app/server/chat.py:817
↓ 1 callers
Method
_init_environment
Initialize LMDB environment.
app/services/lmdb.py:180
↓ 1 callers
Function
_instructions_to_messages
Normalize instructions payload into Message objects.
app/server/chat.py:740
↓ 1 callers
Function
_is_missing_chat_error
(exc: Exception)
app/server/chat.py:944
↓ 1 callers
Function
_merge_clients_with_env
Override base_clients with env_overrides, return the new clients list.
app/utils/config.py:276
↓ 1 callers
Function
_merge_models_with_env
Override base_models with env_overrides using standard update (replace whole fields).
app/utils/config.py:334
↓ 1 callers
Function
_parse_duration
Parse duration in the format '14d' or '24h'.
scripts/rotate_lmdb.py:10
↓ 1 callers
Function
_response_items_to_messages
Convert Responses API input items into internal Message objects and normalized input.
app/server/chat.py:664
↓ 1 callers
Function
_run_retention_cleanup
Periodically enforce LMDB retention policy until the stop_event is set.
app/main.py:20
↓ 1 callers
Function
_setup_logging_intercept
Setup standard logging library interceptor to redirect to loguru
app/utils/logging.py:43
↓ 1 callers
Function
_should_delete
Check if the record is older than the threshold.
scripts/rotate_lmdb.py:19
↓ 1 callers
Function
_strip_param_fences
Remove one layer of outermost Markdown code fences, supporting nested blocks by detecting variable fence lengths.
app/utils/helper.py:154
↓ 1 callers
Function
add_cors_middleware
(app: FastAPI)
app/server/middleware.py:112
↓ 1 callers
Function
add_exception_handler
(app: FastAPI)
app/server/middleware.py:108
↓ 1 callers
Method
cleanup_expired
Delete conversations older than the given retention period.
app/services/lmdb.py:497
↓ 1 callers
Function
cleanup_expired_images
Delete images in IMAGE_STORE_DIR older than retention_days.
app/server/middleware.py:46
↓ 1 callers
Function
create_app
()
app/main.py:89
↓ 1 callers
Function
detect_image_extension
Detect image extension from magic bytes.
app/utils/helper.py:409
↓ 1 callers
Function
dump_lmdb
Print selected or all key-value pairs from the LMDB database.
scripts/dump_lmdb.py:36
↓ 1 callers
Function
extract_gemini_clients_env
Extract and remove all Gemini clients related environment variables, return a mapping from index to field dict.
app/utils/config.py:254
↓ 1 callers
Function
extract_gemini_models_env
Extract and remove all Gemini models related environment variables, supporting nested fields.
app/utils/config.py:303
↓ 1 callers
Function
extract_image_dimensions
Return image dimensions (width, height) if PNG or JPEG headers are present.
app/utils/helper.py:368
↓ 1 callers
Function
initialize_config
Initialize the configuration. Returns: Config: Configuration object
app/utils/config.py:364
↓ 1 callers
Function
main
()
scripts/rotate_lmdb.py:57
↓ 1 callers
Function
main
()
scripts/dump_lmdb.py:46
↓ 1 callers
Function
rotate_lmdb
Remove records older than the specified duration.
scripts/rotate_lmdb.py:31
↓ 1 callers
Function
save_file_to_tempfile
Decode base64 file data and save to a temporary file.
app/utils/helper.py:182
↓ 1 callers
Function
setup_logging
Setup loguru logging configuration to unify all project logging output Args: level: Log level diagnose: Whether to enable di
app/utils/logging.py:9
↓ 1 callers
Method
stats
Get database statistics.
app/services/lmdb.py:566
↓ 1 callers
Method
status
Return running status for each client.
app/services/pool.py:113
↓ 1 callers
Method
store
Store a conversation model in LMDB. Args: conv: Conversation model to store custom_key: Optional custom key,
app/services/lmdb.py:264
↓ 1 callers
Function
strip_tagged_blocks
Remove ChatML role blocks (<|im_start|>role...<|im_end|>). Role 'tool' blocks are removed entirely; others have markers stripped but content
app/utils/helper.py:220
↓ 1 callers
Function
verify_image_token
Verify the provided token against the filename.
app/server/middleware.py:36
Method
__call__
(cls, *args, **kwargs)
app/utils/singleton.py:7
next →
1–100 of 125, ranked by callers