23 lines
678 B
Python
23 lines
678 B
Python
import os
|
|
import google.generativeai as genai
|
|
from dotenv import load_dotenv
|
|
from typing import List
|
|
|
|
load_dotenv()
|
|
|
|
class GeminiService:
|
|
def __init__(self):
|
|
self.api_key = os.getenv("GEMINI_API_KEY")
|
|
if not self.api_key:
|
|
raise ValueError("GEMINI_API_KEY not found in .env file")
|
|
genai.configure(api_key=self.api_key)
|
|
|
|
async def generate_content(self, prompts: List[str], model: str = "gemini-2.5-flash"):
|
|
"""
|
|
Generates content using the Gemini API.
|
|
"""
|
|
model_instance = genai.GenerativeModel(model)
|
|
response = await model_instance.generate_content_async(prompts)
|
|
return response.text
|
|
|