File size: 1,490 Bytes
26df9fd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
56
57
58
59
60
61

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)