Skip to content

Latest commit

 

History

History
153 lines (112 loc) · 3.85 KB

File metadata and controls

153 lines (112 loc) · 3.85 KB

Using Web Models with Copilot & Cline

Overview

This setup creates an OpenRouter-compatible API server that wraps web-based AI models, making them usable with tools like GitHub Copilot, Cline, and any OpenAI-compatible client.

Quick Start

  1. Install dependencies:
pip install fastapi uvicorn selenium langchain webdriver-manager
  1. Start the server:
python openrouter_server.py
  1. Server runs on: http://localhost:8000

Configuration for Different Tools

GitHub Copilot (VS Code Extension)

Unfortunately, GitHub Copilot doesn't support custom endpoints directly. However, you can:

  1. Use Continue.dev extension instead (supports custom endpoints)
  2. Use Cline (formerly Claude Dev) which supports OpenAI-compatible APIs

Cline (VS Code Extension)

  1. Install Cline extension in VS Code
  2. Open Cline settings
  3. Configure API:
    • Provider: OpenAI Compatible
    • Base URL: http://localhost:8000/v1
    • API Key: dummy-key (not used but required)
    • Model: google/gemini-pro

Continue.dev

  1. Install Continue extension
  2. Edit ~/.continue/config.json:
{
  "models": [
    {
      "title": "Gemini Pro (Web)",
      "provider": "openai",
      "model": "google/gemini-pro",
      "apiBase": "http://localhost:8000/v1",
      "apiKey": "dummy-key"
    }
  ]
}

Cursor IDE

  1. Go to Settings → Models
  2. Add custom model:
    • Provider: OpenAI Compatible
    • Base URL: http://localhost:8000/v1
    • Model: google/gemini-pro
    • API Key: dummy-key

Any OpenAI-Compatible Client

import openai

client = openai.OpenAI(
    api_key="dummy-key",
    base_url="http://localhost:8000/v1"
)

response = client.chat.completions.create(
    model="google/gemini-pro",
    messages=[{"role": "user", "content": "Hello!"}]
)

Available Models

  • google/gemini-pro - Google's Gemini Pro via AI Studio
  • google/gemini-pro-vision - Gemini Pro with vision (same backend for now)

Adding More Models

To add support for other web-based models:

  1. Create new LLM wrapper (similar to GoogleAIStudioLLM)
  2. Add to model registry in openrouter_server.py
  3. Update get_llm_instance() to handle new models

Example for ChatGPT:

# In openrouter_server.py
AVAILABLE_MODELS["openai/gpt-4-web"] = {
    "id": "openai/gpt-4-web",
    "name": "GPT-4 Web",
    "description": "ChatGPT via web interface"
}

# Create ChatGPTWebLLM class similar to GoogleAIStudioLLM

Authentication

Since web models require login:

  1. First run: Set headless=False in GoogleAIStudioLLM
  2. Manual login: Browser opens, log in manually
  3. Session persistence: Browser stays logged in
  4. Production: Implement automated login (advanced)

Limitations

  • Slower than APIs: Web scraping adds latency
  • Rate limits: Web interfaces have stricter limits
  • Fragile: UI changes can break selectors
  • Authentication: Requires manual login initially

Troubleshooting

Server won't start

  • Check if port 8000 is available
  • Install missing dependencies

Model not responding

  • Check if you're logged into the web interface
  • Verify selectors are still valid
  • Check browser console for errors

Cline/Continue not connecting

  • Ensure server is running on correct port
  • Check firewall settings
  • Verify API endpoint configuration

Security Notes

  • Server runs locally only by default
  • No real API key validation (uses dummy keys)
  • Web sessions are browser-based
  • Consider VPN if accessing from remote tools

Performance Tips

  • Keep browser sessions alive
  • Add connection pooling for multiple requests
  • Implement caching for repeated queries
  • Use headless mode in production