Skip to content

Commit 8defc84

Browse files
authored
Merge pull request #152 from NeuroJSON/staging
Release: Ollama on shui and download script fix
2 parents 468f41e + 8c48ff0 commit 8defc84

4 files changed

Lines changed: 57 additions & 16 deletions

File tree

‎backend/src/controllers/ollama.controller.js‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
const OLLAMA_BASE_URL = "http://jin.neu.edu:11434";
2-
const OLLAMA_MODEL = "qwen3.6:27b";
1+
// Ollama server + model come from .env, so switching needs no code change:
2+
// OLLAMA_BASE_URL=http://shui.neu.edu:11434
3+
// OLLAMA_MODEL=qwen3.8-careful:latest
4+
const OLLAMA_BASE_URL = (
5+
process.env.OLLAMA_BASE_URL || "http://shui.neu.edu:11434"
6+
).replace(/\/+$/, "");
7+
const OLLAMA_MODEL = process.env.OLLAMA_MODEL || "qwen3.8-careful:latest";
38

49
const proxyChat = async (req, res) => {
510
console.log("🟣 [Ollama] proxyChat hit — model:", OLLAMA_MODEL);

‎src/components/User/Dashboard/DatasetOrganizer/LLMPanel.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ const llmProviders: Record<string, LLMProvider> = {
6666
name: "Ollama (NeuroJSON Server)",
6767
baseUrl: "",
6868
models: [
69-
{ id: "qwen3.6:27b", name: "Qwen 3.6 27B" },
69+
{ id: "qwen3.8-careful:latest", name: "Qwen 3.8 Careful" },
7070
// { id: "qwen3-coder-next:latest", name: "Qwen 3 Coder Next" },
7171
// { id: "qwen3-coder-careful:latest", name: "Qwen 3 Coder Careful" },
7272
// { id: "qwen3.5:9b", name: "Qwen 3.5 9B" },
@@ -1461,7 +1461,7 @@ const LLMPanel: React.FC<LLMPanelProps> = ({
14611461

14621462
{provider === "ollama" && (
14631463
<Typography variant="caption" color="text.secondary" sx={{ mt: -1, mb: 2, display: "block" }}>
1464-
Using qwen3.6:27b on NeuroJSON server
1464+
Using Qwen 3.8 Careful on NeuroJSON server
14651465
</Typography>
14661466
)}
14671467

‎src/pages/UpdatedDatasetDetailPage.tsx‎

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -619,16 +619,39 @@ const UpdatedDatasetDetailPage: React.FC = () => {
619619
}),
620620
];
621621

622-
// Bash script (Mac/Linux)
622+
// Shell-safe single quoting: ' → '\'' (nothing inside '…' is expanded).
623+
const shq = (s?: string) => `'${(s ?? "").replace(/'/g, `'\\''`)}'`;
624+
// Batch: % must be doubled (else %20 etc. are read as variables);
625+
// a " can't be quoted safely, so such items are skipped below.
626+
const batq = (s?: string) => `"${(s ?? "").replace(/%/g, "%%")}"`;
627+
// Only plain relative paths inside the download folder: no leading /,
628+
// no "..", no backslash, no control characters. Others → file-<n>.
629+
const safeName = (name: string) =>
630+
!!name &&
631+
!name.startsWith("/") &&
632+
!name.includes("\\") &&
633+
!/[\x00-\x1f\x7f]/.test(name) &&
634+
!name.split("/").some((part) => part === ".." || part === "");
635+
const safeItems = items.map((it, i) => ({
636+
...it,
637+
filename: safeName(it.filename) ? it.filename : `file-${i}`,
638+
}));
639+
640+
// Bash script (Mac/Linux). --create-dirs makes the sub-01/anat/… folders.
623641
const sh =
624642
`#!/bin/bash\n` +
625643
`# Downloads ${docId} from ${dbName}\n` +
626644
`# Usage: bash ${docId}.sh\n` +
627645
`set -e\n` +
628-
`mkdir -p "${docId}"\n` +
629-
`cd "${docId}" || exit 1\n` +
630-
items
631-
.map((it) => `curl -L -C - -o "${it.filename}" "${it.url}"`)
646+
`mkdir -p ${shq(docId)}\n` +
647+
`cd ${shq(docId)} || exit 1\n` +
648+
safeItems
649+
.map(
650+
(it) =>
651+
`curl -L -C - --create-dirs -o ${shq(it.filename)} ${shq(
652+
it.url
653+
)}`
654+
)
632655
.join("\n") +
633656
`\necho "Done. Files saved to $(pwd)"\n`;
634657

@@ -637,10 +660,16 @@ const UpdatedDatasetDetailPage: React.FC = () => {
637660
`@echo off\r\n` +
638661
`REM Downloads ${docId} from ${dbName}\r\n` +
639662
`REM Usage: double-click or run ${docId}.bat\r\n` +
640-
`if not exist "${docId}" mkdir "${docId}"\r\n` +
641-
`cd /d "${docId}"\r\n` +
642-
items
643-
.map((it) => `curl -L -C - -o "${it.filename}" "${it.url}"`)
663+
`if not exist ${batq(docId)} mkdir ${batq(docId)}\r\n` +
664+
`cd /d ${batq(docId)}\r\n` +
665+
safeItems
666+
.filter((it) => !it.filename.includes('"') && !it.url.includes('"'))
667+
.map(
668+
(it) =>
669+
`curl -L -C - --create-dirs -o ${batq(it.filename)} ${batq(
670+
it.url
671+
)}`
672+
)
644673
.join("\r\n") +
645674
`\r\necho Done. Files saved to %cd%\r\n` +
646675
`pause\r\n`;

‎src/services/ollama.service.ts‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export const OllamaService = {
1515
// const temperature = getQwenTemperature(model);
1616
const response = await fetch(`${API_URL}/ollama/bidsify`, {
1717
method: "POST",
18+
// Send the login cookie: /ollama/bidsify requires login, and locally the
19+
// API (localhost:5000) is a different origin from the page.
20+
credentials: "include",
1821
headers: { "Content-Type": "application/json" },
1922
body: JSON.stringify({
2023
model,
@@ -29,19 +32,23 @@ export const OllamaService = {
2932
const data = await response.json();
3033

3134
if (!response.ok) {
32-
throw new Error(data.error || "Failed to call Ollama");
35+
throw new Error(data.error || data.message || "Failed to call Ollama");
3336
}
3437

3538
return data;
3639
},
3740

3841
getTags: async (): Promise<any> => {
39-
const response = await fetch(`${API_URL}/ollama/tags`);
42+
const response = await fetch(`${API_URL}/ollama/tags`, {
43+
credentials: "include",
44+
});
4045

4146
const data = await response.json();
4247

4348
if (!response.ok) {
44-
throw new Error(data.error || "Failed to fetch Ollama models");
49+
throw new Error(
50+
data.error || data.message || "Failed to fetch Ollama models"
51+
);
4552
}
4653

4754
return data;

0 commit comments

Comments
 (0)