File size: 1,341 Bytes
aaa4ec9
 
 
1d1b426
e8e3115
 
aaa4ec9
 
 
 
 
 
 
 
 
 
 
 
 
b55588d
aaa4ec9
 
 
 
 
 
 
 
9e38dfa
aaa4ec9
 
 
 
 
e8e3115
 
 
 
 
 
 
aaa4ec9
e8e3115
 
 
aaa4ec9
e8e3115
 
 
 
1d1b426
aaa4ec9
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import os
import sys
import logging
from api.vectorstore import VectorStoreManager
from dotenv import load_dotenv
from google import genai

logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s [%(levelname)s] %(message)s",
    handlers=[logging.StreamHandler(sys.stdout)],
)

logger = logging.getLogger(__name__)

load_dotenv()

GOOGLE_API_KEY = os.environ.get("GOOGLE_API_KEY", "")
PINECONE_API_KEY = os.environ.get("PINECONE_API_KEY", "")
INDEX_NAME = "ragbot"


def log_critical(api_key: str):
    logger.critical(f"CRITICAL: {api_key} is missing from .env")
    sys.exit(1)


if not GOOGLE_API_KEY:
    log_critical("GOOGLE_API_KEY")

if not PINECONE_API_KEY:
    log_critical("PINECONE_API_KEY")


def system_instruction(url: str, context: str):
    return f"""
    INSTRUCTION:
    You are a helpful assistant for the website: {url}.  
    Answer only using the provided context below.  
    If the information is missing, reply: "Sorry, I haven't read that information yet."  
    Limit every answer to five sentences.

    CONTEXT:
    {context}
    """


try:
    vs = VectorStoreManager(api_key=PINECONE_API_KEY, index_name=INDEX_NAME)
    flash = genai.Client()
    logger.info("✅ System initialized: Pinecone & Gemini ready.")
except Exception as e:
    logger.critical(f"Startup Failure: {e}")
    sys.exit(1)