|
|
| import os |
| import streamlit as st |
| from embedchain import App |
|
|
| |
| try: |
| from dotenv import load_dotenv |
| load_dotenv() |
| except ImportError: |
| pass |
|
|
| |
|
|
|
|
| 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) |
|
|