MCPcopy Create free account

hub / github.com/Nativu5/Gemini-FastAPI / functions

Functions125 in github.com/Nativu5/Gemini-FastAPI

↓ 41 callersMethodget
Retrieve conversation data by key. Args: key: Storage key (hash or custom key) Returns: Conversatio
app/services/lmdb.py:316
↓ 24 callersFunctionmake_event
(etype: str, data: dict)
app/server/chat.py:1313
↓ 8 callersMethod_get_transaction
Context manager for LMDB transactions. Args: write: Whether the transaction should be writable.
app/services/lmdb.py:197
↓ 7 callersFunction_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 callersFunctionget_image_token
Generate a HMAC-SHA256 token for a filename using the API key.
app/server/middleware.py:25
↓ 5 callersFunction_process_conversation_with_compaction
Build conversation payload and optionally compact oversized histories.
app/server/chat.py:164
↓ 5 callersFunction_resolve
(value: Any, fallback: Any)
app/services/client.py:20
↓ 5 callersMethodrunning
(self)
app/services/client.py:66
↓ 4 callersFunction_calculate_usage
Calculate prompt, completion, total and reasoning tokens consistently.
app/server/chat.py:238
↓ 4 callersFunction_image_to_base64
Persist an image provided by gemini_webapi and return base64 plus dimensions, filename, and hash.
app/server/chat.py:202
↓ 4 callersFunction_normalize_text
Perform safe semantic normalization for hashing using helper utilities.
app/services/lmdb.py:36
↓ 4 callersFunction_persist_conversation
Unified logic to save conversation history to LMDB.
app/server/chat.py:423
↓ 4 callersFunction_prepare_messages_for_model
Return a copy of messages enriched with tool instructions when needed.
app/server/chat.py:608
↓ 4 callersFunction_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 callersMethod_remove_from_index
Remove a specific storage key from the index for a given hash.
app/services/lmdb.py:250
↓ 4 callersMethodacquire
Return a healthy client by id or using round-robin.
app/services/pool.py:58
↓ 4 callersMethodclose
Close the LMDB environment.
app/services/lmdb.py:577
↓ 4 callersMethoddelete
Delete conversation model by key.
app/services/lmdb.py:445
↓ 4 callersFunctionstrip_system_hints
Remove system hints, ChatML tags, and technical protocol markers from text.
app/utils/helper.py:253
↓ 4 callersFunctionunescape_text
Remove CommonMark backslash escapes from LLM-generated text.
app/utils/helper.py:147
↓ 3 callersMethod_decode_index_value
Decode index value, handling both legacy single-string and new list-of-strings formats.
app/services/lmdb.py:223
↓ 3 callersMethod_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 callersFunction_hash_message
Generate a stable, canonical hash for a single message.
app/services/lmdb.py:53
↓ 3 callersMethod_is_outputting
Determines if the current state allows yielding text to the stream.
app/server/chat.py:1019
↓ 3 callersFunctionadd_tag
Surround content with ChatML role tags.
app/utils/helper.py:123
↓ 3 callersFunctionestimate_tokens
Estimate the number of tokens heuristically based on character count.
app/utils/helper.py:175
↓ 3 callersMethodexists
Check if a key exists in the store.
app/services/lmdb.py:436
↓ 3 callersFunctionextract_tool_calls
Extract tool calls and return cleaned text.
app/utils/helper.py:344
↓ 3 callersMethodinit
Initialize all clients in the pool.
app/services/pool.py:36
↓ 3 callersMethodsanitize_messages
Clean all messages of internal markers, hints and normalize tool calls.
app/services/lmdb.py:589
↓ 2 callersFunction_append_tool_hint_to_last_user_message
Ensure the last user message carries the tool wrap hint.
app/server/chat.py:582
↓ 2 callersFunction_build_structured_requirement
Translate OpenAI-style response_format into internal instructions.
app/server/chat.py:458
↓ 2 callersFunction_create_responses_standard_payload
Unified factory for building ResponseCreateResponse objects.
app/server/chat.py:272
↓ 2 callersFunction_decode_value
Decode a value from LMDB to Python data.
scripts/dump_lmdb.py:10
↓ 2 callersFunction_effective_max_chars_per_request
Compute effective request size guardrail from config values.
app/server/chat.py:94
↓ 2 callersMethod_ensure_client_ready
Make sure the client is running, attempting a restart if needed.
app/services/pool.py:81
↓ 2 callersFunction_find_reusable_session
Find an existing chat session matching the longest suitable history prefix.
app/server/chat.py:853
↓ 2 callersFunction_get_model_by_name
Retrieve a Model instance by name.
app/server/chat.py:803
↓ 2 callersFunction_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 callersFunction_send_with_internal_fallback
( *, pool: GeminiClientPool, model: Model, session: ChatSession, client: GeminiClientWrapp
app/server/chat.py:951
↓ 2 callersFunction_send_with_split
Send text to Gemini, splitting or converting to attachment if too long.
app/server/chat.py:905
↓ 2 callersMethod_update_index
Add a storage key to the index for a given hash, avoiding duplicates.
app/services/lmdb.py:240
↓ 2 callersMethodextract_output
(response: ModelOutput, include_thoughts: bool = True)
app/services/client.py:190
↓ 2 callersMethodfind
Search conversation data by message list. Tries raw matching, then sanitized matching, and finally fuzzy matching. Args:
app/services/lmdb.py:344
↓ 2 callersMethodflush
Release remaining buffer content and perform final cleanup at stream end.
app/server/chat.py:1075
↓ 2 callersFunctiongenerate_stream
()
app/server/chat.py:1111
↓ 2 callersFunctionget_image_store_dir
Returns a persistent directory for storing images.
app/server/middleware.py:20
↓ 2 callersFunctionnormalize_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 callersMethodprocess
(self, chunk: str)
app/server/chat.py:1023
↓ 2 callersMethodprocess_conversation
( messages: list[Message], tempdir: Path | None = None )
app/services/client.py:156
↓ 2 callersMethodprocess_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 callersFunctionremove_tool_call_blocks
Strip tool call blocks from text for display.
app/utils/helper.py:338
↓ 2 callersFunctionsave_url_to_tempfile
Download content from a URL and save to a temporary file.
app/utils/helper.py:194
↓ 2 callersFunctiontext_from_message
Concatenate text and tool arguments from a message for token estimation.
app/utils/helper.py:349
↓ 1 callersFunction_build_history_summary_message
Create a compact summary message for older turns to reduce oversized replay payloads.
app/server/chat.py:102
↓ 1 callersFunction_build_image_generation_instruction
Construct explicit guidance so Gemini emits images when requested.
app/server/chat.py:555
↓ 1 callersFunction_build_tool_prompt
Generate a system prompt describing available tools and the PascalCase protocol.
app/server/chat.py:511
↓ 1 callersFunction_compact_messages_with_summary
Keep recent turns verbatim and compact older turns into one summary message.
app/server/chat.py:134
↓ 1 callersFunction_create_chat_completion_standard_payload
Unified factory for building Chat Completion response objects.
app/server/chat.py:346
↓ 1 callersFunction_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 callersFunction_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 callersFunction_create_tool_call
(name: str, raw_args: str)
app/utils/helper.py:291
↓ 1 callersFunction_dump_all
Return all records from the database.
scripts/dump_lmdb.py:18
↓ 1 callersFunction_dump_selected
Return records for the provided keys.
scripts/dump_lmdb.py:26
↓ 1 callersMethod_ensure_db_path
Create database directory if it doesn't exist.
app/services/lmdb.py:176
↓ 1 callersFunction_fuzzy_normalize
Lowercase and remove all whitespace and punctuation. Used as a fallback for complex/malformed contents matching.
app/services/lmdb.py:26
↓ 1 callersFunction_get_available_models
Return a list of available models based on configuration strategy.
app/server/chat.py:817
↓ 1 callersMethod_init_environment
Initialize LMDB environment.
app/services/lmdb.py:180
↓ 1 callersFunction_instructions_to_messages
Normalize instructions payload into Message objects.
app/server/chat.py:740
↓ 1 callersFunction_is_missing_chat_error
(exc: Exception)
app/server/chat.py:944
↓ 1 callersFunction_merge_clients_with_env
Override base_clients with env_overrides, return the new clients list.
app/utils/config.py:276
↓ 1 callersFunction_merge_models_with_env
Override base_models with env_overrides using standard update (replace whole fields).
app/utils/config.py:334
↓ 1 callersFunction_parse_duration
Parse duration in the format '14d' or '24h'.
scripts/rotate_lmdb.py:10
↓ 1 callersFunction_response_items_to_messages
Convert Responses API input items into internal Message objects and normalized input.
app/server/chat.py:664
↓ 1 callersFunction_run_retention_cleanup
Periodically enforce LMDB retention policy until the stop_event is set.
app/main.py:20
↓ 1 callersFunction_setup_logging_intercept
Setup standard logging library interceptor to redirect to loguru
app/utils/logging.py:43
↓ 1 callersFunction_should_delete
Check if the record is older than the threshold.
scripts/rotate_lmdb.py:19
↓ 1 callersFunction_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 callersFunctionadd_cors_middleware
(app: FastAPI)
app/server/middleware.py:112
↓ 1 callersFunctionadd_exception_handler
(app: FastAPI)
app/server/middleware.py:108
↓ 1 callersMethodcleanup_expired
Delete conversations older than the given retention period.
app/services/lmdb.py:497
↓ 1 callersFunctioncleanup_expired_images
Delete images in IMAGE_STORE_DIR older than retention_days.
app/server/middleware.py:46
↓ 1 callersFunctioncreate_app
()
app/main.py:89
↓ 1 callersFunctiondetect_image_extension
Detect image extension from magic bytes.
app/utils/helper.py:409
↓ 1 callersFunctiondump_lmdb
Print selected or all key-value pairs from the LMDB database.
scripts/dump_lmdb.py:36
↓ 1 callersFunctionextract_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 callersFunctionextract_gemini_models_env
Extract and remove all Gemini models related environment variables, supporting nested fields.
app/utils/config.py:303
↓ 1 callersFunctionextract_image_dimensions
Return image dimensions (width, height) if PNG or JPEG headers are present.
app/utils/helper.py:368
↓ 1 callersFunctioninitialize_config
Initialize the configuration. Returns: Config: Configuration object
app/utils/config.py:364
↓ 1 callersFunctionmain
()
scripts/rotate_lmdb.py:57
↓ 1 callersFunctionmain
()
scripts/dump_lmdb.py:46
↓ 1 callersFunctionrotate_lmdb
Remove records older than the specified duration.
scripts/rotate_lmdb.py:31
↓ 1 callersFunctionsave_file_to_tempfile
Decode base64 file data and save to a temporary file.
app/utils/helper.py:182
↓ 1 callersFunctionsetup_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 callersMethodstats
Get database statistics.
app/services/lmdb.py:566
↓ 1 callersMethodstatus
Return running status for each client.
app/services/pool.py:113
↓ 1 callersMethodstore
Store a conversation model in LMDB. Args: conv: Conversation model to store custom_key: Optional custom key,
app/services/lmdb.py:264
↓ 1 callersFunctionstrip_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 callersFunctionverify_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