Spaces:
Running
Running
# config.py (Updated for OpenAI Generation) | |
import os | |
from dotenv import load_dotenv | |
load_dotenv() | |
# --- LangSmith Configuration --- | |
LANGSMITH_ENDPOINT = os.environ.get("LANGSMITH_ENDPOINT", "https://api.smith.langchain.com") | |
LANGSMITH_TRACING = os.environ.get("LANGSMITH_TRACING", "true") | |
LANGSMITH_API_KEY = os.environ.get("LANGSMITH_API_KEY") | |
LANGSMITH_PROJECT = os.environ.get("LANGSMITH_PROJECT", "DivreyYoel-RAG-GPT4-Gen") # Updated project name | |
# --- API Keys (Required) --- | |
# ANTHROPIC_API_KEY = os.environ.get("ANTHROPIC_API_KEY") # No longer needed | |
OPENAI_API_KEY = os.environ.get("OPENAI_API_KEY") # Used for Embedding, Validation, AND Generation | |
PINECONE_API_KEY = os.environ.get("PINECONE_API_KEY") | |
# --- Model Configuration --- | |
# Embedding Model (Retriever) | |
EMBEDDING_MODEL = os.environ.get("OPENAI_EMBEDDING_MODEL", "text-embedding-3-large") | |
# Validation Model (OpenAI) | |
OPENAI_VALIDATION_MODEL = os.environ.get("OPENAI_VALIDATION_MODEL", "gpt-4o") | |
# Generation Model (OpenAI) - Can be the same or different from validation | |
OPENAI_GENERATION_MODEL = os.environ.get("OPENAI_GENERATION_MODEL", "gpt-4o") # Using GPT-4o for generation too | |
# --- Pinecone Configuration --- | |
PINECONE_INDEX_NAME = os.environ.get("PINECONE_INDEX_NAME", "chassidus-index") | |
# --- Default RAG Pipeline Parameters --- | |
DEFAULT_N_RETRIEVE = 100 | |
DEFAULT_N_VALIDATE = 50 | |
# --- System Prompts --- | |
# --- REMOVED ANTHROPIC_SYSTEM_PROMPT --- | |
# --- NEW OpenAI System Prompt --- | |
OPENAI_SYSTEM_PROMPT = """You are an expert assistant specializing in Chassidic texts, particularly the works of the Satmar Rebbe, Rabbi Yoel Teitelbaum (Divrei Yoel). | |
Your task is to answer the user's question based *exclusively* on the provided source text snippets (paragraphs from relevant books). Do not use any prior knowledge or external information. | |
**Source Text Format:** | |
The relevant source texts will be provided below under the heading "Source Texts:". Each source is numbered and includes an ID. | |
**Response Requirements:** | |
1. **Language:** Respond **exclusively in Hebrew**. | |
2. **Basis:** Base your answer *strictly* on the information contained within the provided "Source Texts:". Do not infer, add external knowledge, or answer if the context does not contain relevant information. | |
3. **Attribution (Optional but Recommended):** When possible, mention the source number (e.g., "ืืคื ืฉืืืคืืข ืืืงืืจ 3") where the information comes from. Do not invent information. Use quotes sparingly and only when essential, quoting the Hebrew text directly. | |
4. **Completeness:** Synthesize information from *multiple* relevant sources if they contribute to the answer. | |
5. **Handling Lack of Information:** If the provided sources do not contain information relevant to the question, state clearly in Hebrew that the provided texts do not contain the answer (e.g., "ืขื ืคื ืืืงืืจืืช ืฉืกืืคืงื, ืืื ืืืืข ืืขื ืืช ืขื ืฉืืื ืื."). Do not attempt to answer based on outside knowledge. | |
6. **Clarity and Conciseness:** Provide a clear, well-structured, and concise answer in Hebrew. Focus on directly answering the user's question. | |
7. **Tone:** Maintain a formal and respectful tone appropriate for discussing religious texts. | |
8. **No Greetings/Closings:** Do not include introductory greetings (e.g., "ืฉืืื") or concluding remarks (e.g., "ืืืจืื", "ืืงืืื ืฉืขืืจืชื"). Focus solely on the answer. | |
""" | |
# --- Helper Functions --- | |
def check_env_vars(): | |
"""Checks if essential API keys are present.""" | |
missing_keys = [] | |
if not LANGSMITH_API_KEY: missing_keys.append("LANGSMITH_API_KEY") | |
# if not ANTHROPIC_API_KEY: missing_keys.append("ANTHROPIC_API_KEY") # Removed check | |
if not OPENAI_API_KEY: missing_keys.append("OPENAI_API_KEY") | |
if not PINECONE_API_KEY: missing_keys.append("PINECONE_API_KEY") | |
return missing_keys | |
def configure_langsmith(): | |
"""Sets LangSmith environment variables.""" | |
os.environ["LANGSMITH_ENDPOINT"] = LANGSMITH_ENDPOINT | |
os.environ["LANGSMITH_TRACING"] = LANGSMITH_TRACING | |
if LANGSMITH_API_KEY: os.environ["LANGSMITH_API_KEY"] = LANGSMITH_API_KEY | |
if LANGSMITH_PROJECT: os.environ["LANGSMITH_PROJECT"] = LANGSMITH_PROJECT | |
print(f"LangSmith configured: Endpoint={LANGSMITH_ENDPOINT}, Tracing={LANGSMITH_TRACING}, Project={LANGSMITH_PROJECT or 'Default'}") | |
# --- Initial Check on Import --- | |
missing = check_env_vars() | |
if missing: | |
print(f"Warning: Missing essential API keys in Replit Secrets: {', '.join(missing)}") | |
else: | |
print("All essential API keys found in environment/secrets.") | |
configure_langsmith() |