### Install file bed server dependencies Source: https://github.com/lianues/lmarenabridge/blob/main/README.md Navigate to the `file_bed_server` directory and install its specific Python dependencies using `requirements.txt`. ```bash cd file_bed_server pip install -r requirements.txt cd .. ``` -------------------------------- ### Install Python Dependencies Source: https://github.com/lianues/lmarenabridge/blob/main/README.md Installs necessary Python packages from the requirements file. Ensure you have Python installed and are in the project's root directory. ```bash pip install -r requirements.txt ``` -------------------------------- ### Start the file bed server Source: https://github.com/lianues/lmarenabridge/blob/main/README.md This command starts the dedicated file bed server, which handles uploads of various file types and bypasses LMArena's Base64 size and type limitations. The server runs on `http://127.0.0.1:5104` by default. ```bash python file_bed_server/main.py ``` -------------------------------- ### Run Local API Server Source: https://github.com/lianues/lmarenabridge/blob/main/README.md Starts the main FastAPI server. This server acts as a proxy between your OpenAI client and the LMArena API. It needs to be running for the bridge to function. ```bash python api_server.py ``` -------------------------------- ### Update Available Models List Source: https://github.com/lianues/lmarenabridge/blob/main/README.md Runs a script to fetch and generate a list of available models from LMArena. This helps in identifying models you can use and updating your local configuration. ```bash python model_updater.py ``` -------------------------------- ### LMArena Global Configuration (`config.jsonc`) Source: https://github.com/lianues/lmarenabridge/blob/main/README.md The `config.jsonc` file controls global server settings, including default session IDs, message IDs, request modes, API keys, and file bed settings. ```json { "session_id": "global_default_session_id", "message_id": "global_default_message_id", "id_updater_last_mode": "direct_chat", "id_updater_battle_target": "", "use_default_ids_if_mapping_not_found": true, "api_key": "your_secret_api_key", "tavern_mode_enabled": false, "file_bed_enabled": true, "file_bed_upload_url": "http:\/\/127.0.0.1:5104/upload", "file_bed_api_key": "your_secret_api_key" } ``` -------------------------------- ### LMArena Models JSON configuration Source: https://github.com/lianues/lmarenabridge/blob/main/README.md The `models.json` file maps LMArena model names to their internal IDs. It supports specifying image generation models by appending `:image` to the model ID. ```json { "gemini-1.5-pro-flash-20240514": "gemini-1.5-pro-flash-20240514", "dall-e-3": "null:image" } ``` -------------------------------- ### LMArena Model-Specific Configuration (`model_endpoint_map.json`) Source: https://github.com/lianues/lmarenabridge/blob/main/README.md This advanced configuration file allows overriding global settings for specific models, enabling session isolation, request load balancing via ID pools, and mode binding. ```json { "claude-3-opus-20240229": [ { "session_id": "session_for_direct_chat_1", "message_id": "message_for_direct_chat_1", "mode": "direct_chat" }, { "session_id": "session_for_battle_A", "message_id": "message_for_battle_A", "mode": "battle", "battle_target": "A" } ], "gemini-1.5-pro-20241022": { "session_id": "single_session_id_no_mode", "message_id": "single_message_id_no_mode" } } ``` -------------------------------- ### Tampermonkey Script for LMArena API Bridge Source: https://github.com/lianues/lmarenabridge/blob/main/README.md The JavaScript code to be pasted into the Tampermonkey extension. This script runs in the browser on LMArena pages, capturing necessary data and communicating with the local server via WebSockets. ```javascript // Placeholder for the actual LMArenaApiBridge.js content. // This script facilitates communication between the browser and the local server. ``` -------------------------------- ### Update Session and Message IDs Source: https://github.com/lianues/lmarenabridge/blob/main/README.md Executes a script to capture necessary session and message IDs for API communication. This is a crucial step for enabling the bridge to interact with LMArena. ```bash python id_updater.py ``` -------------------------------- ### Update available models from LMArena Source: https://github.com/lianues/lmarenabridge/blob/main/README.md This script, `model_updater.py`, manually extracts the latest available model list from the LMArena website. It saves this information to `available_models.json`, which can then be used to update the core `models.json`. ```python import requests from bs4 import BeautifulSoup import json def update_models(): url = "https://lmarena.ai/" try: response = requests.get(url) response.raise_for_status() # Raise an exception for bad status codes except requests.exceptions.RequestException as e: print(f"Error fetching LMArena page: {e}") return soup = BeautifulSoup(response.text, 'html.parser') model_list_items = soup.select('div.model_list_item') available_models = {} for item in model_list_items: try: model_id_element = item.select_one('div.model_id') model_name_element = item.select_one('div.model_name') if model_id_element and model_name_element: model_id = model_id_element.get_text(strip=True) model_name = model_name_element.get_text(strip=True) # Determine if it's an image model based on common naming or explicit markers # This is a heuristic and might need adjustment if LMArena changes its display is_image_model = ":image" in model_id.lower() or "image" in model_name.lower() or "generate" in model_name.lower() if is_image_model: available_models[model_name] = f"{model_id}:image" else: available_models[model_name] = model_id except Exception as e: print(f"Error parsing model item: {e}") continue try: with open('available_models.json', 'w', encoding='utf-8') as f: json.dump(available_models, f, indent=2, ensure_ascii=False) print("Successfully updated available_models.json") except IOError as e: print(f"Error writing to available_models.json: {e}") if __name__ == "__main__": update_models() ``` -------------------------------- ### Update session IDs with Oil Monkey script Source: https://github.com/lianues/lmarenabridge/blob/main/README.md A Tampermonkey script (`LMArenaApiBridge.js`) is provided to communicate with the backend server and perform necessary browser operations, including updating session IDs. ```javascript // LMArenaApiBridge.js - Tampermonkey Script // ==UserScript== // @name LMArena API Bridge // @namespace http://tampermonkey.net/ // @version 0.1 // @description Bridge LMArena API with local backend // @match https://lmarena.ai/* // @grant none // ==/UserScript== (function() { 'use strict'; const BACKEND_URL = "http://127.0.0.1:8000"; // Default backend URL // Function to send session ID to backend function sendSessionId(session_id, message_id, mode, battle_target) { fetch(`${BACKEND_URL}/update_session`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify({ session_id: session_id, message_id: message_id, mode: mode, battle_target: battle_target }), }) .then(response => response.json()) .then(data => console.log('Session updated:', data)) .catch((error) => console.error('Error updating session:', error)); } // Example: Listen for events or user actions to capture session IDs // This part is highly dependent on LMArena's UI and might need adjustments. // For demonstration, let's assume there's a button to capture the current session. // Example placeholder for capturing session data: // You would need to find the actual DOM elements or event listeners // on LMArena.ai to extract session_id, message_id, and mode. // Mock function to simulate capturing session data function captureSessionData() { // Replace with actual logic to get data from LMArena UI console.log("Attempting to capture session data..."); const mockSessionId = "captured_session_123"; const mockMessageId = "captured_message_456"; const mockMode = "direct_chat"; // or "battle" const mockBattleTarget = "A"; // if mode is battle console.log(`Captured: Session ID=${mockSessionId}, Message ID=${mockMessageId}, Mode=${mockMode}`); sendSessionId(mockSessionId, mockMessageId, mockMode, mockBattleTarget); } // Add a button or hook into an existing UI element to trigger captureSessionData // Example: Add a button to the page const captureButton = document.createElement('button'); captureButton.textContent = 'Capture Session ID'; captureButton.style.position = 'fixed'; captureButton.style.top = '10px'; captureButton.style.right = '10px'; captureButton.style.zIndex = '10000'; captureButton.onclick = captureSessionData; document.body.appendChild(captureButton); console.log('LMArena API Bridge script loaded.'); })(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.