Spaces:
Sleeping
Sleeping
Create llms.py
Browse files
llms.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from langchain_google_genai import ChatGoogleGenerativeAI
|
| 7 |
+
|
| 8 |
+
load_dotenv()
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def build_llm(model_name: str, temperature: float) -> ChatGoogleGenerativeAI:
|
| 12 |
+
api_key = os.getenv("GEMINI_API_KEY")
|
| 13 |
+
if not api_key:
|
| 14 |
+
raise ValueError("GEMINI_API_KEY is not set in the environment.")
|
| 15 |
+
return ChatGoogleGenerativeAI(
|
| 16 |
+
model=model_name,
|
| 17 |
+
google_api_key=api_key,
|
| 18 |
+
temperature=temperature,
|
| 19 |
+
)
|