File size: 2,458 Bytes
1ec79bd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import gradio as gr
import requests

# Apni API Key aur AgentRouter ka URL
API_KEY = "sk-ZCDGmT8bXQzwjzW2UeBYCAtlBtCSHJZ7flOUo6u6TEWOS7DA"
API_URL = "https://agentrouter.org/v1/chat/completions"

def chat_with_bot(message, history, model_name):
    messages = []
    
    # Purani chat history ko add karna
    for user_msg, bot_msg in history:
        messages.append({"role": "user", "content": user_msg})
        messages.append({"role": "assistant", "content": bot_msg})
    
    # Naya message add karna
    messages.append({"role": "user", "content": message})

    # πŸ”₯ ALIBABA CLOUD WAF BYPASS HEADERS πŸ”₯
    # Yeh headers WAF ko bewaqoof banate hain ke request kisi real CLI tool se aa rahi hai
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {API_KEY}",
        "User-Agent": "codex_cli_rs/0.101.0 (Mac OS; arm64)", 
        "Originator": "codex_cli_rs",
        "Accept": "application/json"
    }

    payload = {
        "model": model_name,
        "messages": messages
    }

    try:
        response = requests.post(API_URL, headers=headers, json=payload)
        
        # Check karna ke kahin Alibaba WAF ne phir bhi to block nahi kiya
        if "CF_APP_WAF" in response.text or "<html" in response.text.lower():
            yield "❌ **Alibaba Cloud WAF Block!**\nFirewall ne Hugging Face ki IP ko rok diya hai. Thori dair baad try karein."
            return
            
        data = response.json()
        
        if response.status_code == 200:
            yield data['choices'][0]['message']['content']
        else:
            yield f"⚠️ **API Error ({response.status_code}):** {data.get('error', {}).get('message', response.text)}"
            
    except Exception as e:
        yield f"πŸ”Œ **Connection Error:** {str(e)}"

# Gradio Interface (UI) Design karna
with gr.Blocks(theme=gr.themes.Soft()) as demo:
    gr.Markdown("<center><h1>πŸ€– AgentRouter Chatbot</h1><p>Running with Alibaba WAF Bypass Headers</p></center>")
    
    with gr.Row():
        model_dropdown = gr.Dropdown(
            choices=["deepseek-v4-pro", "deepseek-v4-flash", "claude-haiku-4-5-20251001", "claude-opus-4-6", "glm-5.1"],
            value="deepseek-v4-pro",
            label="Select AI Model"
        )
        
    chat = gr.ChatInterface(
        fn=chat_with_bot,
        additional_inputs=[model_dropdown]
    )

# App ko run karna
if __name__ == "__main__":
    demo.launch()