code 2

PS C:\Lab\Python\python_code_v1>  & 'c:\Python314\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '62198' '--' 'C:\Lab\Python\python_code_v1\api.py' 

PS C:\Lab\Python\python_code_v1> pip install requests

Requirement already satisfied: requests in c:\python312\lib\site-packages (2.32.5)

Requirement already satisfied: charset_normalizer<4,>=2 in c:\python312\lib\site-packages (from requests) (3.4.4)

Requirement already satisfied: idna<4,>=2.5 in c:\python312\lib\site-packages (from requests) (3.11)

Requirement already satisfied: urllib3<3,>=1.21.1 in c:\python312\lib\site-packages (from requests) (2.6.3)

Requirement already satisfied: certifi>=2017.4.17 in c:\python312\lib\site-packages (from requests) (2026.2.25)


[notice] A new release of pip is available: 24.3.1 -> 26.0.1    

[notice] To update, run: python.exe -m pip install --upgrade pip

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Python314\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '58995' '--' 'C:\Lab\Python\python_code_v1\api.py'

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '64566' '--' 'C:\Lab\Python\python_code_v1\api.py'

API Testing for Google AIs  - Gemini 1.5 Pro

Status code: 404

Response text: <!DOCTYPE html>

<html lang=en>

  <meta charset=utf-8>

  <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width">

  <title>Error 404 (Not Found)!!1</title>

  <style>

    *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}

  <a href=//www.google.com/><span id=logo aria-label=Google></span></a>

  <p><b>404.</b> <ins>That’s an error.</ins>

  <p>The requested URL <code>/gemini/v1.5/pro</code> was not found on this server.  <ins>That’s all we know.</ins>


JSON decode error: Expecting value: line 1 column 1 (char 0)

None

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '58236' '--' 'C:\Lab\Python\python_code_v1\api.py'        

API Testing for Google AIs - Gemini 1.5 Pro

Status code: 400

Error Response: {

  "error": {

    "code": 400,

    "message": "API key not valid. Please pass a valid API key.",

    "status": "INVALID_ARGUMENT",

    "details": [

      {

        "@type": "type.googleapis.com/google.rpc.ErrorInfo",

        "reason": "API_KEY_INVALID",

        "domain": "googleapis.com",

        "metadata": {

          "service": "generativelanguage.googleapis.com"

        }

      },

      {

        "@type": "type.googleapis.com/google.rpc.LocalizedMessage",

        "locale": "en-US",

        "message": "API key not valid. Please pass a valid API key."

      }

    ]

  }

}


PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '58260' '--' 'C:\Lab\Python\python_code_v1\api.py' 

API Testing for Google AIs - Gemini 1.5 Pro

Status code: 404

Error Response: {

  "error": {

    "code": 404,

    "message": "models/gemini-1.5-pro is not found for API version v1beta, or is not supported for generateContent. Call ListModels to see the list of available models and their supported methods.",  

    "status": "NOT_FOUND"

  }

}


PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '61718' '--' 'C:\Lab\Python\python_code_v1\api.py'        

API Testing for Google AIs - Gemini 1.5 Pro

Status code: 404

Error Response: {

  "error": {

    "code": 404,

    "message": "models/gemini-1.5-flash is not found for API version v1beta, or is not supported for generateContent. Call ListModels to see the list of available models and their supported methods.",

    "status": "NOT_FOUND"

  }

}


PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '53945' '--' 'C:\Lab\Python\python_code_v1\api.py'        

API Testing for Google AIs - Gemini 1.0 Pro

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '53967' '--' 'C:\Lab\Python\python_code_v1\api.py' 

API Testing for Google AIs - Gemini 1.0 Pro

Model Name                     | Methods Supported

------------------------------------------------------------

models/gemini-2.5-flash        | Stable version of Gemini 2.5 Flash, our mid-size m...

models/gemini-2.5-pro          | Stable release (June 17th, 2025) of Gemini 2.5 Pro...

models/gemini-2.0-flash        | Gemini 2.0 Flash...

models/gemini-2.0-flash-001    | Stable version of Gemini 2.0 Flash, our fast and v...

models/gemini-2.0-flash-lite-001 | Stable version of Gemini 2.0 Flash-Lite...

models/gemini-2.0-flash-lite   | Gemini 2.0 Flash-Lite...

models/gemini-2.5-flash-preview-tts | Gemini 2.5 Flash Preview TTS...

