-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
`import openai
from google.auth import default
import google.auth.transport.requests
TODO(developer): Update and un-comment below lines
project_id = "PROJECT_ID"
location = "global"
Programmatically get an access token
credentials, _ = default(scopes=["https://www.googleapis.com/auth/cloud-platform"])
credentials.refresh(google.auth.transport.requests.Request())
OpenAI Client
client = openai.OpenAI(
base_url=f"https://aiplatform.googleapis.com/v1/projects/{project_id}/locations/{location}/endpoints/openapi",
api_key=credentials.token
)
response = client.chat.completions.create(
model="google/gemini-2.0-flash-001",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Explain to me how AI works"}
]
)
print(response.choices[0].message)`
通过Accesstoken 调用,不支持这种格式吗?
Gemini VertexAI OpenAI规范地址
https://docs.cloud.google.com/vertex-ai/generative-ai/docs/start/openai?hl=zh-cn