-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_gemma.py
More file actions
49 lines (39 loc) · 1.55 KB
/
Copy pathtest_gemma.py
File metadata and controls
49 lines (39 loc) · 1.55 KB
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
import asyncio
import httpx
from backend.config import settings
from backend.llm.auth import get_gcp_bearer_token
async def main():
endpoint_id = settings.VERTEX_LLM_ENDPOINT_ID
region = settings.VERTEX_LLM_REGION
project = settings.GCP_PROJECT
if not endpoint_id:
print("Please set VERTEX_LLM_ENDPOINT_ID in your .env file")
return
print(f"Testing Vertex AI Endpoint: {endpoint_id} in {region}")
token = get_gcp_bearer_token()
if not token:
print("Failed to get GCP token. Are you logged in via `gcloud auth application-default login`?")
return
url = f"https://{region}-aiplatform.googleapis.com/v1beta1/projects/{project}/locations/{region}/endpoints/{endpoint_id}/chat/completions"
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
payload = {
"model": "google/gemma-4-26B-A4B-it",
"messages": [
{"role": "user", "content": "Hello, please reply with a single word: 'Success!'"}
],
"max_tokens": 10,
"temperature": 0.0
}
print("Sending request...")
async with httpx.AsyncClient(timeout=60) as client:
response = await client.post(url, headers=headers, json=payload)
print(f"Status Code: {response.status_code}")
if response.status_code == 200:
print("Response:", response.json()["choices"][0]["message"]["content"])
else:
print("Error:", response.text)
if __name__ == "__main__":
asyncio.run(main())