Uname:Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64

Base Dir : /var/www/moonbloom

User : wp-moonbloom


403WebShell
403Webshell
Server IP : 85.155.190.233  /  Your IP : 216.73.216.103
Web Server : nginx/1.24.0
System : Linux antigravity-cli 6.8.0-31-generic #31-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 20 00:40:06 UTC 2024 x86_64
User : wp-moonbloom ( 1001)
PHP Version : 8.3.6
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /opt/Gemini_Swarm_Core/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/Gemini_Swarm_Core/scripts/test_sdk_oauth.py
import json
import httpx
from google.oauth2.credentials import Credentials
from google.auth.transport.requests import Request
from google import genai
from google.genai import types

def test():
    oauth_path = "/opt/Gemini_Swarm_Core/.gemini/oauth_creds.json"
    try:
        with open(oauth_path) as f:
            creds_data = json.load(f)
    except Exception as e:
        print(f"Error loading oauth_creds.json: {e}")
        return

    # Create Credentials object with the client_id/client_secret from Gemini CLI
    creds = Credentials(
        token=creds_data.get("access_token"),
        refresh_token=creds_data.get("refresh_token"),
        token_uri="https://oauth2.googleapis.com/token",
        client_id="681255809395-oo8ft2oprdrnp9e3aqf6av3hmdib135j.apps.googleusercontent.com",
        client_secret="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",
        scopes=creds_data.get("scope", "").split()
    )

    try:
        print("Refreshing credentials...")
        req = Request()
        creds.refresh(req)
        print("Refreshed successfully!")
    except Exception as e:
        print(f"Refresh failed: {e}")
        return

    # Scenario 1: Using google-genai SDK for Developer API (Google AI)
    print("\n--- Scenario 1: google-genai SDK (Google AI) ---")
    try:
        client = genai.Client(credentials=creds)
        response = client.models.generate_content(
            model='gemini-2.5-flash',
            contents='Hello, answer in one short sentence in Russian.',
        )
        print("Scenario 1 Success!")
        print("Response:", response.text)
    except Exception as e:
        print("Scenario 1 Failed:", e)

    # Scenario 2: Using google-genai SDK for Vertex AI
    print("\n--- Scenario 2: google-genai SDK (Vertex AI) ---")
    try:
        client = genai.Client(
            vertexai=True,
            project="gen-lang-client-0207686288",
            location="us-central1",
            credentials=creds
        )
        response = client.models.generate_content(
            model='gemini-2.5-flash',
            contents='Hello, answer in one short sentence in Russian.',
        )
        print("Scenario 2 Success!")
        print("Response:", response.text)
    except Exception as e:
        print("Scenario 2 Failed:", e)

    # Scenario 3: Direct REST to Google AI (Developer API) with x-goog-user-project
    print("\n--- Scenario 3: REST to Google AI (with x-goog-user-project) ---")
    url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent"
    headers = {
        "Authorization": f"Bearer {creds.token}",
        "Content-Type": "application/json",
        "x-goog-user-project": "gen-lang-client-0207686288"
    }
    data = {
        "contents": [{"parts": [{"text": "Hello! Answer in Russian."}]}]
    }
    try:
        r = httpx.post(url, json=data, headers=headers)
        print("Status:", r.status_code)
        print("Response:", r.text[:300])
    except Exception as e:
        print("Scenario 3 Failed:", e)

if __name__ == "__main__":
    test()

Youez - 2016 - github.com/yon3zu
LinuXploit