models/gemini-2.5-pro-preview-tts | Gemini 2.5 Pro Preview TTS...

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '59632' '--' 'C:\Lab\Python\python_code_v1\api.py'        

API Testing for Google AIs - Gemini 1.0 Pro

Model Name                     | Methods Supported

------------------------------------------------------------

models/gemini-2.5-flash        | 001...

models/gemini-2.5-pro          | 2.5...

models/gemini-2.0-flash        | 2.0...

models/gemini-2.0-flash-001    | 2.0...

models/gemini-2.0-flash-lite-001 | 2.0...

models/gemini-2.0-flash-lite   | 2.0...

models/gemini-2.5-flash-preview-tts | gemini-2.5-flash-exp-tts-2025-05-19...

models/gemini-2.5-pro-preview-tts | gemini-2.5-pro-preview-tts-2025-05-19...

models/gemma-3-1b-it           | 001...

models/gemma-3-4b-it           | 001...

models/gemma-3-12b-it          | 001...

models/gemma-3-27b-it          | 001...

models/gemma-3n-e4b-it         | 001...

models/gemma-3n-e2b-it         | 001...

models/gemma-4-26b-a4b-it      | 001...

models/gemma-4-31b-it          | 001...

models/gemini-flash-latest     | Gemini Flash Latest...

models/gemini-flash-lite-latest | Gemini Flash-Lite Latest...

models/gemini-pro-latest       | Gemini Pro Latest...

models/gemini-2.5-flash-lite   | 001...

models/gemini-2.5-flash-image  | 2.0...

models/gemini-3-pro-preview    | 3-pro-preview-11-2025...

models/gemini-3-flash-preview  | 3-flash-preview-12-2025...

models/gemini-3.1-pro-preview  | 3.1-pro-preview-01-2026...

models/gemini-3.1-pro-preview-customtools | 3.1-pro-preview-01-2026...

models/gemini-3.1-flash-lite-preview | 3.1-flash-lite-preview-03-2026...

models/gemini-3-pro-image-preview | 3.0...

models/nano-banana-pro-preview | 3.0...

models/gemini-3.1-flash-image-preview | 3.0...

models/lyria-3-clip-preview    | lyria-3-clip-preview...

models/lyria-3-pro-preview     | lyria-3-pro-preview...

models/gemini-robotics-er-1.5-preview | 1.5-preview...

models/gemini-2.5-computer-use-preview-10-2025 | Gemini 2.5 Computer Use Preview 10-2025...

models/deep-research-pro-preview-12-2025 | deepthink-exp-05-20...

Status code: 404

Error Response: {

  "error": {

    "code": 404,

    "message": "models/gemini-1.0-pro is not found for API version v1beta, or is not supported for generateContent. Call ListModels to see the list of available models and their supported methods.",  

    "status": "NOT_FOUND"

  }

}


PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '53635' '--' 'C:\Lab\Python\python_code_v1\api.py' 

API Testing for Google AIs - Gemini 1.0 Pro

Model Name                     | Methods Supported

------------------------------------------------------------

models/gemini-2.5-flash        | 001...

models/gemini-2.5-pro          | 2.5...

models/gemini-2.0-flash        | 2.0...

models/gemini-2.0-flash-001    | 2.0...

models/gemini-2.0-flash-lite-001 | 2.0...

models/gemini-2.0-flash-lite   | 2.0...

models/gemini-2.5-flash-preview-tts | gemini-2.5-flash-exp-tts-2025-05-19...

models/gemini-2.5-pro-preview-tts | gemini-2.5-pro-preview-tts-2025-05-19...

models/gemma-3-1b-it           | 001...

models/gemma-3-4b-it           | 001...

models/gemma-3-12b-it          | 001...

models/gemma-3-27b-it          | 001...

models/gemma-3n-e4b-it         | 001...

models/gemma-3n-e2b-it         | 001...

models/gemma-4-26b-a4b-it      | 001...

models/gemma-4-31b-it          | 001...

models/gemini-flash-latest     | Gemini Flash Latest...

models/gemini-flash-lite-latest | Gemini Flash-Lite Latest...

models/gemini-pro-latest       | Gemini Pro Latest...

models/gemini-2.5-flash-lite   | 001...

models/gemini-2.5-flash-image  | 2.0...

models/gemini-3-pro-preview    | 3-pro-preview-11-2025...

models/gemini-3-flash-preview  | 3-flash-preview-12-2025...

models/gemini-3.1-pro-preview  | 3.1-pro-preview-01-2026...

