Google Gen AI SDK

새로운 Google 생성형 AI SDK는 Gemini 개발자 API와 Vertex AI (Gemini Enterprise API)를 통해 Gemini 2.0에 통합된 인터페이스를 제공합니다. 몇 가지 예외를 제외하고 한 플랫폼에서 실행되는 코드는 두 플랫폼에서 모두 실행됩니다. Gen AI SDK는 Gemini 1.5 모델도 지원합니다.

Python

Python용 Google Gen AI SDK는 PyPIGitHub에서 사용할 수 있습니다.

자세한 내용은 Python SDK 참조를 참고하세요.

빠른 시작

1. SDK 설치

pip install google-genai

2. 라이브러리 가져오기

from google import genai

3. 클라이언트 만들기

client = genai.Client(api_key='GEMINI_API_KEY')

4. 콘텐츠 생성

response = client.models.generate_content(
    model='gemini-2.0-flash', contents='How does RLHF work?'
)
print(response.text)

Go

Go용 Google 생성형 AI SDK는 go.devGitHub에서 사용할 수 있습니다.

빠른 시작

1. 라이브러리 가져오기

import "google.golang.org/genai"

2. 클라이언트 만들기

client, err := genai.NewClient(ctx, &genai.ClientConfig{
    APIKey:   apiKey,
    Backend:  genai.BackendGeminiAPI,
})

3. 콘텐츠 생성

// Call the GenerateContent method
  result, err := client.Models.GenerateContent(ctx, "gemini-2.0-flash", genai.Text("How does RLHF work?"), nil)

자바

Java용 Google Gen AI SDK는 MavenGitHub를 통해 사용할 수 있습니다.

빠른 시작

1. 라이브러리 가져오기

Maven을 사용하는 경우 종속 항목에 다음을 추가합니다.

<dependencies>
  <dependency>
    <groupId>com.google.genai</groupId>
    <artifactId>google-genai</artifactId>
    <version>0.1.0</version>
  </dependency>
</dependencies>

2. 클라이언트 만들기

import com.google.genai.Client;

// The client gets the API key from the environment variable `GOOGLE_API_KEY`
Client client = new Client();

// Use the builder class for instantiation.
Client client = Client.builder().apiKey("your-api-key").build();

3. 콘텐츠 생성

package <your.pack.name>;

import com.google.genai.Client;
import com.google.genai.types.GenerateContentResponse;
import java.io.IOException;
import org.apache.http.HttpException;

public class GenerateContentWithTextInput {
  public static void main(String[] args) throws IOException, HttpException {
    Client client = new Client();

    GenerateContentResponse response =
        client.models.generateContent("gemini-2.0-flash-001", "How does RLHF work?", null);
    System.out.println("Unary response: " + response.text());
  }
}