Google Vertex AI

Gemini와 같은 생성 모델을 실행하기 위해 Google Vertex AI gRPC API를 호출하는 형식화된 인터페이스입니다.

소개

Google Vertex AI는 Gemini 제품군을 포함하여 Google의 파운데이션 및 생성 모델을 실행합니다. gRPC API는 google.cloud.aiplatform.v1.PredictionService 서비스를 통해 제공되며, 주요 메서드는 GenerateContentPredict입니다.

Vertex AI는 지역 엔드포인트를 사용합니다: 호스트는 <region>-aiplatform.googleapis.com(예: us-central1-aiplatform.googleapis.com)이며 TLS를 통해 포트 443에서 접근하고, JWT audience는 동일한 호스트(예: https://us-central1-aiplatform.googleapis.com/)와 일치해야 합니다.

요청은 TsgcGRPCVertexAIGenerateContentRequest로 작성되며, 이는 정규화된 Model(projects/<id>/locations/<region>/publishers/google/models/<model>, 예: gemini-1.5-flash)을 프롬프트 콘텐츠와 함께 설정합니다.

아래 예제는 서비스 계정 JWT로 인증하고, 지역 Vertex AI 호스트에 대해 TsgcHTTP2Client 위에 TsgcGRPCClient를 연결하고, authorization Bearer 메타데이터를 설정한 후, us-central1의 Gemini 모델에 대해 프롬프트와 함께 GenerateContent를 호출합니다.


    TsgcHTTP2Client *oHTTP2 = new TsgcHTTP2Client();
    oHTTP2->Host = "us-central1-aiplatform.googleapis.com";
    oHTTP2->Port = 443;
    oHTTP2->TLS = true;

    TsgcGRPCClient *oGRPC = new TsgcGRPCClient();
    oGRPC->Client = oHTTP2;

    // service-account JWT authentication (audience must match the regional host)
    oGRPC->GoogleCloudOptions->JWT->KeyFile = "service-account.json";
    oGRPC->GoogleCloudOptions->JWT->API_Endpoint = "https://us-central1-aiplatform.googleapis.com/";
    oGRPC->DefaultMetadata->AddValue("authorization", "Bearer " + oGRPC->GoogleCloudOptions->JWT->Token);

    // build the typed request and call the method
    TsgcGRPCVertexAIGenerateContentRequest *oRequest = new TsgcGRPCVertexAIGenerateContentRequest();
    oRequest->Model = "projects/my-project-id/locations/us-central1/publishers/google/models/gemini-1.5-flash";
    oRequest->AddText("Write a haiku about the sea.");
    TsgcGRPCResponse *oResponse = oGRPC->Call("google.cloud.aiplatform.v1.PredictionService", "GenerateContent", oRequest->ToBytes());
    ShowMessage(oResponse->DataString);
    delete oRequest;

Methods

Name설명
GenerateContent프롬프트가 주어지면 생성 모델(예: Gemini)에서 콘텐츠를 생성합니다.
Predict배포된 모델에 대해 예측을 실행합니다.

Demo

작동하는 샘플은 데모 폴더 Demos/21.GRPC/17.Vertex_AI에서 제공되며, 지역 엔드포인트에 대해 인증하고 GenerateContent 메서드로 Gemini 모델에서 콘텐츠를 생성하는 방법을 보여줍니다.

참조