Skip to content

Commit 1f38eab

Browse files
committed
Load models in the UI without navigating the page
1 parent a6b2e93 commit 1f38eab

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
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: 11 additions & 3 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,25 @@ 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">Upstream</th>
47+
<th className="text-left p-2">Actions</th>
4648
<th className="text-left p-2">State</th>
4749
</tr>
4850
</thead>
4951
<tbody>
5052
{models.map((model) => (
5153
<tr key={model.id} className="border-b hover:bg-secondary-hover border-border">
5254
<td className="p-2">
53-
<a href={`/upstream/${model.id}/`} className="underline" target="top">
54-
{model.id}
55+
<span className="">{model.id}</span>
56+
</td>
57+
<td className="p-2">
58+
<a href={`/upstream/${model.id}/`} className="underline" target="_blank">
59+
Direct Link
5560
</a>
5661
</td>
62+
<td className="p-2">
63+
<button className="btn btn--sm" disabled={model.state !== "stopped"} onClick={() => loadModel(model.id)}>Load</button>
64+
</td>
5765
<td className="p-2">
5866
<span className={`status status--${model.state}`}>{model.state}</span>
5967
</td>

0 commit comments

Comments
 (0)