models/gemini-3.1-pro-preview-customtools | 3.1-pro-preview-01-2026...

models/gemini-3.1-flash-lite-preview | 3.1-flash-lite-preview-03-2026...

models/gemini-3-pro-image-preview | 3.0...

models/nano-banana-pro-preview | 3.0...

models/gemini-3.1-flash-image-preview | 3.0...

models/gemini-3.1-pro-preview-customtools | 3.1-pro-preview-01-2026...

models/gemini-3.1-flash-lite-preview | 3.1-flash-lite-preview-03-2026...

models/gemini-3-pro-image-preview | 3.0...

models/nano-banana-pro-preview | 3.0...

models/gemini-3.1-flash-image-preview | 3.0...

models/gemini-3-pro-image-preview | 3.0...

models/nano-banana-pro-preview | 3.0...

models/gemini-3.1-flash-image-preview | 3.0...

models/gemini-3.1-flash-image-preview | 3.0...

models/lyria-3-clip-preview    | lyria-3-clip-preview...

models/lyria-3-pro-preview     | lyria-3-pro-preview...

models/gemini-robotics-er-1.5-preview | 1.5-preview...

models/gemini-2.5-computer-use-preview-10-2025 | Gemini 2.5 Computer Use Preview 10-2025...

models/deep-research-pro-preview-12-2025 | deepthink-exp-05-20...

Status code: 200

------------------------------

AI Response: The capital of France is **Paris**.

------------------------------

PS C:\Lab\Python\python_code_v1> ^C

PS C:\Lab\Python\python_code_v1>  c:; cd 'c:\Lab\Python\python_code_v1'; & 'c:\Lab\Python\python_code_v1\.venv\Scripts\python.exe' 'c:\Users\PijushBiswas\.vscode\extensions\ms-python.debugpy-2025.18.0-win32-x64\bundled\libs\debugpy\launcher' '49250' '--' 'C:\Lab\Python\python_code_v1\api.py'        

API Testing for Google AIs - Gemini 1.0 Pro

Status code: 200

------------------------------

AI Response: ```json

[

  {

    "name": "Andhra Pradesh",

    "area_sq_km": 162975,

    "population_2011": 84580777,

    "capital": "Amaravati"

  },

  {

    "name": "Arunachal Pradesh",

    "area_sq_km": 83743,

    "name": "Andhra Pradesh",

    "area_sq_km": 162975,

    "population_2011": 84580777,

    "capital": "Amaravati"

  },

  {

    "name": "Andhra Pradesh",

    "area_sq_km": 162975,

    "population_2011": 84580777,

    "name": "Andhra Pradesh",

    "area_sq_km": 162975,

    "name": "Andhra Pradesh",

    "name": "Andhra Pradesh",

    "area_sq_km": 162975,

    "population_2011": 84580777,

    "capital": "Amaravati"

  },

  {

    "name": "Arunachal Pradesh",

    "area_sq_km": 83743,

    "population

------------------------------

PS C:\Lab\Python\python_code_v1> python api.py                                                      

C:\Python312\Lib\site-packages\requests\__init__.py:113: RequestsDependencyWarning: urllib3 (2.6.3) or chardet (6.0.0.post1)/charset_normalizer (3.4.4) doesn't match a supported version!              

  warnings.warn(

API Testing for Google AIs - Gemini 1.0 Pro

Status code: 200

------------------------------

AI Response: ```json

