Skip to content

Commit 8d102e1

Browse files
committed
first commit
0 parents  commit 8d102e1

42 files changed

Lines changed: 5412 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/release.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: goreleaser
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- '*'
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
goreleaser:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v3
17+
with:
18+
fetch-depth: 0
19+
- run: git fetch --force --tags
20+
- uses: actions/setup-go@v3
21+
with:
22+
go-version: '>=1.24.0'
23+
cache: true
24+
- uses: goreleaser/goreleaser-action@v3
25+
with:
26+
distribution: goreleaser
27+
version: latest
28+
args: release --clean
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[0-9]*.md
2+
!*[a-zA-Z]*.md
3+
.vscode
4+
.idea
5+
auth/*.json
6+
anyAIProxyAPI-go

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "runner"]
2+
path = runner
3+
url = git@github.com:luispater/anyAIProxyAPI-runner.git

.goreleaser.yaml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: 2
2+
3+
before:
4+
hooks:
5+
# You may remove this if you don't use go modules.
6+
- go mod tidy
7+
builds:
8+
- env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
- windows
13+
- darwin
14+
15+
archives:
16+
- id: archive
17+
formats: [ 'tar.gz' ]
18+
# this name template makes the OS and Arch compatible with the results of uname.
19+
name_template: >-
20+
{{ .ProjectName }}_
21+
{{- title .Os }}_
22+
{{- if eq .Arch "amd64" }}x86_64
23+
{{- else if eq .Arch "386" }}i386
24+
{{- else }}{{ .Arch }}{{ end }}
25+
{{- if .Arm }}v{{ .Arm }}{{ end }}
26+
# use zip for windows archives
27+
format_overrides:
28+
- goos: windows
29+
formats: [ 'zip' ]
30+
files:
31+
- LICENSE
32+
checksum:
33+
name_template: 'checksums.txt'
34+
snapshot:
35+
version_template: "{{ incpatch .Version }}-next"
36+
changelog:
37+
sort: asc
38+
filters:
39+
exclude:
40+
- '^docs:'
41+
- '^test:'
42+
43+
# The lines beneath this are called `modelines`. See `:help modeline`
44+
# Feel free to remove those if you don't want/use them.
45+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
46+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2025 Luis Pater
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
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.

go.mod

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
module github.com/luispater/anyAIProxyAPI
2+
3+
go 1.24
4+
5+
require (
6+
github.com/gin-gonic/gin v1.10.1
7+
github.com/goccy/go-yaml v1.17.1
8+
github.com/google/uuid v1.6.0
9+
github.com/playwright-community/playwright-go v0.5200.0
10+
github.com/sirupsen/logrus v1.9.3
11+
github.com/tidwall/gjson v1.18.0
12+
github.com/tidwall/sjson v1.2.5
13+
golang.org/x/net v0.40.0
14+
)
15+
16+
require (
17+
github.com/bytedance/sonic v1.13.2 // indirect
18+
github.com/bytedance/sonic/loader v0.2.4 // indirect
19+
github.com/cloudwego/base64x v0.1.5 // indirect
20+
github.com/deckarep/golang-set/v2 v2.8.0 // indirect
21+
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
22+
github.com/gin-contrib/sse v1.1.0 // indirect
23+
github.com/go-jose/go-jose/v3 v3.0.4 // indirect
24+
github.com/go-playground/locales v0.14.1 // indirect
25+
github.com/go-playground/universal-translator v0.18.1 // indirect
26+
github.com/go-playground/validator/v10 v10.26.0 // indirect
27+
github.com/go-stack/stack v1.8.1 // indirect
28+
github.com/goccy/go-json v0.10.5 // indirect
29+
github.com/json-iterator/go v1.1.12 // indirect
30+
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
31+
github.com/kr/text v0.2.0 // indirect
32+
github.com/leodido/go-urn v1.4.0 // indirect
33+
github.com/mattn/go-isatty v0.0.20 // indirect
34+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
35+
github.com/modern-go/reflect2 v1.0.2 // indirect
36+
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
37+
github.com/tidwall/match v1.1.1 // indirect
38+
github.com/tidwall/pretty v1.2.1 // indirect
39+
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
40+
github.com/ugorji/go/codec v1.2.12 // indirect
41+
golang.org/x/arch v0.17.0 // indirect
42+
golang.org/x/crypto v0.38.0 // indirect
43+
golang.org/x/sys v0.33.0 // indirect
44+
golang.org/x/text v0.25.0 // indirect
45+
google.golang.org/protobuf v1.36.6 // indirect
46+
gopkg.in/yaml.v3 v3.0.1 // indirect
47+
)

0 commit comments

Comments
 (0)