First commit
This commit is contained in:
22
workspace/services/gemini_service.py
Normal file
22
workspace/services/gemini_service.py
Normal file
@@ -0,0 +1,22 @@
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user