{

  "states": [

    {

      "name": "Andhra Pradesh",

      "area_sq_km": 162975,

      "population": 49577103,

      "capital": "Amaravati"

    },

    {

      "name": "Arunachal Pradesh",

      "area_sq_km": 83743,

      "population": 1383727,

      "capital": "Itanagar"

    },

    {

      "name": "Assam",

      "area_sq_km": 78438,

      "population": 31205576,

      "capital": "Dispur"

    },

    {

      "name": "Bihar",

      "area_sq_km": 94163,

      "population": 104099452,

      "capital": "Patna"

    },

    {

      "name": "Chhattisgarh",

      "area_sq_km": 135192,

      "population": 25545198,

      "capital": "Raipur"

    },

    {

      "name": "Goa",

      "area_sq_km": 3702,

      "population": 1458545,

      "capital": "Panaji"

    },

    {

      "name": "Gujarat",

      "area_sq_km": 196244,

      "population": 60439692,

      "capital": "Gandhinagar"

    },

    {

      "name": "Haryana",

      "area_sq_km": 44212,

      "population": 25351462,

      "capital": "Chandigarh"

    },

    {

      "name": "Himachal Pradesh",

      "area_sq_km": 55673,

      "population": 6864602,

      "capital": "Shimla"

    },

    {

      "name": "Jharkhand",

      "area_sq_km": 79716,

      "population": 32988134,

      "capital": "Ranchi"

    },

    {

      "name": "Karnataka",

      "area_sq_km": 191791,

      "population": 61095297,

      "capital": "Bengaluru"

    },

    {

      "name": "Kerala",

      "area_sq_km": 38863,

      "population": 33406061,

      "capital": "Thiruvananthapuram"

    },

    {

      "name": "Madhya Pradesh",

      "area_sq_km": 308252,

      "population": 72626809,

      "capital": "Bhopal"

    },

    {

      "name": "Maharashtra",

      "area_sq_km": 307713,

      "population": 112374333,

      "capital": "Mumbai"

    },

    {

      "name": "Manipur",

      "area_sq_km": 22327,

      "population": 2855794,

      "capital": "Imphal"

    },

    {

      "name": "Meghalaya",

      "area_sq_km": 22429,

      "population": 2966889,

      "capital": "Shillong"

    },

    {

      "name": "Mizoram",

      "area_sq_km": 21081,

      "population": 1097206,

      "capital": "Aizawl"

    },

    {

      "name": "Nagaland",

      "area_sq_km": 16579,

      "population": 1978502,

      "capital": "Kohima"

    },

    {

      "name": "Odisha",

      "area_sq_km": 155707,

      "population": 41974218,

      "capital": "Bhubaneswar"

    },

    {

      "name": "Punjab",

      "area_sq_km": 50362,

      "population": 27743338,

      "capital": "Chandigarh"

    },

    {

      "name": "Rajasthan",

      "area_sq_km": 342239,

      "population": 68548437,

      "capital": "Jaipur"

    },

    {

      "name": "Sikkim",

      "area_sq_km": 7096,

      "population": 610577,

      "capital": "Gangtok"

    },

    {

      "name": "Tamil Nadu",

      "area_sq_km": 130058,

      "population": 72147030,

      "capital": "Chennai"

    },

    {

      "name": "Telangana",

      "area_sq_km": 112077,

      "population": 35003674,

      "capital": "Hyderabad"

    },

    {

      "name": "Tripura",

      "area_sq_km": 10486,

      "population": 3673917,

      "capital": "Agartala"

    },

    {

      "name": "Uttar Pradesh",

      "area_sq_km": 240928,

      "population": 199812341,

      "capital": "Lucknow"

    },

    {

      "name": "Uttarakhand",

      "area_sq_km": 53483,

      "population": 10086292,

      "capital": "Dehradun"

    },

    {

      "name": "West Bengal",

      "area_sq_km": 88752,

      "population": 91276115,

      "capital": "Kolkata"

    }

  ]

}

