AI Studio Bridge

repository·main·Indexed 42 days ago

https://github.com/lianues/aistudiobridge

A toolset to automate Google AI Studio workflows using Tampermonkey scripts and local Python servers. It provides OpenAI-compatible API endpoints, automated function calling, and dynamic model discovery by bridging the browser interface with local servers.

Tokens
820
Snippets
2
Records
4
Agent score
3%

What's inside AI Studio Bridge

  1. How Function Calling and Dynamic Model Lists work

    main

    AI Studio Bridge provides an end-to-end automation loop for advanced AI features:

    Function Calling / Tool Calling

    • Definition: You define tools (functions) within your API request.
    • AI Decision: AI Studio determines when to call a tool and returns a tool_calls response in OpenAI format.
    • Parallel Execution: The system supports scenarios where the AI calls multiple functions in a single request.
    • Automation Loop: You execute the function on the client side and send the result back using a message with role: "tool". The system automatically submits this to AI Studio and streams the final text response.

    Dynamic Model Discovery

    When a client calls the /v1/models endpoint, the system triggers the modelfetcher.js script. This script refreshes the page, intercepts the model requests, and returns a real-time, OpenAI-compatible list of available models.

  2. Start the AI Studio Bridge servers

    main

    The project requires two Python servers to be running simultaneously to handle history management and OpenAI API compatibility.

    1. Local History Server: Handles history data and streaming. It listens on http://127.0.0.1:5101.

      python local_history_server.py
    2. OpenAI Compatible Server: Acts as a proxy for OpenAI API requests, forwarding them to the local history server and returning responses in OpenAI-compatible formats. It listens on http://127.0.0.1:5100.

      python openai_compatible_server.py
    # Terminal 1
    python local_history_server.py
    
    # Terminal 2
    python openai_compatible_server.py
  3. Install and use Tampermonkey scripts

    main

    Once the servers are running, you must install the browser-side automation scripts to enable interaction between the browser and the local servers.

    Installation

    1. Open the following files in your browser via your script manager (Tampermonkey/Greasemonkey):
      • TampermonkeyScript/automator.js
      • TampermonkeyScript/historyforger.js
      • TampermonkeyScript/modelfetcher.js
    2. Your script manager should automatically prompt you to install all three scripts.

    Script Roles

    • automator.js: Automates repetitive tasks in the browser workflow.
    • historyforger.js: Manages and modifies chat history for testing or data preparation.
    • modelfetcher.js: Intercepts and fetches available AI model lists to provide them to clients via the local server.

    Final Step

    After installation, open an existing AI Studio Chat history page (ensure it is not an empty chat page) to allow the scripts to begin interacting with the local servers.

  4. Install AI Studio Bridge

    main

    To set up the AI Studio Bridge environment, follow these steps to clone the repository and install the necessary Python dependencies.

    Prerequisites

    • A web browser with a userscript manager installed (e.g., Tampermonkey or Greasemonkey).
    • Python (version 3.8 or higher recommended).

    Installation Steps

    1. Clone the repository:
      git clone https://github.com/Lianues/AIStudioBridge
      cd AIStudioBridge
    2. Install Python dependencies using pip:
      pip install -r requirements.txt
    git clone https://github.com/Lianues/AIStudioBridge
    cd AIStudioBridge
    pip install -r requirements.txt