Skip to content

Commit d93d406

Browse files
authored
Merge pull request #6 from dristy-daxa/dristy-safeinfer-chatbot
Dristy safeinfer chatbot
2 parents dbb3c43 + a6bb408 commit d93d406

File tree

3 files changed

+17
-36
lines changed

3 files changed

+17
-36
lines changed

safe_infer_chatbot_app/README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ Then open your browser to `http://localhost:8501`
5151
```bash
5252
export PEBBLO_API_KEY="pebblo-api-key"
5353
export PROXIMA_HOST="http://your-proxima-host"
54-
export PROXIMA_USER_USERNAME="your-proxima-username"
55-
export PROXIMA_USER_PASSWORD="your-proxima-password"
5654
```
5755

5856
4. **Run the application**:
@@ -67,6 +65,7 @@ Then open your browser to `http://localhost:8501`
6765
### Environment Variables
6866

6967
- `PROXIMA_HOST`: Base URL for the SafeInfer API (default: `http://localhost`)
68+
- `PEBBLO_API_KEY`: Pebblo API Key
7069

7170
### API Configuration
7271

safe_infer_chatbot_app/safe_infer_chatbot.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from typing import Dict, Any
66
import time
77

8+
9+
810
# Page configuration
911
st.set_page_config(
1012
page_title="SafeInfer LLM Chatbot",
@@ -98,8 +100,7 @@ def call_safe_infer_api(message: str, model: str, api_key: str = "") -> Dict[str
98100

99101
payload = {
100102
"model": model,
101-
"input": message,
102-
"app": "chatbot",
103+
"input": message
103104
}
104105

105106
try:
@@ -191,14 +192,15 @@ def display_chat_message(role: str, content: str, model: str = "", timestamp: st
191192
st.header("⚙️ Configuration")
192193

193194
# Model selection
194-
st.subheader("🤖 Model Selection")
195195
available_models = AVAILABLE_MODELS
196-
selected_model = st.selectbox(
197-
"Choose a model:",
198-
available_models,
199-
index=available_models.index(st.session_state.selected_model)
200-
)
201-
st.session_state.selected_model = selected_model
196+
if available_models:
197+
st.subheader("🤖 Model Selection")
198+
selected_model = st.selectbox(
199+
"Choose a model:",
200+
available_models,
201+
index=available_models.index(st.session_state.selected_model)
202+
)
203+
st.session_state.selected_model = selected_model
202204

203205
# API connection test
204206
st.subheader("🔗 API Status")

safe_infer_chatbot_app/utils.py

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,20 @@
22

33
import requests
44

5-
def get_proxima_cookie():
6-
try:
7-
proxima_url = f"{os.environ.get('PROXIMA_HOST')}/api/auth/login"
8-
headers = {
9-
'accept': 'application/json',
10-
'Content-Type': 'application/x-www-form-urlencoded'
11-
}
12-
data = {
13-
"username": os.environ.get("PROXIMA_USER_USERNAME"),
14-
"password": os.environ.get("PROXIMA_USER_PASSWORD")
15-
}
16-
response = requests.post(proxima_url, headers=headers, data=data)
17-
18-
response.raise_for_status()
19-
20-
token = response.headers['set-cookie'].split(';')[0]
21-
return token
22-
except Exception as e:
23-
print(f"Error getting proxima cookie: {e}")
24-
raise e
25-
26-
275

286
def get_available_models():
297
try:
30-
proxima_cookie = get_proxima_cookie()
318
headers = {
329
'accept': 'application/json',
10+
'Authorization': f"Bearer {os.environ.get('PEBBLO_API_KEY')}",
3311
'Content-Type': 'application/x-www-form-urlencoded',
34-
'Cookie': f"fastapiusersauth={proxima_cookie}"
3512
}
36-
response = requests.get(f"{os.environ.get('PROXIMA_HOST')}/api/llm/provider", headers=headers)
13+
url = f"{os.environ.get('PROXIMA_HOST')}/safe_infer/llm/provider/list"
14+
response = requests.get(url, headers=headers)
3715
response.raise_for_status()
3816
models = response.json()
17+
if len(models) == 0:
18+
return [], ""
3919
model_names = [model['default_model_name'] for model in models]
4020

4121
default_model_name = next(model for model in models if model['is_default_provider'])['default_model_name']

0 commit comments

Comments
 (0)