import os import streamlit as st from embedchain import App # Load environment variables try: from dotenv import load_dotenv load_dotenv() except ImportError: pass # dotenv not installed, likely running on Hugging Face Spaces # Function to get the API key def get_api_key(name): api_key = os.environ.get(name) if not api_key: api_key = st.secrets.get(name) if not api_key: raise ValueError( f"{name} is not set. Please set it in your environment or Streamlit secrets.") return api_key config_dict = { 'app': { 'config': { 'name': 'ttv-ec' } }, 'llm': { 'provider': 'huggingface', 'config': { 'model': 'mistralai/Mistral-7B-Instruct-v0.2', 'top_p': 0.5, 'stream': False, 'prompt': """You are an AI assistant that answers questions based solely on the information provided in your knowledge base. Question: $query Context: $context If the information to answer a question is not available in your knowledge base, respond with 'I don't have enough information to answer that question. """, 'api_key': get_api_key('HF_TOKEN') } }, 'embedder': { 'provider': 'huggingface', 'config': { 'model': 'sentence-transformers/all-mpnet-base-v2', 'api_key': get_api_key('HF_TOKEN') } } } def create_app(): return App.from_config(config=config_dict)