File size: 5,782 Bytes
0f77bc1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
# config.py
"""
Configuration for SAP Chatbot
Auto-detects HuggingFace Spaces and Streamlit Cloud environments
"""

import os
from dotenv import load_dotenv

load_dotenv()

# ============== Environment Detection ==============
# Detect if running in HuggingFace Spaces or Streamlit Cloud
RUNNING_IN_HF_SPACES = os.getenv("SPACE_ID") is not None
RUNNING_IN_STREAMLIT_CLOUD = os.getenv("STREAMLIT_SERVER_HEADLESS") == "true"

# ============== LLM Configuration ==============
# Options: "ollama", "replicate", "huggingface"
# Default to HuggingFace when in HF Spaces, otherwise Ollama
default_provider = "huggingface" if RUNNING_IN_HF_SPACES else "ollama"
LLM_PROVIDER = os.getenv("LLM_PROVIDER", default_provider)

# Model names by provider
OLLAMA_MODELS = {
    "fast": "neural-chat",      # 3B, very fast
    "balanced": "mistral",       # 7B, good balance
    "quality": "dolphin-mixtral" # 8x7B, best quality
}

REPLICATE_MODELS = {
    "fast": "meta/llama-2-7b-chat",
    "quality": "mistral-community/mistral-7b-instruct-v0.2"
}

HF_MODELS = {
    "fast": "zephyr",  # HuggingFaceH4/zephyr-7b-beta - fast and efficient
    "balanced": "mistral",  # mistralai/Mistral-7B-Instruct-v0.1 - best quality/speed
    "quality": "llama2"  # meta-llama/Llama-2-7b-chat-hf - high quality
}

# Default model
DEFAULT_MODEL = os.getenv("LLM_MODEL", "mistral")

# API Tokens (if using cloud LLMs)
REPLICATE_API_TOKEN = os.getenv("REPLICATE_API_TOKEN")
HF_API_TOKEN = os.getenv("HF_API_TOKEN")
HF_DATASET_REPO = os.getenv("HF_DATASET_REPO", "your-username/sap-dataset")

# ============== RAG Configuration ==============
# Embeddings model (HuggingFace)
EMBEDDINGS_MODEL = os.getenv("EMBEDDINGS_MODEL", "all-MiniLM-L6-v2")

# Data paths
DATA_DIR = "data"
DATASET_PATH = os.path.join(DATA_DIR, "sap_dataset.json")
INDEX_PATH = os.path.join(DATA_DIR, "rag_index.faiss")
METADATA_PATH = os.path.join(DATA_DIR, "rag_metadata.pkl")

# RAG parameters
RAG_CHUNK_SIZE = 512
RAG_CHUNK_OVERLAP = 100
RAG_TOP_K = 5

# ============== Scraper Configuration ==============
# Web scraping delays (be respectful!)
SCRAPER_DELAY_MIN = 2
SCRAPER_DELAY_MAX = 5

# Max articles per source
MAX_ARTICLES_PER_SOURCE = 50

# ============== Streamlit Configuration ==============
STREAMLIT_PAGE_CONFIG = {
    "page_title": "SAP Chatbot",
    "page_icon": "🧩",
    "layout": "wide",
    "initial_sidebar_state": "expanded"
}

# ============== UI Configuration ==============
TITLE = "🧩 SAP Intelligent Assistant"
SUBTITLE = "Free RAG-based SAP Q&A System"
WELCOME_MESSAGE = """
Welcome to the SAP Intelligent Assistant! 👋

This is a free, open-source RAG (Retrieval-Augmented Generation) system that helps you with:
- SAP Basis administration
- SAP ABAP development
- SAP HANA
- SAP Fiori
- SAP Configuration & Security
- And more!

**How it works:**
1. Your question is searched against a knowledge base of SAP documents
2. Relevant documents are retrieved
3. An AI generates an answer based on the retrieved content

**Features:**
- 100% Free & Open Source
- Local LLM support (Ollama)
- Multi-source data (SAP Community, GitHub, blogs)
- Vector similarity search
- Conversation history

**To get started:**
1. Type your SAP question in the chat box
2. View the sources used for the answer
3. Continue the conversation naturally
"""

# ============== Help Messages ==============
HELP_MESSAGES = {
    "setup_ollama": """
### Setting up Ollama (Local LLM)

1. **Install Ollama**: Download from https://ollama.ai
2. **Start Ollama**: `ollama serve`
3. **Pull a model**: `ollama pull mistral` or `ollama pull neural-chat`
4. **In your terminal**: The server runs on localhost:11434

Supported models:
- **Neural Chat** (3B): Fast, good for quick responses
- **Mistral** (7B): Balanced quality and speed
- **Dolphin Mixtral** (8x7B): Best quality but slower
    """,
    
    "setup_replicate": """
### Setting up Replicate

1. **Get API Token**: https://replicate.com (sign up for free tier)
2. **Set environment variable**: 
   ```bash
   export REPLICATE_API_TOKEN="your_token_here"
   ```
3. **Models available**:
   - Llama 2 7B Chat
   - Mistral 7B
   - And more...
    """,
    
    "setup_huggingface": """
### Setting up HuggingFace

1. **Get API Token**: https://huggingface.co/settings/tokens
2. **Set environment variable**: 
   ```bash
   export HF_API_TOKEN="your_token_here"
   ```
3. **Models available**: Any HuggingFace text-generation model
    """
}

# ============== System Prompts ==============
SYSTEM_PROMPTS = {
    "sap_expert": """You are an expert SAP consultant with deep knowledge of:
- SAP Basis & System Administration
- SAP ABAP & Web Dynpro
- SAP HANA & Database
- SAP Security & Authorization
- SAP Fiori & UI Technologies
- SAP Transport & Change Management
- SAP Performance & Optimization

Provide clear, accurate, practical advice. When citing sources, be specific.
If unsure, acknowledge and suggest official SAP documentation.""",

    "basis_expert": """You are a SAP Basis expert specializing in:
- System administration and monitoring
- Transport management systems
- Background job management
- System performance tuning
- Patch and upgrade management
- System security and authorization

Provide step-by-step guidance with transaction codes and best practices.""",

    "developer": """You are a SAP ABAP developer expert. Help with:
- ABAP programming and development
- Web Dynpro and UI5/Fiori
- Reports and forms
- Interfaces and integration
- Debugging and troubleshooting

Include code examples and best practices."""
}

if __name__ == "__main__":
    print("SAP Chatbot Configuration")
    print(f"LLM Provider: {LLM_PROVIDER}")
    print(f"Model: {DEFAULT_MODEL}")
    print(f"Data Directory: {DATA_DIR}")
    print(f"Embeddings Model: {EMBEDDINGS_MODEL}")