### Install and Run WebAI-to-API Server Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md This sequence of commands guides you through cloning the WebAI-to-API repository, installing its dependencies using Poetry, copying and configuring the example configuration file, and finally running the FastAPI server. ```bash git clone https://github.com/Amm1rr/WebAI-to-API.git cd WebAI-to-API ``` ```bash poetry install ``` ```bash cp config.conf.example config.conf ``` ```bash poetry run python src/run.py ``` -------------------------------- ### Stop Docker Server using Make Source: https://github.com/amm1rr/webai-to-api/blob/master/Docker.md This `make` command provides a simple way to gracefully stop all running Docker containers associated with the project. It ensures that services are shut down cleanly, preventing resource leaks or data corruption. ```bash make stop ``` -------------------------------- ### Run Docker Server using Make Source: https://github.com/amm1rr/webai-to-api/blob/master/Docker.md The `make up` command initiates the Dockerized server. In development mode, it runs in the foreground with hot-reloading enabled. For production, it automatically runs in detached mode with multiple workers, optimizing for performance and stability. ```bash make up ``` -------------------------------- ### Build Docker Images using Make Source: https://github.com/amm1rr/webai-to-api/blob/master/Docker.md These `make` commands streamline the process of building the project's Docker images. `make build` performs a standard build, while `make build-fresh` forces a clean build by ignoring the cache, useful for troubleshooting or ensuring the latest dependencies. ```bash make build # Regular build make build-fresh # Force clean build (no cache) ``` -------------------------------- ### Example API Response for Chat Completions Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md This JSON object illustrates the expected response from the `/v1/chat/completions` endpoint, providing the assistant's reply, model information, and usage statistics in an OpenAI-compatible format. It includes the generated message, finish reason, and token usage. ```json { "id": "chatcmpl-12345", "object": "chat.completion", "created": 1693417200, "model": "gemini-2.0-flash", "choices": [ { "message": { "role": "assistant", "content": "Hi there!" }, "finish_reason": "stop", "index": 0 } ], "usage": { "prompt_tokens": 0, "completion_tokens": 0, "total_tokens": 0 } } ``` -------------------------------- ### Configure Docker Environment Variables Source: https://github.com/amm1rr/webai-to-api/blob/master/Docker.md This snippet demonstrates how to set the `ENVIRONMENT` variable within a `.env` file. This variable is crucial for determining the operational mode of the Dockerized application, switching between 'development' (with auto-reload and debug logs) and 'production' (with multi-worker and detached execution). ```env # Set the environment mode ENVIRONMENT=development ``` -------------------------------- ### Example API Request Payload for Chat Completions Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md This JSON object represents a typical request body for the `/v1/chat/completions` endpoint, specifying the LLM model to use and the user's message in an OpenAI-compatible format. This payload is used to initiate a chat completion request. ```json { "model": "gemini-2.0-flash", "messages": [{ "role": "user", "content": "Hello!" }] } ``` -------------------------------- ### WebAI-to-API Sample Configuration File Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md Provides a sample `config.conf` file demonstrating how to configure the WebAI-to-API service. It includes settings for default AI services, specific model names, cookie values for authentication, and enabling/disabling AI providers. ```INI [AI] # Default AI service. default_ai = gemini # Default model for Gemini. default_model_gemini = gemini-2.0-flash # Gemini cookies (leave empty to use browser_cookies3 for automatic authentication). gemini_cookie_1psid = gemini_cookie_1psidts = [EnabledAI] # Enable or disable AI services. gemini = true [Browser] # Default browser options: firefox, brave, chrome, edge, safari. name = firefox ``` -------------------------------- ### WebAI-to-API Project Directory Structure Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md Outlines the modular project structure of WebAI-to-API, detailing the organization of application components, API endpoints, services, utilities, models, schemas, and configuration files for clarity and maintainability. ```plaintext src/ ├── app/ │ ├── __init__.py │ ├── main.py # FastAPI app creation, configuration, and lifespan management. │ ├── config.py # Global configuration loader/updater. │ ├── logger.py # Centralized logging configuration. │ ├── endpoints/ # API endpoint routers. │ │ ├── __init__.py │ │ ├── gemini.py # Endpoints for Gemini (e.g., /gemini, /gemini-chat). │ │ └── chat.py # Endpoints for translation and OpenAI-compatible requests. │ ├── services/ # Business logic and service wrappers. │ │ ├── __init__.py │ │ ├── gemini_client.py # Gemini client initialization, content generation, and cleanup. │ │ └── session_manager.py # Session management for chat and translation. │ └── utils/ # Helper functions. │ ├── __init__.py │ └── browser.py # Browser-based cookie retrieval. ├── models/ # Models and wrappers (e.g., MyGeminiClient). │ └── gemini.py ├── schemas/ # Pydantic schemas for request/response validation. │ └── request.py ├── config.conf # Application configuration file. └── run.py # Entry point to run the server. ``` -------------------------------- ### WebAI-to-API Key Configuration Options Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md Describes key configuration options for the WebAI-to-API service, including the default AI service for chat completions, the browser used for cookie-based authentication, and flags to enable or disable specific AI services like Gemini. ```APIDOC Section: [AI] Option: default_ai Description: Default service for /v1/chat/completions Example Value: `gemini` Section: [Browser] Option: name Description: Browser for cookie-based authentication Example Value: `firefox` Section: [EnabledAI] Option: gemini Description: Enable/disable Gemini service Example Value: `true` ``` -------------------------------- ### gpt4free Server Endpoints Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md These endpoints are powered by the `gpt4free` library and follow the OpenAI-compatible structure, offering broader access to various LLMs. For detailed usage and advanced customization, refer to the official gpt4free documentation. ```APIDOC POST /v1 - Description: General endpoint for gpt4free services, typically used for various LLM interactions. - Parameters: Refer to gpt4free documentation for specific request body details. - Returns: LLM response based on the request. POST /v1/chat/completions - Description: OpenAI-compatible chat completions endpoint, leveraging the gpt4free library to access multiple LLMs. - Parameters: Request body conforming to OpenAI chat completion specification (e.g., {"model": "string", "messages": [{"role": "string", "content": "string"}]}). - Returns: Response conforming to OpenAI chat completion specification. ``` -------------------------------- ### WebAI-to-API Server Endpoints Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md This section details the API endpoints provided by the WebAI-to-API server, including their purpose and behavior regarding session management. These endpoints facilitate interaction with browser-based LLMs like Gemini. ```APIDOC GET /gemini - Description: Initiates a new conversation with the LLM. Each request creates a fresh session, making it suitable for stateless interactions. - Parameters: None - Returns: LLM response for a new conversation. POST /gemini-chat - Description: Continues a persistent conversation with the LLM without starting a new session. Ideal for use cases that require context retention between messages. - Parameters: Request body containing chat messages. - Returns: LLM response within the ongoing session. POST /translate - Description: Designed for quick integration with the 'Translate It!' browser extension. Functionally identical to `/gemini-chat`, meaning it maintains session context across requests. - Parameters: Request body containing text to translate or chat messages. - Returns: Translated text or LLM response within the ongoing session. POST /v1/chat/completions - Description: A minimalistic implementation of the OpenAI-compatible endpoint. Built for simplicity and ease of integration with clients that expect the OpenAI API format. - Parameters: Request body conforming to OpenAI chat completion specification (e.g., {"model": "string", "messages": [{"role": "string", "content": "string"}]}). - Returns: Response conforming to OpenAI chat completion specification. ``` -------------------------------- ### WebAI-to-API REST API Endpoints Source: https://github.com/amm1rr/webai-to-api/blob/master/README.md Documents the available REST API endpoints for the WebAI-to-API service, including routes for chat completions, image generation, audio processing, model management, and file operations. These endpoints provide an API layer over various AI providers. ```APIDOC GET / # Health check GET /v1 # Version info GET /v1/models # List all available models GET /api/{provider}/models # List models from a specific provider GET /v1/models/{model_name} # Get details of a specific model POST /v1/chat/completions # Chat with default configuration POST /api/{provider}/chat/completions POST /api/{provider}/{conversation_id}/chat/completions POST /v1/responses # General response endpoint POST /api/{provider}/responses POST /api/{provider}/images/generations POST /v1/images/generations POST /v1/images/generate # Generate images using selected provider POST /v1/media/generate # Media generation (audio/video/etc.) GET /v1/providers # List all providers GET /v1/providers/{provider} # Get specific provider info POST /api/{path_provider}/audio/transcriptions POST /v1/audio/transcriptions # Audio-to-text POST /api/markitdown # Markdown rendering POST /api/{path_provider}/audio/speech POST /v1/audio/speech # Text-to-speech POST /v1/upload_cookies # Upload session cookies (browser-based auth) GET /v1/files/{bucket_id} # Get uploaded file from bucket POST /v1/files/{bucket_id} # Upload file to bucket GET /v1/synthesize/{provider} # Audio synthesis POST /json/{filename} # Submit structured JSON data GET /media/{filename} # Retrieve media GET /images/{filename} # Retrieve images ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.