AI, ML, DL
[Gemini] Gemini API for Python and C#
J-sean
2025. 11. 28. 21:32
반응형
Gemini API를 사용해 보자.
Python

from google import genai
client = genai.Client(api_key="your_api_key")
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="Gemini에 대해 짧게 설명해 줘."
)
print(response.text)
API Key는 Google AI Studio에서 발급 받는다.

C#

콘솔창 작업 디렉토리에서 아래 명령을 실행해도 된다.
dotnet add package Google.GenAI
using Google.GenAI;
Client client = new Client(apiKey: "your_api_key");
Google.GenAI.Types.GenerateContentResponse response = await client.Models.GenerateContentAsync(
model: "gemini-2.5-flash",
contents: "Tell me a joke about computers."
);
Console.WriteLine(response.Candidates[0].Content.Parts[0].Text);

※ 참고
반응형