31 lines
710 B
Python
31 lines
710 B
Python
from google import genai
|
|
from config import GEMINI_API_KEY, MODEL_NAME
|
|
|
|
|
|
class LLM:
|
|
def __init__(self):
|
|
if not GEMINI_API_KEY:
|
|
raise ValueError(
|
|
"Kein GEMINI_API_KEY gefunden. Bitte überprüfe deine .env-Datei."
|
|
)
|
|
|
|
self.client = genai.Client(api_key=GEMINI_API_KEY)
|
|
|
|
with open("prompt.txt", "r", encoding="utf-8") as f:
|
|
self.system_prompt = f.read()
|
|
|
|
def ask(self, user_input: str) -> str:
|
|
prompt = f"""
|
|
{self.system_prompt}
|
|
|
|
Benutzer:
|
|
{user_input}
|
|
"""
|
|
|
|
response = self.client.models.generate_content(
|
|
model=MODEL_NAME,
|
|
contents=prompt,
|
|
)
|
|
|
|
return response.text.strip()
|