Vertex AI로 스트리밍이 아닌 멀티턴 대화 만들기

Vertex AI SDK를 설정하고 모델에 연속으로 전송된 메시지 3개로 비스트리밍 대화를 만드는 방법을 보여주는 샘플입니다.

코드 샘플

Node.js

이 샘플을 사용해 보기 전에 Vertex AI 빠른 시작: 클라이언트 라이브러리 사용의 Node.js 설정 안내를 따르세요. 자세한 내용은 Vertex AI Node.js API 참고 문서를 참조하세요.

Vertex AI에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

const {GoogleGenAI} = require('@google/genai');
/**
 * TODO(developer): Update these variables before running the sample.
 */
async function createNonStreamingChat(
  projectId = 'PROJECT_ID',
  location = 'us-central1',
  model = 'gemini-2.5-flash'
) {
  // Initialize client with your Cloud project and location
  const client = new GoogleGenAI({
    vertexai: true,
    project: projectId,
    location: location,
  });

  const chat = client.chats.create({
    model: model,
  });

  const response1 = await chat.sendMessage({message: 'Hello'});
  console.log('Chat response 1: ', response1.text);

  const response2 = await chat.sendMessage({
    message: 'Can you tell me a scientific fun fact?',
  });
  console.log('Chat response 2: ', response2.text);

  const response3 = await chat.sendMessage({
    message: 'How can I learn more about that?',
  });
  console.log('Chat response 3: ', response3.text);
}

다음 단계

다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.