```

------------------------------


{
    "name": "Workflow for Google Gemini 1.5 Pro API Testing",
    "description": "This workflow tests the Google Gemini 1.5 Pro API using a simple prompt and prints the response.",
    "credentials": [
        {
            "name": "YetAgile",
            "email": "account1@gmail.com",
            "model": "gemini-2.5-flash-lite",
            "api_key": "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"
        },
         {
            "name": "XYZ Corp",
            "email": "account2@gmail.com",
            "model": "gemini-2.5-flash-lite",
            "api_key": "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"
        },
         {
            "name": "ABC Ltd",
            "email": "account3@gmail.com",
            "model": "gemini-2.5-flash-lite",
            "api_key": "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"
        },
         {
            "name": "DEF Inc",
            "email": "account4@gmail.com",
            "model": "gemini-2.5-flash-lite",
            "api_key": "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"
        }
    ]
}

from api import  GenAIModel, ModelRoundTable

configfile = "config.json"

model_round_table = ModelRoundTable([])
credentials = model_round_table.read_json_to_credential(configfile)

ai: GenAIModel = model_round_table.get_next_credential()

response_text = ai.test_api("What is the capital of France?")

if response_text:
    print("-" * 30)
    print(f"AI Response: {response_text}")
    print("-" * 30)

prompts =[
    "Provide me list of state in india with name, area, population, and capital in JSON format.",
    "What is the capital of India?",
    "What is the largest mammal on Earth?",
    "Who is the current president of the United States?"
]

for prompt in prompts:
    ai = model_round_table.get_next_credential()
    print(f"Testing Gemini 1.0 Pro with prompt: {prompt}")
    response_1_0 = ai.test_api(prompt)
    print(f"Gemini 1.0 Pro Response: {response_1_0}\n")



import requests
import json

# 1. Replace with your actual API Key from https://aistudio.google.com/
api_key = "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"

print("API Testing for Google AIs - Gemini 1.0 Pro")


MODEL_ID = "gemini-2.5-flash-lite"

# 2. The correct endpoint for Gemini 1.0         Pro
api_url = f"https://generativelanguage.googleapis.com/v1beta/models/{MODEL_ID}:generateContent?key={api_key}"


class ModelRoundTable:
    total = 4
    current = 0
    credentials = []

    def __init__(self, credentials):
        self.credentials = credentials
        self.total = len(credentials)
        self.current = 0

    def get_next_credential(self):
        if self.total == 0:
            return None
        credential = self.credentials[self.current]
        self.current = (self.current + 1) % self.total
        return credential
   
    def read_json_to_credential(self, json_file_path):
        """Read credentials from a JSON file and return a list of GenAIModel objects."""
        with open(json_file_path, 'r') as f:
            data = json.load(f)
       
        self.credentials = []
        for cred in data.get('credentials', []):
            model = GenAIModel(
                model=cred.get('model'),
                api_key=cred.get('api_key'),
                user=cred.get('name', cred.get('email', 'user'))
            )
            self.credentials.append(model)
        self.total = len(self.credentials)
        return self.credentials


class GenAIModel():
    model = "gemini-1.5-pro"
    api_key = "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"
    user = "user123"

    def __init__(self, model=None, api_key=None, user=None):
        if model:
            self.model = model
        if api_key:
            self.api_key = api_key
        if user:
            self.user = user
    def to_url(self):
        return f"https://generativelanguage.googleapis.com/v1beta/models/{self.model}:generateContent?key={self.api_key}"

    def test_api(self, prompt_text):
        headers = {
            "Content-Type": "application/json"
        }
        api_url = self.to_url()
        print(f"Testing API at URL: {api_url}")
        # 3. The specific JSON structure Gemini requires
        data = {
            "contents": [
                {
                    "parts": [
                        {"text": prompt_text}
                    ]
                }
            ],
            "generationConfig": {
                "maxOutputTokens": 5000,
                "temperature": 0.7
            }
        }

        try:
            response = requests.post(api_url, headers=headers, json=data)
           
            print(f"Status code: {response.status_code}")
           
            if response.status_code == 200:
                result = response.json()
                # 4. Extracting the text from the nested response object
                answer = result['candidates'][0]['content']['parts'][0]['text']
                return answer
            else:
                print(f"Error Response: {response.text}")
                return None
               
        except Exception as e:
            print(f"An error occurred: {e}")
            return None

# Execute the test


import requests

print("API Testing for Google AIs  - Gemini 1.5 Pro")

api_url = "https://api.google.com/gemini/v1.5/pro"
api_key = "AIzaSyCZhXBp1i15IwTX2BpAZkeoqPNKRvGZ_b8"


'''
url = f"https://generativelanguage.googleapis.com/v1beta/models?key={api_key}"

response = requests.get(url)

if response.status_code == 200:
    data = response.json()
    print(f"{'Model Name':<30} | {'Methods Supported'}")
    print("-" * 60)
    for model in data['models']:
        # We look for 'generateContent' as that is the method used for AI chat
        if "generateContent" in model['supportedGenerationMethods']:
            print(f"{model['name']:<30} | {model['version']}...")
else:
    print(f"Error: {response.status_code}")
    print(response.text)
'''


def test_api(prompt):
   

    headers = {
        "Authorization": f"Bearer {api_key}",
        "Content-Type": "application/json"
    }
    data = {
        "prompt": prompt,
        "model": "gemini-1.5-pro",
        "max_tokens": 100
    }
    response = requests.post(api_url, headers=headers, json=data)
    print(f"Status code: {response.status_code}")
    print(f"Response text: {response.text}")
    try:
        return response.json()
    except Exception as e:
        print(f"JSON decode error: {e}")
        return None

respone = test_api("What is the capital of France?")
print(respone)





Comments

Popular posts from this blog

যমুনার বৃত্তান্ত: মর্মরের কারাগার

লেখকের নিয়তি

লীলা মজুমদার - আনন্দের জগৎ