Commit
Β·
dfdeb30
1
Parent(s):
ef2b4e3
docs: add UI simplification spec for BYOK cleanup
Browse filesAddresses GitHub issues #52 and #53:
- Remove api_provider dropdown (auto-detect from key prefix)
- Simplify examples table to just query + mode
- Clearer free tier messaging
Spec: docs/bugs/FIX_UI_SIMPLIFICATION.md
docs/bugs/FIX_UI_SIMPLIFICATION.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# UI Simplification: Remove Anthropic Provider
|
| 2 |
+
|
| 3 |
+
**Issues**: #52, #53
|
| 4 |
+
**Priority**: P1 - UX improvement for hackathon demo
|
| 5 |
+
**Estimated Time**: 30 minutes
|
| 6 |
+
|
| 7 |
+
---
|
| 8 |
+
|
| 9 |
+
## Problem
|
| 10 |
+
|
| 11 |
+
The current UI has confusing BYOK (Bring Your Own Key) settings:
|
| 12 |
+
|
| 13 |
+
1. **Provider dropdown is misleading** - Shows "openai" but actually uses free tier when no key
|
| 14 |
+
2. **Examples table shows useless columns** - API Key (empty), Provider (ignored)
|
| 15 |
+
3. **Anthropic doesn't work with Advanced mode** - Only OpenAI has `agent-framework` support
|
| 16 |
+
|
| 17 |
+
## Solution
|
| 18 |
+
|
| 19 |
+
Remove `api_provider` dropdown entirely. Auto-detect provider from key prefix.
|
| 20 |
+
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
## Implementation
|
| 24 |
+
|
| 25 |
+
### File: `src/app.py`
|
| 26 |
+
|
| 27 |
+
#### 1. Update `configure_orchestrator()` signature
|
| 28 |
+
|
| 29 |
+
```python
|
| 30 |
+
# BEFORE
|
| 31 |
+
def configure_orchestrator(
|
| 32 |
+
use_mock: bool = False,
|
| 33 |
+
mode: str = "simple",
|
| 34 |
+
user_api_key: str | None = None,
|
| 35 |
+
api_provider: str = "openai", # REMOVE THIS
|
| 36 |
+
) -> tuple[Any, str]:
|
| 37 |
+
|
| 38 |
+
# AFTER
|
| 39 |
+
def configure_orchestrator(
|
| 40 |
+
use_mock: bool = False,
|
| 41 |
+
mode: str = "simple",
|
| 42 |
+
user_api_key: str | None = None,
|
| 43 |
+
) -> tuple[Any, str]:
|
| 44 |
+
```
|
| 45 |
+
|
| 46 |
+
#### 2. Auto-detect provider from key prefix
|
| 47 |
+
|
| 48 |
+
```python
|
| 49 |
+
# Inside configure_orchestrator, replace provider logic with:
|
| 50 |
+
if user_api_key:
|
| 51 |
+
# Auto-detect provider from key prefix
|
| 52 |
+
if user_api_key.startswith("sk-ant-"):
|
| 53 |
+
# Anthropic key
|
| 54 |
+
anthropic_provider = AnthropicProvider(api_key=user_api_key)
|
| 55 |
+
model = AnthropicModel(settings.anthropic_model, provider=anthropic_provider)
|
| 56 |
+
backend_info = "Paid API (Anthropic)"
|
| 57 |
+
elif user_api_key.startswith("sk-"):
|
| 58 |
+
# OpenAI key
|
| 59 |
+
openai_provider = OpenAIProvider(api_key=user_api_key)
|
| 60 |
+
model = OpenAIModel(settings.openai_model, provider=openai_provider)
|
| 61 |
+
backend_info = "Paid API (OpenAI)"
|
| 62 |
+
else:
|
| 63 |
+
raise ValueError("Invalid API key format. Expected sk-... (OpenAI) or sk-ant-... (Anthropic)")
|
| 64 |
+
|
| 65 |
+
judge_handler = JudgeHandler(model=model)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
#### 3. Update `research_agent()` signature
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
# BEFORE
|
| 72 |
+
async def research_agent(
|
| 73 |
+
message: str,
|
| 74 |
+
history: list[dict[str, Any]],
|
| 75 |
+
mode: str = "simple",
|
| 76 |
+
api_key: str = "",
|
| 77 |
+
api_provider: str = "openai", # REMOVE THIS
|
| 78 |
+
) -> AsyncGenerator[str, None]:
|
| 79 |
+
|
| 80 |
+
# AFTER
|
| 81 |
+
async def research_agent(
|
| 82 |
+
message: str,
|
| 83 |
+
history: list[dict[str, Any]],
|
| 84 |
+
mode: str = "simple",
|
| 85 |
+
api_key: str = "",
|
| 86 |
+
) -> AsyncGenerator[str, None]:
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
#### 4. Update warning message for Advanced mode
|
| 90 |
+
|
| 91 |
+
```python
|
| 92 |
+
# BEFORE
|
| 93 |
+
if mode == "advanced" and not (has_openai or (has_user_key and api_provider == "openai")):
|
| 94 |
+
|
| 95 |
+
# AFTER
|
| 96 |
+
is_openai_key = user_api_key and user_api_key.startswith("sk-") and not user_api_key.startswith("sk-ant-")
|
| 97 |
+
if mode == "advanced" and not (has_openai or is_openai_key):
|
| 98 |
+
yield (
|
| 99 |
+
"β οΈ **Advanced mode requires OpenAI API key.** "
|
| 100 |
+
"Anthropic keys only work in Simple mode. Falling back to Simple.\\n\\n"
|
| 101 |
+
)
|
| 102 |
+
mode = "simple"
|
| 103 |
+
```
|
| 104 |
+
|
| 105 |
+
#### 5. Simplify examples (remove provider column)
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
# BEFORE
|
| 109 |
+
examples=[
|
| 110 |
+
["What drugs improve female libido post-menopause?", "simple", "", "openai"],
|
| 111 |
+
["Clinical trials for erectile dysfunction alternatives to PDE...", "simple", "", "openai"],
|
| 112 |
+
["Evidence for testosterone therapy in women with HSDD?", "simple", "", "openai"],
|
| 113 |
+
]
|
| 114 |
+
|
| 115 |
+
# AFTER
|
| 116 |
+
examples=[
|
| 117 |
+
["What drugs improve female libido post-menopause?", "simple", ""],
|
| 118 |
+
["Clinical trials for ED alternatives to PDE5 inhibitors?", "simple", ""],
|
| 119 |
+
["Evidence for testosterone therapy in women with HSDD?", "simple", ""],
|
| 120 |
+
]
|
| 121 |
+
```
|
| 122 |
+
|
| 123 |
+
#### 6. Remove provider from additional_inputs
|
| 124 |
+
|
| 125 |
+
```python
|
| 126 |
+
# BEFORE
|
| 127 |
+
additional_inputs=[
|
| 128 |
+
gr.Radio(
|
| 129 |
+
choices=["simple", "advanced"],
|
| 130 |
+
value="simple",
|
| 131 |
+
label="Orchestrator Mode",
|
| 132 |
+
...
|
| 133 |
+
),
|
| 134 |
+
gr.Textbox(
|
| 135 |
+
label="π API Key (Optional - BYOK)",
|
| 136 |
+
...
|
| 137 |
+
),
|
| 138 |
+
gr.Radio( # REMOVE THIS ENTIRE BLOCK
|
| 139 |
+
choices=["openai", "anthropic"],
|
| 140 |
+
value="openai",
|
| 141 |
+
label="API Provider",
|
| 142 |
+
...
|
| 143 |
+
),
|
| 144 |
+
]
|
| 145 |
+
|
| 146 |
+
# AFTER
|
| 147 |
+
additional_inputs=[
|
| 148 |
+
gr.Radio(
|
| 149 |
+
choices=["simple", "advanced"],
|
| 150 |
+
value="simple",
|
| 151 |
+
label="Orchestrator Mode",
|
| 152 |
+
info="Simple: Works with free tier | Advanced: Requires OpenAI key",
|
| 153 |
+
),
|
| 154 |
+
gr.Textbox(
|
| 155 |
+
label="π API Key (Optional)",
|
| 156 |
+
placeholder="sk-... (OpenAI) or sk-ant-... (Anthropic)",
|
| 157 |
+
type="password",
|
| 158 |
+
info="Leave empty for free tier (Llama 3.1). Auto-detects provider from key.",
|
| 159 |
+
),
|
| 160 |
+
]
|
| 161 |
+
```
|
| 162 |
+
|
| 163 |
+
#### 7. Update accordion label
|
| 164 |
+
|
| 165 |
+
```python
|
| 166 |
+
additional_inputs_accordion=gr.Accordion(
|
| 167 |
+
label="βοΈ Settings (Free tier works without API key)",
|
| 168 |
+
open=False
|
| 169 |
+
),
|
| 170 |
+
```
|
| 171 |
+
|
| 172 |
+
---
|
| 173 |
+
|
| 174 |
+
## Testing
|
| 175 |
+
|
| 176 |
+
### Manual Tests
|
| 177 |
+
1. **No key**: Should use free tier (HuggingFace Inference)
|
| 178 |
+
2. **OpenAI key**: Should detect and use OpenAI
|
| 179 |
+
3. **Anthropic key**: Should detect and use Anthropic in Simple mode
|
| 180 |
+
4. **Anthropic key + Advanced**: Should warn and fallback to Simple
|
| 181 |
+
|
| 182 |
+
### Unit Test Updates
|
| 183 |
+
- Update `tests/unit/test_app_smoke.py` if it checks additional_inputs count
|
| 184 |
+
|
| 185 |
+
---
|
| 186 |
+
|
| 187 |
+
## Definition of Done
|
| 188 |
+
|
| 189 |
+
- [ ] `api_provider` parameter removed from both functions
|
| 190 |
+
- [ ] Auto-detection logic works for both key types
|
| 191 |
+
- [ ] Examples table only shows 2 columns (query, mode)
|
| 192 |
+
- [ ] Accordion label updated
|
| 193 |
+
- [ ] Placeholder text shows key formats
|
| 194 |
+
- [ ] Advanced mode warning works with auto-detection
|
| 195 |
+
- [ ] All existing tests pass
|
| 196 |
+
|
| 197 |
+
---
|
| 198 |
+
|
| 199 |
+
## Related
|
| 200 |
+
- Issue #52: UI Polish - Examples table confusion
|
| 201 |
+
- Issue #53: API Provider Simplification
|