Skip to content

Commit 756193d

Browse files
authored
Load models in the UI without navigating the page (#173)
* Load models in the UI without navigating the page * fix table layout for mobile
1 parent a6b2e93 commit 756193d

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

ui/src/contexts/APIProvider.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface APIProviderType {
1212
models: Model[];
1313
listModels: () => Promise<Model[]>;
1414
unloadAllModels: () => Promise<void>;
15+
loadModel: (model: string) => Promise<void>;
1516
enableProxyLogs: (enabled: boolean) => void;
1617
enableUpstreamLogs: (enabled: boolean) => void;
1718
enableModelUpdates: (enabled: boolean) => void;
@@ -139,11 +140,26 @@ export function APIProvider({ children }: APIProviderProps) {
139140
}
140141
}, []);
141142

143+
const loadModel = useCallback(async (model: string) => {
144+
try {
145+
const response = await fetch(`/upstream/${model}/`, {
146+
method: "GET",
147+
});
148+
if (!response.ok) {
149+
throw new Error(`Failed to load model: ${response.status}`);
150+
}
151+
} catch (error) {
152+
console.error("Failed to load model:", error);
153+
throw error; // Re-throw to let calling code handle it
154+
}
155+
}, []);
156+
142157
const value = useMemo(
143158
() => ({
144159
models,
145160
listModels,
146161
unloadAllModels,
162+
loadModel,
147163
enableProxyLogs,
148164
enableUpstreamLogs,
149165
enableModelUpdates,
@@ -154,6 +170,7 @@ export function APIProvider({ children }: APIProviderProps) {
154170
models,
155171
listModels,
156172
unloadAllModels,
173+
loadModel,
157174
enableProxyLogs,
158175
enableUpstreamLogs,
159176
enableModelUpdates,

ui/src/index.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@
143143
@apply bg-surface p-2 px-4 text-sm rounded-full border border-2 transition-colors duration-200 border-btn-border;
144144
}
145145

146+
.btn:hover {
147+
cursor: pointer;
148+
}
149+
146150
.btn--sm {
147151
@apply px-2 py-0.5 text-xs;
148152
}

ui/src/pages/Models.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { useAPI } from "../contexts/APIProvider";
33
import { LogPanel } from "./LogViewer";
44

55
export default function ModelsPage() {
6-
const { models, enableModelUpdates, unloadAllModels, upstreamLogs, enableUpstreamLogs } = useAPI();
6+
const { models, enableModelUpdates, unloadAllModels, loadModel, upstreamLogs, enableUpstreamLogs } = useAPI();
77
const [isUnloading, setIsUnloading] = useState(false);
88

99
useEffect(() => {
@@ -43,17 +43,21 @@ export default function ModelsPage() {
4343
<thead>
4444
<tr className="border-b border-primary">
4545
<th className="text-left p-2">Name</th>
46+
<th className="text-left p-2"></th>
4647
<th className="text-left p-2">State</th>
4748
</tr>
4849
</thead>
4950
<tbody>
5051
{models.map((model) => (
5152
<tr key={model.id} className="border-b hover:bg-secondary-hover border-border">
5253
<td className="p-2">
53-
<a href={`/upstream/${model.id}/`} className="underline" target="top">
54+
<a href={`/upstream/${model.id}/`} className="underline" target="_blank">
5455
{model.id}
5556
</a>
5657
</td>
58+
<td className="p-2">
59+
<button className="btn btn--sm" disabled={model.state !== "stopped"} onClick={() => loadModel(model.id)}>Load</button>
60+
</td>
5761
<td className="p-2">
5862
<span className={`status status--${model.state}`}>{model.state}</span>
5963
</td>

0 commit comments

Comments
 (0)