|
| 1 | +# Any Proxy API (Go) |
| 2 | + |
| 3 | +A Go-based proxy server that provides OpenAI-compatible API endpoints for **Any** AI website using browser automation. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This project creates a bridge between OpenAI's API format and an AI website's web interface. It uses Playwright for browser automation to interact with **Any** AI website and provides a REST API that mimics OpenAI's chat completions endpoint. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- **OpenAI-Compatible API**: Supports `/v1/chat/completions` endpoints |
| 12 | +- **Browser Automation**: Uses Playwright with [Camoufox](https://github.com/daijro/camoufox) browser for web automation |
| 13 | +- **Request Queue**: Implements a queue system to handle requests sequentially |
| 14 | +- **Configurable Workflows**: YAML-based configuration for different automation workflows |
| 15 | +- **Proxy Support**: Built-in HTTP proxy for network traffic interception |
| 16 | +- **Multi-Instance Support**: Can manage multiple AI Studio instances simultaneously |
| 17 | + |
| 18 | +## Architecture |
| 19 | + |
| 20 | +The application consists of several key components: |
| 21 | + |
| 22 | +### Core Components |
| 23 | + |
| 24 | +1. **API Server** (`internal/api/`): Gin-based HTTP server providing OpenAI-compatible endpoints |
| 25 | +2. **Browser Manager** (`internal/browser/`): Manages Playwright browser instances and contexts |
| 26 | +3. **Runner System** (`internal/runner/`): Executes YAML-defined workflows for browser automation |
| 27 | +4. **Method Library** (`internal/method/`): Collection of automation methods (click, input, etc.) |
| 28 | +5. **Proxy Server** (`internal/proxy/`): HTTP proxy for intercepting and analyzing network traffic |
| 29 | +6. **Configuration** (`internal/config/`): Application configuration management |
| 30 | + |
| 31 | +### Request Flow |
| 32 | + |
| 33 | +1. Client sends OpenAI-format request to `/v1/chat/completions` |
| 34 | +2. Request is queued in the request queue system |
| 35 | +3. Runner executes the appropriate YAML workflow to interact with AI Studio |
| 36 | +4. Browser automation performs the necessary actions (input text, click buttons, etc.) |
| 37 | +5. Proxy intercepts the response from AI Studio |
| 38 | +6. Response is formatted and returned to the client |
| 39 | + |
| 40 | +## Installation |
| 41 | + |
| 42 | +### Prerequisites |
| 43 | + |
| 44 | +- Go 1.24 or later |
| 45 | +- Camoufox browser |
| 46 | + |
| 47 | +### Setup |
| 48 | + |
| 49 | +1. Clone the repository: |
| 50 | +```bash |
| 51 | +git clone https://github.com/luispater/anyAIProxyAPI.git |
| 52 | +cd anyAIProxyAPI |
| 53 | +``` |
| 54 | + |
| 55 | +2. Install dependencies: |
| 56 | +```bash |
| 57 | +go mod download |
| 58 | +``` |
| 59 | + |
| 60 | +3. Install Playwright browsers: |
| 61 | +```bash |
| 62 | +go run github.com/playwright-community/playwright-go/cmd/playwright@latest install |
| 63 | +``` |
| 64 | + |
| 65 | +4. Configure the application by editing `runner/main.yaml` |
| 66 | + |
| 67 | +## Configuration |
| 68 | + |
| 69 | +The main configuration file is `runner/main.yaml`: |
| 70 | + |
| 71 | +```yaml |
| 72 | +version: "1" |
| 73 | +debug: false |
| 74 | +camoufox-path: "/path/to/camoufox" |
| 75 | +api-port: "2048" |
| 76 | +headless: true |
| 77 | +instance: |
| 78 | + - name: "example" |
| 79 | + proxy-url: "" |
| 80 | + url: "https://example.com/new_chat" |
| 81 | + sniff-port: "3120" |
| 82 | + sniff-domain: "*.example.com" |
| 83 | + auth-file: "auth/example.json" |
| 84 | + runner: # must be init, chat_completions, context_canceled |
| 85 | + init: "init-system" #init runner |
| 86 | + chat_completions: "chat_completions" #chat_completions runner |
| 87 | + context_canceled: "context-canceled" #context canceled(client disconnect) runner |
| 88 | +``` |
| 89 | +
|
| 90 | +### Configuration Parameters |
| 91 | +
|
| 92 | +- `debug`: Enable debug mode for detailed logging |
| 93 | +- `camoufox-path`: Path to Camoufox browser executable |
| 94 | +- `api-port`: Port for the API server |
| 95 | +- `headless`: Run browser in headless mode |
| 96 | +- `instance`: Array of AI Studio instances to manage. Each instance has its own configuration. All runner files must be defined in a directory corresponding to the instance name. For details on the runner file syntax, please refer to [runner.md](runner.md) |
| 97 | + |
| 98 | +## Usage |
| 99 | + |
| 100 | +### Starting the Server |
| 101 | + |
| 102 | +```bash |
| 103 | +go run main.go |
| 104 | +``` |
| 105 | + |
| 106 | +The server will start on the configured port (default: 2048). |
| 107 | + |
| 108 | +### API Endpoints |
| 109 | + |
| 110 | +#### Chat Completions |
| 111 | +```bash |
| 112 | +POST http://localhost:2048/v1/chat/completions |
| 113 | +Content-Type: application/json |
| 114 | +
|
| 115 | +{ |
| 116 | + "model": "instance-name/model-name", |
| 117 | + "messages": [ |
| 118 | + { |
| 119 | + "role": "user", |
| 120 | + "content": "Hello, how are you?" |
| 121 | + } |
| 122 | + ] |
| 123 | +} |
| 124 | +``` |
| 125 | + |
| 126 | +## Workflow System |
| 127 | + |
| 128 | +The application uses a YAML-based workflow system to define browser automation sequences. Workflows are stored in the `runner/` directory and define step-by-step instructions for interacting with AI Studio. |
| 129 | + |
| 130 | +For detailed information about the runner system, see [runner.md](runner.md). |
| 131 | + |
| 132 | +## Development |
| 133 | + |
| 134 | +### Project Structure |
| 135 | + |
| 136 | +``` |
| 137 | +├── main.go # Application entry point |
| 138 | +├── internal/ |
| 139 | +│ ├── api/ # HTTP API server |
| 140 | +│ ├── browser/ # Browser management |
| 141 | +│ ├── config/ # Configuration handling |
| 142 | +│ ├── method/ # Automation methods |
| 143 | +│ ├── proxy/ # HTTP proxy server |
| 144 | +│ └── runner/ # Workflow execution engine |
| 145 | +├── runner/ |
| 146 | +│ ├── main.yaml # Main configuration |
| 147 | +│ └── instance-name/ # AI Studio workflows |
| 148 | +├── auth/ # Authentication files |
| 149 | +└── docs/ # Documentation |
| 150 | +``` |
| 151 | +
|
| 152 | +### Building |
| 153 | +
|
| 154 | +```bash |
| 155 | +go build -o any-ai-proxy main.go |
| 156 | +``` |
| 157 | + |
| 158 | +## Contributing |
| 159 | + |
| 160 | +1. Fork the repository |
| 161 | +2. Create a feature branch |
| 162 | +3. Make your changes |
| 163 | +4. Add tests if applicable |
| 164 | +5. Submit a pull request |
| 165 | + |
| 166 | +## License |
| 167 | + |
| 168 | +This project is licensed under the MIT License. Refer to the LICENSE file for details. |
| 169 | + |
| 170 | +## Acknowledgements |
| 171 | + |
| 172 | +This project was inspired by [AIStudioProxyAPI](https://github.com/CJackHwang/AIstudioProxyAPI) |
| 173 | + |
| 174 | +## Disclaimer |
| 175 | + |
| 176 | +This project is for educational and research purposes. Please ensure you comply with **Any** AI website's terms of service when using this software. |
0 commit comments